[LRUG] Initial migration for new Rails 4 project using existing postgres db

Graham Ashton graham at effectif.com
Wed Mar 16 15:10:27 PDT 2016


On Wed, 16 Mar 2016, at 18:59, gvim wrote:
> 
> My tentative approach is to do away with an initial "create" migration 
> and substitute it with the output an initial pg_dump. Will subsequent 
> migrations work, assuming there will never be a need to recreate the db 
> solely from Rails migrations?

As I was reading your post and saw how you'd made an initial migration using the output of a dump, it struck me as odd. Did you find that approach documented somewhere?

It seems a little too likely to fiddle (needlessly) with your data to me.

Did you try just starting with your legacy database, and using migrations to manage schema changes moving forward? I'd be surprised if it didn't just work (though I've never tried it, so I could be talking rubbish).

Rails keeps track of the migrations that have been run in a schema_versions table. I don't know when that gets created – it could be made automatically when you run your first migration, in which case you're good to go.

If not, it's very simple, and only has one column, so you could make it yourself.

As for recreating the db solely from migrations, don't worry about needing to do it. The schema:load rake task the recommended way to create a new empty database.

It's actually a good idea to remove old migrations from the db/migrate folder once you've no further use for them (i.e. they've been run on all instances of your database).

Hope that makes some sense...



More information about the Chat mailing list