Db:schema vs db:structure

This is a smaller one, but I’ve always wondered why there are separate tasks for db:schema:load and db:structure:load (same for dump). Could we combine these into a single set of tasks and load either the schema or structure based on the sql_format config?

4 Likes

I’ve had the same question. At work we use sql format. A team member uses db:schema:dump because he finds the format easier to parse visually. If there were no format specific dump tasks he would change sql_format in the config file to dump the format he preferred. Since that change could easily be comitted I think there is value in being able to specify the desired format by command apart from configuration. Instead of separate commands, would a single task with a format option make a difference?

I think we could combine them. I can’t think of a reason off the top of my head why we need to have separate tasks (I’ve had the same question myself but never investigated)

2 Likes

It’s been a long time since I’ve delved into the details, but db:structure:dump produces a .sql file with content that is not necessarily portable, but db:schema:dump produces a .rb file which any ActiveRecord-supported database can use.

(I think that I’ve only ever had one project where the database-specific db:structure:dump was useful because we used something that AR didn’t support.)

I personally prefer the SQL format as it usually contains more info and I don’t have to make the mental effort to translate to SQL but both are fine.

To be fair most of the apps I’ve ever worked on never changed DB, they usually add more data sources, but I seldom see a PostgreSQL app switching to MySQL or viceversa.

I don’t advise removing either or changing the default, just wanted to give a bit of more context :slight_smile:

1 Like