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
2019-09-04 04:50:46 +05:00

38 lines
851 B
Ruby

# 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
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 { execute "DROP TYPE #{name}" }
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 { execute "ALTER TABLE #{table} DROP CONSTRAINT #{name}" }
end
end
end
end