1

Is the structure just a sql version of the db while the schema is a Rails version of the db? When would you want to load either? Or does it make a difference?

0

1 Answer 1

7

The schema file is the Rails version of your db and doesn't contain any db specific stuff like, views, triggers, and so on.

db/schema.rb cannot express database specific items such as triggers, sequences, stored procedures or check constraints, etc. Please note that while custom SQL statements can be run in migrations, these statements cannot be reconstituted by the schema dumper. If you are using features like this, then you should set the schema format to :sql. http://edgeguides.rubyonrails.org/active_record_migrations.html#schema-dumping-and-you

When would you use one over the other depends on whether you have db specific stuff that you need. If all you use are the basic tables, with indexes and primary and foreign keys you are good to go with schema files.

In my opinion however I always use structure.sql since I always use some db specific things.

You can change what format you want to use by changing this in your config/application.rb file.

config.active_record.schema_format = :sql # default is :ruby 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.