Module: IdempotentMigration
- Defined in:
- lib/stack-service-base/database.rb
Overview
DB.extension :pg_enum module Sequel::Postgres::EnumDatabaseMethods
def create_enum?(enum, values)
create_enum(enum, values) unless from(:pg_type).where(typname: enum.to_s).count > 0
end
end
Instance Method Summary collapse
- #table_add_column(table, name, *opts) ⇒ Object
- #table_add_index(table, *opts) ⇒ Object
- #table_add_unique_constraint(table, *opts) ⇒ Object
- #table_drop_column(table, name, *opts) ⇒ Object
- #table_rename_column(table, name, *opts) ⇒ Object
Instance Method Details
#table_add_column(table, name, *opts) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/stack-service-base/database.rb', line 15 def table_add_column table, name, *opts return if self[table].columns.include? name alter_table table do add_column name, *opts end end |
#table_add_index(table, *opts) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/stack-service-base/database.rb', line 36 def table_add_index(table, *opts) this = self alter_table table do this.indexes(table).each do |_name, index| if index[:columns].join === opts.join return end end add_index *opts end end |
#table_add_unique_constraint(table, *opts) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/stack-service-base/database.rb', line 48 def table_add_unique_constraint table, *opts this = self alter_table table do this.indexes(table).each do |name, index| if index[:columns].join === opts.join return # drop_constraint name, type: :unique end end add_unique_constraint *opts end end |
#table_drop_column(table, name, *opts) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/stack-service-base/database.rb', line 22 def table_drop_column table, name, *opts return unless self[table].columns.include? name alter_table table do drop_column name, *opts end end |
#table_rename_column(table, name, *opts) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/stack-service-base/database.rb', line 29 def table_rename_column table, name, *opts return unless self[table].columns.include? name alter_table table do rename_column name, *opts end end |