Search code examples
rubypostgresqlmigrationsequel

How do I create a Sequel migration from an existing postgres table dump?


I am wondering the best way to create a migration in sequel that is based on an existing table dump from postgres. I realise that I will have to write the down method myself to remove the table / functions / sequences, but is there a way to tell the sequel up migration to load an existing sql script and execute everything in the script?

Edit: Just in case its unclear, this is using the ruby Sequel SQL library / gem


Solution

  • You wouldn't create a migration from a table dump, but you can easily create one by using Sequel's schema_dumper extension. There's actually built-in support for this in the sequel command line program:

    sequel -d postgres://postgres@localhost/mydb > 001_initial_migration.rb

    There's no support for dumping functions or sequences, as this is designed to produce a database-independent migration.

    If you are using functions and custom sequences, you are fully in database-specific territory, and may be better off just using the database's tools.