Convert DB schema from Ruby to SQL format
Configure the application to use SQL format for the database schema instead of Ruby:
- Database-specific features - structure.sql allows you to use database-specific features which may not be supported in schema.rb. For example, let's say you want to make sure the jsonb data-type that is supported by PostgreSQL but not SQLite is represented properly in your database schema. You'll find that structure.sql will give you a better solution compared to the standard schema.rb.
- Complex migrations - If your app uses complex migrations and SQL statements that need to be maintained as they are, you'll find that structure.sql will be exactly what you need.
- Maintaining database state - structure.sql is a much better tool at capturing the exact state of a database compared to
schema.rb. This becomes important in cases where you need to capture the entire structure of a database as is, for instance, when dealing with legacy databases or when moving databases between different deployment servers.
In the application.rb we need to add this line: config.active_record.schema_format = :sql and the re-generate the schema with ./bin/rails db:migrate.
Edited by Vitaly Slobodin