Be sure to read this section of the manual .
Make sure in the application block in config/application.rb :
config.active_record.schema_format = :sql
You can then use this Rake task to unload the schema, but it needs to be reset / updated whenever you migrate / etc. because of this above:
rake db:structure:dump
Your flush structure should be in db/structure.sql . It should look like a dump schema file from your database, i.e. Do not include data, except for migration data that will be placed at the end (at least for postgres).
When using config.active_record.schema_format = :sql your db/schema.rb not updated by default whenever you migrate, because db/schema.rb not designed to completely decommission the SQL schema. However, some tools like IntelliJ Rubymine and IDea with a Ruby plugin similar to this file, so add them to your Rakefile (as mentioned here ):
Rake::Task["db:migrate"].enhance do if ActiveRecord::Base.schema_format == :sql Rake::Task["db:schema:dump"].invoke end end Rake::Task["db:rollback"].enhance do if ActiveRecord::Base.schema_format == :sql Rake::Task["db:schema:dump"].invoke end end
When the test database is recreated by Rails, it uses db/structure.sql as the base if config.active_record.schema_format = :sql . If you roll back or make changes to the database from the outside and redump using the above command or do the migration, etc., It will also update db/structure.sql (and db/schema.rb with these tasks above, although db/schema.rb does not fully cover information from the dump of the circuit).
Gary S. weaver
source share