4 def add_index_options(table_name, column_name, options = {})
5 columns = options.delete(:columns)
6 index_name, index_type, index_columns, index_options, algorithm, using = super(table_name, column_name, options)
7 [index_name, index_type, columns || index_columns, index_options, algorithm, using]
11 module PostgreSQLAdapter
12 def quote_column_name(name)
13 Array(name).map { |n| super(n) }.join(", ")
16 def add_primary_key(table_name, column_name, _options = {})
17 table_name = quote_table_name(table_name)
18 column_name = quote_column_name(column_name)
20 execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{column_name})"
23 def remove_primary_key(table_name)
24 table_name = quote_table_name(table_name)
26 execute "ALTER TABLE #{table_name} DROP PRIMARY KEY"
29 def alter_primary_key(table_name, new_columns)
30 constraint_name = quote_table_name("#{table_name}_pkey")
31 table_name = quote_table_name(table_name)
32 new_columns = quote_column_name(new_columns)
34 execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint_name}"
35 execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{new_columns})"
38 def create_enumeration(enumeration_name, values)
39 execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
42 def drop_enumeration(enumeration_name)
43 execute "DROP TYPE #{enumeration_name}"
46 def rename_enumeration(old_name, new_name)
47 old_name = quote_table_name(old_name)
48 new_name = quote_table_name(new_name)
50 execute "ALTER TYPE #{old_name} RENAME TO #{new_name}"
56 ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(OpenStreetMap::ActiveRecord::AbstractAdapter)
57 ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(OpenStreetMap::ActiveRecord::PostgreSQLAdapter)