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

Duncan Stuart dgmstuart at gmail.com
Thu Mar 17 01:06:03 PDT 2016


Not sure if this is what you're asking, but I wrote a blog post about using
migrations to move a legacy database into a state where a new project with
a *different schema* can use it:
https://dgmstuart.github.io/blog/2014/08/20/migrating-postgres-data-from-an-old-rails-project-to-a-new-one/

On 16 March 2016 at 22:10, Graham Ashton <graham at effectif.com> wrote:

> 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...
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20160317/eca289dc/attachment-0002.html>


More information about the Chat mailing list