Forum: Ruby on Rails Migrations question: force initial version?

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.
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (al-evans)
on 2006-12-22 23:48
I have an application that's been under constant heavy development for
several months. I'm now rewriting it to somewhat different specs, and I
decided it would be easiest and cleanest to start with a new blank
application, and copy only the parts I need from the old one.

Almost all of the changes will be in the controller code and HTML. The
models and database will stay substantially the same.

The database is up to 25 migrations, and I'd like to "flatten" them for
this new version. As far as I could tell, the migrate task gets its next
number by adding one to the number of the highest-numbered file in the
migrations folder. So I made a migration file in the new project,
"025_inherited_db.rb", and put everything from the schema.rb in the old
project into it.

I ran rake db:migrate, and as expected, it didn't do anything. So
generated a new migration, added a table, ran the migration again, and
the new table appeared as expected. Then I migrated back to the initial
version, and it correctly dropped the new table and set schema_info to
the correct value.

So it looks to me like this works. Am I missing something that will bite
me later?

Thanks,

--Al Evans
72f8ab180f81f9c544e2b58da399c0be?d=identicon&s=25 Elad Meidar - Creopolis.com (Guest)
on 2006-12-23 23:14
(Received via mailing list)
Hi Al,

As you already found, the base level of your database structure is
found in schema.rb.
but db:migrate will not help you in this case, although you created a
new member since it compares the migration number (aka schema version)
to the number found in the schema_info table (version column) in your
working db.

try copying the schema.rb file into your new project and issue the
db:schema:load command.

hope this helps.
This topic is locked and can not be replied to.