heroku - Rails Data Migration Mystery -


My bank account model and a card model. Currently, both of them have a customer_id and a company_id. I am trying to convert those who are just a molecular collaborator for "owner". I added proper relationships to the model, and then went to write data migrations for all existing customers and companies. This migration looks like this ...

Class AddOwnersToCardsAndBanks & lt; ActiveRecord :: Migration Class Card & lt; ActiveRecord :: Base; And class bank account & lt; ActiveRecord :: Base; Card ,: def # changes related to card add_column change again OWNER_ID ,: integer add_column: Card ,: owner_type ,: string # BankAccount related changes add_column: bank_accounts ,: owner_id ,: integer add_column: bank_accounts ,: owner_type ,: string Card.all Do .each | Card | If card.try (: CUSTOMER_ID) card.update_attribute (: owner_id, card.patient_id) card.update_attribute (: owner_type, "patient") end end BankAccount.all.each | Bank_acount | If bank_acount.try (: CUSTOMER_ID) bank_acount.update_attribute (: owner_id, bank_acount.customer_id) bank_acount.update_attribute (: owner_type, "patient") end if bank_acount.try (: company_id) bank_acount.update_attribute (: owner_id, bank_acount.company_id) bank_acount.update_attribute (: owner_type, "company") end end remove_column: card ,: CUSTOMER_ID ,: integer remove_column: bank_accounts ,: CUSTOMER_ID ,: integer remove_column: bank_accounts ,: company_id ,: rounded end end

This work locally (it seems) I pushed it to a feature server, and even conveyed what was happening in the migration. It appears that everything in the migration should do (which means that I had updated it, then logged into the bank account, and printed those features where I expected them). However, when I console the railway server with the convenience server and look at the converted data, it used to work only for the card, but not for bank accounts.

Specifically, the identity of the owner and the owner's nature is not really set up on the bank accounts after the reality. But when I log those attributes from migration, then they are in line with expectations. This is the opposite of the card, where everything is set properly, and the database shows that. I'm totally confused.

It seems that maybe there is something like that with the Heroica, or Circle, but I do not know. What could be the problem but any thoughts would be greatly appreciated.

After

During a data migration, you can sometimes write 't columns that were just created . Try adding it to your migration script:

  # BankAccount related changes add_column: bank_accounts ,: owner_id ,: integer add_column: bank_accounts ,: owner_type ,: string Card.reset_column_information BankAccount.reset_column_information Card. All Do each. Card |  

More information can be found at:


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -