I would like to output the generated SQL statements from Sequel migrations to a file without having a connection to the actual database. I need this because I want to export the statements in MySQL form, but I use PostgreSQL normally.
I could try to set up MySQL and output with the -E
option while creating the database, but that is not how things should work right?
What I need is something like:
sequel -m db/migrations/ -E --type mysql > msysql_statements.sql
I'm using Sequel with migrations.
Is there a way to achieve this?
Trials according to answers
I tried the command proposed Jeremy Evans'es answer:
sequel -m db/migrations/ -t -E mock://mysql
the error is following output:
I, [2016-07-18T13:57:09.020630 #21573] INFO -- : SELECT NULL AS `nil` FROM `schema_migrations` LIMIT 1
I, [2016-07-18T13:57:09.020802 #21573] INFO -- : SELECT * FROM `schema_migrations` LIMIT 1
/home/me/.rvm/gems/ruby-2.2.1/gems/sequel-4.34.0/lib/sequel/extensions/migration.rb:751:in `schema_dataset': Migrator table schema_migrations does not contain column filename (Sequel::Migrator::Error)
from /home/me/.rvm/gems/ruby-2.2.1/gems/sequel-4.34.0/lib/sequel/extensions/migration.rb:450:in `initialize'
from /home/me/.rvm/gems/ruby-2.2.1/gems/sequel-4.34.0/lib/sequel/extensions/migration.rb:652:in `initialize'
from /home/me/.rvm/gems/ruby-2.2.1/gems/sequel-4.34.0/lib/sequel/extensions/migration.rb:397:in `new'
from /home/me/.rvm/gems/ruby-2.2.1/gems/sequel-4.34.0/lib/sequel/extensions/migration.rb:397:in `run'
from /home/me/.rvm/gems/ruby-2.2.1/gems/sequel-4.34.0/lib/sequel/extensions/migration.rb:368:in `apply'
from /home/me/.rvm/gems/ruby-2.2.1/gems/sequel-4.34.0/bin/sequel:160:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.2.1/bin/sequel:23:in `load'
from /home/me/.rvm/gems/ruby-2.2.1/bin/sequel:23:in `<main>'
from /home/me/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /home/me/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Unfortunately it seems to try to access something from the mock-database.
Update
With Jeremy's answer i had something to work with, i came up with following hacky workaround, which generates at least most of the statements, but not all :( :
- issue
sequel -m db/migrations/ -t -E mock://mysql > mysql-statements.sql
- if you get an exeption, comment out raise statement in sequel code
- at the and you will have an output with the correct sql statement, but with extra logging information
- remove that extra information by using some replacement tool or easier with multi-cursor-editors like sublime or atom
- put semicolons at the end of the lines
- now you have correct mysql statements
- Dont forget to revert modifications on sequel-gem-code ;)