On Monday, July 13, 2015 at 5:43:48 PM UTC-7, John Mettraux wrote:
>
> Hello, 
>
> would there be a way to generate a SQL script for a migration instead of 
> running the migration? 
>
> Something along the lines of: 
>
>     sequel -m path/to/migrations jdbc:sqlite:tmp/test.db -o migration.sql 
>
> I work in an environment where a person runs the SQL scripts when 
> deploying a 
> new release. No leeway to run the migration directly from Sequel. 
>
> Granted, I could run the migration against an equivalent server and rework 
> the resulting log to obtain this SQL script, but that's not optimal. I'd 
> also 
> love to have such a capabilites in less restrictive environments, just for 
> "dry runs" of migrations. 
>

The easiest way to do this is to run the migration on a mock database with 
a logger, and use the mock database's stored sql as the output.  There's 
nothing built in that does this, but something like:

Sequel.extension :migration
DB = Sequel.connect('mock://postgres')
migration_number = 4
Sequel::Migrator.run(DB, 'path/to/migrations', :current=>migrate_version-1, 
:target=>migrate_version)
sqls = DB.sqls
sqls = sqls[sqls.index('BEGIN')..-1]
file.write('migrations.sql', sqls.join(";\n"))

Note that the above will only work if you use transactional migrations. 
 Hopefully you can play around with that and get something that works for 
you.

Thanks,
Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to