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