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

39 lines
851 B
Ruby
Raw Normal View History

2019-09-03 19:26:12 -04:00
# frozen_string_literal: true
module Partynest
module Migration
def func(name, sql)
reversible do |dir|
2019-09-03 19:50:46 -04:00
dir.up { execute "CREATE FUNCTION #{name} #{sql}" }
2019-09-03 19:26:12 -04:00
2019-09-03 19:50:46 -04:00
dir.down { execute "DROP FUNCTION #{name}" }
2019-09-03 19:26:12 -04:00
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
2019-09-03 19:50:46 -04:00
dir.down { execute "DROP TYPE #{name}" }
2019-09-03 19:26:12 -04:00
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
2019-09-03 19:50:46 -04:00
dir.down { execute "ALTER TABLE #{table} DROP CONSTRAINT #{name}" }
2019-09-03 19:26:12 -04:00
end
end
end
end