Is it possible to output the SQL change scripts that \'rake db:migrate\' produces?
You can run preview SQL in rails console
like this:
ActiveRecord::Base.connection.change_table(:events) do |t|
t.integer :submission_id, default: 5, null: false
end
#=> ALTER TABLE `events` ADD `submission_id` int DEFAULT 5 NOT NULL
So, just prepend your ordinary migration methods with ActiveRecord::Base.connection.
and you are good to go.
There is also rails console --sandbox
mode which rollbacks changes after you close the console. Though check if it works for your project, somehow for our project with rails 5 + MySQL it doesn't roll back DDL changes.
If you have migration files ready, you can also run it directly:
ActiveRecord::MigrationContext.new("db/migrate").migrate
ActiveRecord::MigrationContext.new("db/migrate").rollback