Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude non-expert-validated plays. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jamiefolsom
Copy link
Member

@jamiefolsom jamiefolsom commented Jan 25, 2017

This filters out play which are not expert_validated when the warehouse script is run.

It occurs to me that there could be a related problem in which existing tickets sales, or registers, are still referring to these non-expert validated plays, and which therefore need to be re-mapped to their expert validated equivalents.

I will (and you can) test the PR without affecting the staging or production databases, run the warehouse rake task on this heroku app: https://dashboard.heroku.com/apps/cfrp-staging-pr-3

@jamiefolsom jamiefolsom temporarily deployed to cfrp-staging-pr-3 January 25, 2017 21:06 Inactive
@jamiefolsom jamiefolsom self-assigned this Jan 25, 2017
@jamiefolsom
Copy link
Member Author

jamiefolsom commented Jan 25, 2017

Update -- testing this PR on the Review app, indeed the rake task aborts because of the same foreign key constraint issue.

ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR:  insert or update on table "sales_facts" violates foreign key constraint "sales_facts_play_2_id_fkey"
DETAIL:  Key (play_2_id)=(856) is not present in table "play_dim".
: UPDATE warehouse.sales_facts SET play_2_id = (SELECT min(play_id) FROM register_plays WHERE ordering = 2 AND register_plays.register_id = sales_facts.register_id)

So a next step would be to find out which registers are still referencing non-validated plays, and remap them to validated ones.

@forestofarden
Copy link
Contributor

forestofarden commented Jan 25, 2017

Hi Jamie - It may help to know that the warehouse plays_dim table uses the same ids as the original plays table.

Here are the bad plays:

cfrp_development=# select distinct(play_dim.id) as play_id from warehouse.sales_facts, warehouse.play_dim where play_dim.id in (play_1_id, play_2_id, play_3_id, play_4_id) and acts is null;
 play_id 
---------
     856
    5677
    5878
    5917
(4 rows)

And, the bad register entries:

cfrp_development=# select registers.id, date, ordering, plays.id, title from register_plays join registers on (registers.id = register_id) join plays on(plays.id = play_id) where play_id in (856,5917,5878,5677) and verification_state_id in (1,6) order by date, ordering;
  id   |    date    | ordering |  id  |          title           
-------+------------+----------+------+--------------------------
 24629 | 1684-11-23 |        2 | 5917 | Danse de Gigogne
 24654 | 1684-12-19 |        2 | 5917 | Danse de Gigogne
 34950 | 1688-10-27 |        2 | 5677 | Le Désespoir extravagant
 17370 | 1746-04-24 |        3 |  856 | 
 17377 | 1746-05-01 |        3 |  856 | 
 21142 | 1759-05-23 |        1 | 5878 | Suivante généreuse (La)
 21144 | 1759-05-26 |        1 | 5878 | Suivante généreuse (La)
  3289 | 1770-02-19 |        2 |  856 | 
  3295 | 1770-02-25 |        2 |  856 | 
  3407 | 1770-07-25 |        2 |  856 | 
  3526 | 1770-12-02 |        2 |  856 | 
  3551 | 1770-12-30 |        2 |  856 | 
  4172 | 1773-01-23 |        2 |  856 | 
  2954 | 1774-02-10 |        2 |  856 | 
  2957 | 1774-02-13 |        2 |  856 | 
  2959 | 1774-02-15 |        2 |  856 | 
  2964 | 1774-02-20 |        2 |  856 | 
  2967 | 1774-02-23 |        2 |  856 | 
  2971 | 1774-02-27 |        2 |  856 | 
  2983 | 1774-03-13 |        2 |  856 | 
(20 rows)

Hope this helps! C

@jamiefolsom
Copy link
Member Author

@christopheryork -- Yep, that makes sense. I will request an update from Sara as to which plays those registers should point to instead. Thanks for confirming, and for those queries!

@forestofarden
Copy link
Contributor

Sounds good. Good luck!

@jamiefolsom jamiefolsom temporarily deployed to cfrp-staging-pr-3 May 23, 2017 08:21 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants