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

gvim gvimrc at gmail.com
Wed Mar 16 20:34:00 PDT 2016


On 16/03/2016 22:10, Graham Ashton wrote:
>
> 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?
>
No, but then again the docs don't seem to address importing an existing 
database. Especially one that doesn't conform to Rails conventions. I 
quoted a web page which addressed this issue but, as I said, it didn't 
produce the required results.

> 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).
>
That's my next approach though I have to somehow get a rather large VIEW 
into the models somehow. Again, not something which seems to be documented.

> 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.

The thing which puzzles me is this. If you're starting out with a legacy 
database which contains a lot of data. How can you contemplate starting 
again from a blank database? If your starting point is a database full 
of valuable data surely any migrations would also have to start from 
this point, no?

>
> 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).
>

There are no old ones yet. I just setting up this project.

> Hope that makes some sense...

Thanks

gvim



More information about the Chat mailing list