On Friday, June 27, 2014 11:09:24 AM UTC-7, Paul Cowan wrote:
>
> I am migrating data from a horrible yaml serialized field into an actual
> table.
>
>
> I have 1 migration file that updates the schema and 1 migration file that
> does something like this:
>
> SequelAdapter::Account.all().each do |account|
> #do stuff
>
> I would rather not use the model but as the data is in a horrible yaml
> blob so I don't have really any alternative as getting the data out is
> tough.
>
You don't need to use the model to deserialize the yaml:
from(:accounts).all do |row|
yaml_data = YAML.load(row[:serialized_field])
# do stuff
end
Using the model may make things slightly easier, but it is a bad trade off
IMO.
> The problem is that after the ddl statements have been executed, the
> sequel model appears to be still referencing the old schema before the ddl
> statements where executed and it errors when trying to reference the new
> fields.
>
> If I run the migration again then all is good. Is there away to reload
> the sequel model before running the update commands?
>
Sequel model classes cache the database schema, so if you modify the schema
after creating the class, you need to reload the schema. The simplest way
to do this is:
SequelAdapter::Account.send(:get_db_schema, true)
If you don't want to use a private method, you need to reload the schema
manually, then reset the model's dataset:
schema(:table_name, :reload=>true)
SequelAdapter::Account.dataset = SequelAdapter::Account.dataset
However, I strongly recommend against using your models in your migrations.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.