Chaz Meyers (cpm) wrote,
Chaz Meyers
cpm

Why `rake db:migrate` is slow against large databases.

I just realized why `rake db:migrate` takes so damn long at work.

Rails is generally designed assuming that the application will get its own database. This is normal in environments where "database" is a lightweight concept, as in MySQL, PostgreSQL, or SQLite. After updating the database, it dumps the database schema to a file so when you install a new copy of the application you don't need to run dozens of migrations.

This works fine when there aren't many tables unrelated to your application, but in Oracle-land it's not unusual to put tons of applications all in the same massive database. Consider the following:

SQL> SELECT count(*) FROM all_tables;

COUNT(*)
----------
1747


Every time I add a single column to the database via migrations, all those tables get introspected and transformed into 13.5K lines of ruby. A three minute tax is added to an operation which usually takes less than a second.

I wonder if there's some way to turn off this behavior without hacking up their Rake file.

Update: Turns out this only happens if ActiveRecord.schema_format = :ruby. Change it to :sql and it won't try to dump the database.
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments