2 module ConnectionAdapters
3 module SchemaStatements
4 def add_index_options_with_columns(table_name, column_name, options = {})
5 columns = options.delete(:columns)
6 index_name, index_type, index_columns, index_options, algorithm, using = add_index_options_without_columns(table_name, column_name, options)
7 [index_name, index_type, columns || index_columns, index_options, algorithm, using]
10 alias_method_chain :add_index_options, :columns
15 def quote_column_name_with_arrays(name)
16 Array(name).map { |n| quote_column_name_without_arrays(n) }.join(", ")
19 alias_method_chain :quote_column_name, :arrays
22 module SchemaStatements
23 def add_primary_key(table_name, column_name, options = {})
24 execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
27 def remove_primary_key(table_name)
28 execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
31 def alter_primary_key(table_name, new_columns)
32 execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + "_pkey")}"
33 execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
36 def create_enumeration(enumeration_name, values)
37 execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
40 def drop_enumeration(enumeration_name)
41 execute "DROP TYPE #{enumeration_name}"
44 def rename_enumeration(old_name, new_name)
45 execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"