Rom-sql Rake Task

481 Views Asked by At

I'm trying to setup migrations using 'rom/sql/rake_task'.

Here is my sample, but sadly it isn't working as it's complaining about a missing sequel adaptor. Any assistance or direction would be appreciated?

require 'sqlite3'
require 'rom-sql'
require 'rom/sql/rake_task'

namespace :db do
  task :setup do
    ROM.setup(:sql, 'sqlite_memory')
    ROM.finalize

    ROM::SQL.migration do
      change do
        create_table(:users) do
          primary_key :id
          String :name
        end
      end
    end
  end
end
2

There are 2 best solutions below

0
On BEST ANSWER

Complete example: https://github.com/gotar/sinatra-rom

after you add

require 'bundler/setup'
require 'rom/sql/rake_task'

task :setup do
  # Load ROM related stuff. You don't need to specify manually connection
end

to Rakefile you will get few Raketasks (rake -T) to list them,

and then

$ rake db:create_migration[any_name]

and in file it will create, you can add your migration.

Thats all

4
On

you may wanna try:

ROM::SQL::Migration.connection = ROM.setup(:sql, 'sqlite_memory').default.connection
ROM.finalize.env

ROM::SQL::Migration.create do
  # ...
end