X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a0af70cfb4b7ab179014050ce026ab054025a65e..c53db246f606e0233a524e8f3c6390ea74e96890:/config/initializers/postgresql_adapter.rb diff --git a/config/initializers/postgresql_adapter.rb b/config/initializers/postgresql_adapter.rb index 0420a7495..9dcc34fcc 100644 --- a/config/initializers/postgresql_adapter.rb +++ b/config/initializers/postgresql_adapter.rb @@ -1,33 +1,33 @@ -module ActiveRecord - module ConnectionAdapters - class PostgreSQLAdapter - alias_method :old_pk_and_sequence_for, :pk_and_sequence_for +if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) + module ActiveRecord + module ConnectionAdapters + class PostgreSQLAdapter + def initialize_type_map_with_enums(type_map) + OID.alias_type "format_enum", "text" + OID.alias_type "gpx_visibility_enum", "text" + OID.alias_type "note_status_enum", "text" + OID.alias_type "note_event_enum", "text" + OID.alias_type "nwr_enum", "text" + OID.alias_type "user_role_enum", "text" + OID.alias_type "user_status_enum", "text" - def pk_and_sequence_for(table) - result = query(<<-end_sql, 'PK and serial sequence')[0] - SELECT attr.attname, seq.relname - FROM pg_class seq, - pg_attribute attr, - pg_depend dep, - pg_namespace name, - pg_constraint cons - WHERE seq.oid = dep.objid - AND seq.relkind = 'S' - AND attr.attrelid = dep.refobjid - AND attr.attnum = dep.refobjsubid - AND attr.attrelid = cons.conrelid - AND attr.attnum = cons.conkey[1] - AND cons.contype = 'p' - AND dep.classid = '"pg_class"'::regclass - AND dep.refclassid = '"pg_class"'::regclass - AND dep.refobjid = '#{quote_table_name(table)}'::regclass - end_sql + initialize_type_map_without_enums(type_map) + end + + alias_method_chain :initialize_type_map, :enums + end - if result.nil? or result.empty? - old_pk_and_sequence_for(table) - else - [result.first, result.last] + class PostgreSQLColumn + def simplified_type_with_enum(field_type) + case field_type + when /_enum$/ + :string + else + simplified_type_without_enum(field_type) + end end + + alias_method_chain :simplified_type, :enum end end end