Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is db/development_structure.sql in a rails project?

There is a development_structure.sql inside my /db folder of my rails application (rails 2.3.4, ruby 1.8.7) and I am not sure exactly what it does.

  1. Is it needed for some specific environment? (I think I read somewhere that it's used for tests)
  2. Do I need to add it to my git repository?
like image 599
Kostas Avatar asked Oct 13 '09 13:10

Kostas


People also ask

What is schema RB in rails?

The schema. rb serves mainly two purposes: It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduce the schema just from the migrations alone. With a present schema.


3 Answers

This post has been used as a reference by a coworker of mine, but the two answers are not exact or informative enough.

development_structure.sql is a low-level dump of the schema, which is necessary when you start to use proprietary database features - either you want to or not, you're going to use them at some point.

Regarding the question of storing it or not, there's some debate. Here is an informative post: http://www.saturnflyer.com/blog/jim/2010/09/14/always-check-in-schema-rb/. And my take on this follows.

The objective of the development_structure.sql is to sync, for any given commit, the database structure with the code, without having previous knowledge of the schema structure, that is, without having to rely on a pre-existing state of the schema to get the new one.

In a nutshell, by having a schema structure available, whenever you change branch/commit, you load it directly and forget it. This is mostly valid for dynamic and "crowded" projects, where different branches have differences in the underlying schema structure.

Without having the schema structure stored, you would need to always use an existing reference schema in your database, and migrate it back or forward every time you change branch/commit; several real-world cases can make this process inefficient (e.g. when another branch doesn't have some migrations you currently have, or some migrations can't be rolled back).

Another problem is automated builds, which suffer from the same problems, and even worse, they can't apply manual changes.

The only downside is that it requires a certain habit, which is, to store it every time you run a migration. Easy to say, but also easy to forget.

I don't say you can't live without development_structure.sql - of course you can. But if you have it, when changing branch/commit you just load-and-forget; if you don't, you [may] have to go through a series of manual steps.

like image 106
Marcus Avatar answered Sep 21 '22 17:09

Marcus


You should not add it to your git repository.

It is a file created automatically by rails when you run migrations with your database.yml configured to connect against a mysql database. You can view it as an alternative to schema.rb

I believe you can force rails to create it by adding in your environment.rb:

config.active_record.schema_format = :sql

When present this file is used for example by:

rake db:test:clone_structure

Edit

Relevant section in Ruby On Rails Guides. http://guides.rubyonrails.org/migrations.html#schema-dumping-and-you

They recommend to check it into source control on the wiki.

I personally like to keep it out of it. I like to be able to run all migrations very quickly. It is for me a good sign. If migrations become slow I feel like I am not in total control of my environment anymore. Slowness in migrations generally means I have a lot of data in my development database which I feel wrong.

However, It seems to be a matter of personal taste nowadays. Follow your instincts on this one.

like image 27
Aurélien Bottazini Avatar answered Sep 21 '22 17:09

Aurélien Bottazini


It's created when you run a rake task to clone your development database to your test database. The development database is outputted to SQL which is then read in to your test DB. You can safely delete it.

like image 34
insane.dreamer Avatar answered Sep 18 '22 17:09

insane.dreamer