Chaz Meyers (cpm) wrote,
Chaz Meyers

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;


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.

  • My tweets

    Sun, 01:39: RT @ dinoman_j:

  • My tweets

    Mon, 00:15: In a randoms Among Us discord, people were going "POGGERS" and I ask, "Hey, are any of you old enough to remember the game "pogs"…

  • My tweets

    Sun, 11:55: RT @ computerfact: everyone thinks theyre the plumber but in reality we're all just turtles minding our own business waiting to be…

  • Post a new comment


    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.