1

My first time with Padrino and DataMapper. If I understood correctly,

  • padrino g model Foo will make models/foo.rb as well as db/migrate/001_create_foos.rb.

  • In order to create an index, I need to specify it in the model, not in the migration.

  • padrino rake dm:auto:{upgrade|migrate} will generate the database from models, without paying attention to db/migrate folder.

So, it seems that migrations are only kept as "just in case" for upgrading production databases. Is there a way to generate a migration from the model? If not, does everyone else also have a headache trying to keep migrations up-to-date as you change your model? How do people write their migrations?

Amadan
  • 191,408
  • 23
  • 240
  • 301

1 Answers1

1

According Padrino documentation i guess you're right. The Orm section states that the auto namespace won't use the generated migrations.

Basically, instead of writing migrations you can directly edit your schema.rb and perform a non destructive migration with padrino rake ar:auto:upgrade

I guess you can track the database with migrations removing the auto namespace as:

rake dm:migrate                # Migrates the database to the latest version
rake dm:migrate:down[version]  # Migrates down using migrations
rake dm:migrate:up[version]    # Migrates up using migrations

And generate migrations as described in the Migration Generator section

  • The problem is, I couldn't find any way to make indices using DM migrations. So (unless I'm missing something), I need automigrate. – Amadan Dec 26 '13 at 03:10
  • I also couldn't find documentation for that. I guess in that case you should try to add the index statement after the migration is generated. Like changing `column :name, String, :index => true` in the create_table block. The source code for that may help (https://github.com/datamapper/dm-migrations/blob/master/examples/sample_migration.rb) – Júlio Bueno Dec 26 '13 at 06:44
  • I tried `column :name, String, :index => true` in the migration; it did not produce an index in the SQL. (And it is not in the example migration.) – Amadan Dec 26 '13 at 07:18