Forum: Ruby on Rails automatically generate migration from db/SQL?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D2b2017098da3e2fd1cdcfbb72ecdbfb?d=identicon&s=25 Jason Edgecombe (Guest)
on 2005-12-18 02:29
(Received via mailing list)
Hi,

I'd like to use migrations to build my initial database. Is there a gem
or plugin that will generate the migration code for initial db if I
point it at a live database or sql file?

If yes, then can you automatically generate the incremental migrations
as well?


Thanks,
Jason
5b9fe87ec1faa67a4599782930f45ec9?d=identicon&s=25 Sam Stephenson (Guest)
on 2005-12-18 02:32
(Received via mailing list)
Hi Jason,

On 12/17/05, Jason Edgecombe <jedgecombe@carolina.rr.com> wrote:
> Hi,
>
> I'd like to use migrations to build my initial database. Is there a gem
> or plugin that will generate the migration code for initial db if I
> point it at a live database or sql file?

It's built right in. Uncomment the line in config/environment.rb that
says:

  config.active_record.schema_format = :ruby

Then run rake db_schema_dump and you'll have the schema in
db/schema.rb.  This can be loaded with rake db_schema_import, or you
can copy the create_table statements into a new migration.

> If yes, then can you automatically generate the incremental migrations
> as well?

No, but if you run your tests db/schema.rb will always be up-to-date.

--
sam
6993d6b4b6d882f421e1b45ac147f3e0?d=identicon&s=25 Scott Barron (Guest)
on 2005-12-18 02:38
(Received via mailing list)
On Dec 17, 2005, at 8:26 PM, Jason Edgecombe wrote:

> Hi,
>
> I'd like to use migrations to build my initial database. Is there a
> gem or plugin that will generate the migration code for initial db if
> I point it at a live database or sql file?
>
> If yes, then can you automatically generate the incremental migrations
> as well?
>

Point rails to your database and do 'rake db_schema_dump', you could
then paste the guts of the schema.rb it produces into your initial
migration.

It could not generate incremental migrations from an existing schema,
there is no way to know how the schema was put together, only that it
is what it is.

--
Scott Barron
Lunchbox Software
http://lunchboxsoftware.com
http://lunchroom.lunchboxsoftware.com
http://rubyi.st
Ccfe7d097475a32dc3ff78d6fc42c852?d=identicon&s=25 List Recv (lstrecv)
on 2005-12-18 02:42
Also, check out SQL Translator (Google). It's amazing at migrations -
just sqlt-diff.
All we need is for someone to write ActiveRecord.migration bindings to
it.

Sam Stephenson wrote:
> Hi Jason,
>
> On 12/17/05, Jason Edgecombe <jedgecombe@carolina.rr.com> wrote:
>> Hi,
>>
>> I'd like to use migrations to build my initial database. Is there a gem
>> or plugin that will generate the migration code for initial db if I
>> point it at a live database or sql file?
>
> It's built right in. Uncomment the line in config/environment.rb that
> says:
>
>   config.active_record.schema_format = :ruby
>
> Then run rake db_schema_dump and you'll have the schema in
> db/schema.rb.  This can be loaded with rake db_schema_import, or you
> can copy the create_table statements into a new migration.
>
>> If yes, then can you automatically generate the incremental migrations
>> as well?
>
> No, but if you run your tests db/schema.rb will always be up-to-date.
>
> --
> sam
This topic is locked and can not be replied to.