2 module SchemaStatements
3 def add_index_options(table_name, column_name, options = {})
4 columns = options.delete(:columns)
5 index_name, index_type, index_columns, index_options, algorithm, using = super(table_name, column_name, options)
6 [index_name, index_type, columns || index_columns, index_options, algorithm, using]
12 def quote_column_name(name)
13 Array(name).map { |n| super(n) }.join(", ")
17 module SchemaStatements
18 def add_primary_key(table_name, column_name, _options = {})
19 execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
22 def remove_primary_key(table_name)
23 execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
26 def alter_primary_key(table_name, new_columns)
27 execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}"
28 execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
31 def create_enumeration(enumeration_name, values)
32 execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
35 def drop_enumeration(enumeration_name)
36 execute "DROP TYPE #{enumeration_name}"
39 def rename_enumeration(old_name, new_name)
40 execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
46 ActiveRecord::ConnectionAdapters::SchemaStatements.extend(OSM::SchemaStatements)
47 ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting.extend(OSM::PostgreSQL::Quoting)
48 ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements.extend(OSM::PostgreSQL::SchemaStatements)