Migrations question: force initial version?


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?


–Al Evans


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.