1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/lib/partynest/migration.rb

48 lines
966 B
Ruby

# frozen_string_literal: true
module Partynest
module Migration
def func(name, sql)
reversible do |dir|
dir.up do
execute "CREATE FUNCTION #{name} #{sql}"
end
dir.down do
execute "DROP FUNCTION #{name}"
end
end
end
def enum(name, values)
reversible do |dir|
dir.up do
execute <<~SQL
CREATE TYPE #{name}
AS ENUM (#{values.map { |s| "'#{s}'" }.join(', ')})
SQL
end
dir.down do
execute "DROP TYPE #{name}"
end
end
end
def constraint(table, name, check)
reversible do |dir|
dir.up do
execute <<~SQL
ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{check})
SQL
end
dir.down do
execute <<~SQL
ALTER TABLE #{table} DROP CONSTRAINT #{name}
SQL
end
end
end
end
end