From eada36ff96d1b534457d98a25239ec468a7cba2c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 10 Dec 2020 14:46:41 +0000 Subject: [PATCH] Switch to using the zeitwork autoloader --- Gemfile | 1 + Gemfile.lock | 3 +- config/application.rb | 3 - config/initializers/migrate.rb | 59 +++++++++++++++++++ config/initializers/zeitwerk.rb | 9 +++ db/migrate/001_create_osm_db.rb | 2 - db/migrate/002_cleanup_osm_db.rb | 2 - db/migrate/003_sql_session_store_setup.rb | 2 - db/migrate/004_user_enhancements.rb | 2 - db/migrate/005_tile_tracepoints.rb | 2 - db/migrate/006_tile_nodes.rb | 2 - db/migrate/007_add_relations.rb | 2 - db/migrate/008_remove_segments.rb | 2 - db/migrate/010_diary_comments.rb | 2 - db/migrate/018_create_acls.rb | 2 - .../020_populate_node_tags_and_remove.rb | 2 - db/migrate/021_move_to_innodb.rb | 2 - db/migrate/022_key_constraints.rb | 2 - db/migrate/023_add_changesets.rb | 2 - db/migrate/024_order_relation_members.rb | 2 - db/migrate/025_add_end_time_to_changesets.rb | 2 - db/migrate/028_add_more_changeset_indexes.rb | 2 - db/migrate/029_add_user_foreign_keys.rb | 2 - db/migrate/030_add_foreign_keys.rb | 2 - db/migrate/031_create_countries.rb | 1 - db/migrate/034_create_languages.rb | 2 - db/migrate/035_change_user_locale.rb | 2 - .../039_add_more_controls_to_gpx_files.rb | 2 - .../042_add_foreign_keys_to_oauth_tables.rb | 2 - db/migrate/044_create_user_roles.rb | 2 - db/migrate/045_create_user_blocks.rb | 2 - db/migrate/046_alter_user_roles_and_blocks.rb | 2 - db/migrate/051_add_status_to_user.rb | 2 - db/migrate/053_add_map_bug_tables.rb | 2 - db/migrate/054_refactor_map_bug_tables.rb | 2 - db/migrate/055_change_map_bug_comment_type.rb | 2 - db/migrate/056_add_date_closed.rb | 2 - db/migrate/057_add_map_bug_comment_event.rb | 2 - .../20110521142405_rename_bugs_to_notes.rb | 2 - ...111212183945_add_lowercase_user_indexes.rb | 2 - db/migrate/20120214210114_add_text_format.rb | 2 - .../20120318201948_create_redactions.rb | 2 - .../20120328090602_drop_session_table.rb | 2 - ...4_add_user_and_description_to_redaction.rb | 2 - ...5192822_add_text_index_to_note_comments.rb | 2 - ...0140507110937_create_changeset_comments.rb | 2 - ...join_table_between_users_and_changesets.rb | 2 - ...0160822153055_create_issues_and_reports.rb | 2 - ...n_table_between_users_and_diary_entries.rb | 2 - lib/migrate.rb | 57 ------------------ 50 files changed, 71 insertions(+), 148 deletions(-) create mode 100644 config/initializers/migrate.rb create mode 100644 config/initializers/zeitwerk.rb delete mode 100644 lib/migrate.rb diff --git a/Gemfile b/Gemfile index 264674fbc..a880a8534 100644 --- a/Gemfile +++ b/Gemfile @@ -130,6 +130,7 @@ group :development do gem "annotate" gem "better_errors" gem "binding_of_caller" + gem "debug_inspector", "< 1.0.0" gem "listen" gem "vendorer" end diff --git a/Gemfile.lock b/Gemfile.lock index 396166a58..b4274d143 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -140,7 +140,7 @@ GEM rexml crass (1.0.6) dalli (2.7.11) - debug_inspector (1.0.0) + debug_inspector (0.0.3) deep_merge (1.2.1) delayed_job (4.1.9) activesupport (>= 3.0, < 6.2) @@ -486,6 +486,7 @@ DEPENDENCIES composite_primary_keys (~> 12.0.0) config dalli + debug_inspector (< 1.0.0) delayed_job_active_record dynamic_form erb_lint diff --git a/config/application.rb b/config/application.rb index 54390ba29..f5638e233 100644 --- a/config/application.rb +++ b/config/application.rb @@ -31,9 +31,6 @@ module OpenStreetMap # Custom directories with classes and modules you want to be autoloadable. config.autoload_paths += %W[#{config.root}/lib] - # Continue to use the classic autoloader for now - config.autoloader = :classic - # Force requests from old versions of IE (<= IE8) to be UTF-8 encoded. # This has defaulted to false since rails 6.0 config.action_view.default_enforce_utf8 = true diff --git a/config/initializers/migrate.rb b/config/initializers/migrate.rb new file mode 100644 index 000000000..787f3d551 --- /dev/null +++ b/config/initializers/migrate.rb @@ -0,0 +1,59 @@ +if defined?(ActiveRecord::ConnectionAdapters::AbstractAdapter) + module OpenStreetMap + module ActiveRecord + module AbstractAdapter + def add_index_options(table_name, column_name, options = {}) + columns = options.delete(:columns) + index_name, index_type, index_columns, index_options, algorithm, using = super(table_name, column_name, options) + [index_name, index_type, columns || index_columns, index_options, algorithm, using] + end + end + + module PostgreSQLAdapter + def quote_column_name(name) + Array(name).map { |n| super(n) }.join(", ") + end + + def add_primary_key(table_name, column_name, _options = {}) + table_name = quote_table_name(table_name) + column_name = quote_column_name(column_name) + + execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{column_name})" + end + + def remove_primary_key(table_name) + table_name = quote_table_name(table_name) + + execute "ALTER TABLE #{table_name} DROP PRIMARY KEY" + end + + def alter_primary_key(table_name, new_columns) + constraint_name = quote_table_name("#{table_name}_pkey") + table_name = quote_table_name(table_name) + new_columns = quote_column_name(new_columns) + + execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint_name}" + execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{new_columns})" + end + + def create_enumeration(enumeration_name, values) + execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')" + end + + def drop_enumeration(enumeration_name) + execute "DROP TYPE #{enumeration_name}" + end + + def rename_enumeration(old_name, new_name) + old_name = quote_table_name(old_name) + new_name = quote_table_name(new_name) + + execute "ALTER TYPE #{old_name} RENAME TO #{new_name}" + end + end + end + end + + ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(OpenStreetMap::ActiveRecord::AbstractAdapter) + ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(OpenStreetMap::ActiveRecord::PostgreSQLAdapter) +end diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb new file mode 100644 index 000000000..803a60cb9 --- /dev/null +++ b/config/initializers/zeitwerk.rb @@ -0,0 +1,9 @@ +Rails.autoloaders.each do |autoloader| + autoloader.inflector.inflect( + "gpx" => "GPX", + "id" => "ID", + "osm" => "OSM", + "rubyvm" => "RubyVM", + "utf8" => "UTF8" + ) +end diff --git a/db/migrate/001_create_osm_db.rb b/db/migrate/001_create_osm_db.rb index 3772c5dc2..43e4bf4b2 100644 --- a/db/migrate/001_create_osm_db.rb +++ b/db/migrate/001_create_osm_db.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateOsmDb < ActiveRecord::Migration[4.2] def self.up create_table "current_nodes", :id => false do |t| diff --git a/db/migrate/002_cleanup_osm_db.rb b/db/migrate/002_cleanup_osm_db.rb index 8728f1a6a..23f988dc1 100644 --- a/db/migrate/002_cleanup_osm_db.rb +++ b/db/migrate/002_cleanup_osm_db.rb @@ -1,5 +1,3 @@ -require "migrate" - class CleanupOsmDb < ActiveRecord::Migration[4.2] def self.up change_column "current_nodes", "latitude", :float, :limit => 53, :null => false diff --git a/db/migrate/003_sql_session_store_setup.rb b/db/migrate/003_sql_session_store_setup.rb index 060ffe089..1be5daf7a 100644 --- a/db/migrate/003_sql_session_store_setup.rb +++ b/db/migrate/003_sql_session_store_setup.rb @@ -1,5 +1,3 @@ -require "migrate" - class SqlSessionStoreSetup < ActiveRecord::Migration[4.2] def self.up create_table "sessions" do |t| diff --git a/db/migrate/004_user_enhancements.rb b/db/migrate/004_user_enhancements.rb index 99da718fd..5d3bc4858 100644 --- a/db/migrate/004_user_enhancements.rb +++ b/db/migrate/004_user_enhancements.rb @@ -1,5 +1,3 @@ -require "migrate" - class UserEnhancements < ActiveRecord::Migration[4.2] def self.up add_column "diary_entries", "latitude", :float, :limit => 53 diff --git a/db/migrate/005_tile_tracepoints.rb b/db/migrate/005_tile_tracepoints.rb index b46fdf25f..0e557067d 100644 --- a/db/migrate/005_tile_tracepoints.rb +++ b/db/migrate/005_tile_tracepoints.rb @@ -1,5 +1,3 @@ -require "migrate" - class TileTracepoints < ActiveRecord::Migration[4.2] class Tracepoint < ApplicationRecord self.table_name = "gps_points" diff --git a/db/migrate/006_tile_nodes.rb b/db/migrate/006_tile_nodes.rb index d13ada170..7fdb34e57 100644 --- a/db/migrate/006_tile_nodes.rb +++ b/db/migrate/006_tile_nodes.rb @@ -1,5 +1,3 @@ -require "migrate" - class TileNodes < ActiveRecord::Migration[4.2] class Node < ApplicationRecord self.table_name = "current_nodes" diff --git a/db/migrate/007_add_relations.rb b/db/migrate/007_add_relations.rb index 05d3c634b..1e5bc5d3a 100644 --- a/db/migrate/007_add_relations.rb +++ b/db/migrate/007_add_relations.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddRelations < ActiveRecord::Migration[4.2] def self.up # enums work like strings but are more efficient diff --git a/db/migrate/008_remove_segments.rb b/db/migrate/008_remove_segments.rb index f8a3085c6..c528742c9 100644 --- a/db/migrate/008_remove_segments.rb +++ b/db/migrate/008_remove_segments.rb @@ -1,5 +1,3 @@ -require "migrate" - class RemoveSegments < ActiveRecord::Migration[4.2] def self.up have_segs = select_value("SELECT count(*) FROM current_segments").to_i.nonzero? diff --git a/db/migrate/010_diary_comments.rb b/db/migrate/010_diary_comments.rb index 94d8a985b..15730bd8e 100644 --- a/db/migrate/010_diary_comments.rb +++ b/db/migrate/010_diary_comments.rb @@ -1,5 +1,3 @@ -require "migrate" - class DiaryComments < ActiveRecord::Migration[4.2] def self.up create_table "diary_comments", :id => false do |t| diff --git a/db/migrate/018_create_acls.rb b/db/migrate/018_create_acls.rb index c5c7c7444..ce5b6d4ca 100644 --- a/db/migrate/018_create_acls.rb +++ b/db/migrate/018_create_acls.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateAcls < ActiveRecord::Migration[4.2] def self.up create_table "acls", :id => false do |t| diff --git a/db/migrate/020_populate_node_tags_and_remove.rb b/db/migrate/020_populate_node_tags_and_remove.rb index fbb5d1af4..c8c017806 100644 --- a/db/migrate/020_populate_node_tags_and_remove.rb +++ b/db/migrate/020_populate_node_tags_and_remove.rb @@ -1,5 +1,3 @@ -require "migrate" - class PopulateNodeTagsAndRemove < ActiveRecord::Migration[4.2] def self.up have_nodes = select_value("SELECT count(*) FROM current_nodes").to_i.nonzero? diff --git a/db/migrate/021_move_to_innodb.rb b/db/migrate/021_move_to_innodb.rb index 81663eb1b..4dac8410c 100644 --- a/db/migrate/021_move_to_innodb.rb +++ b/db/migrate/021_move_to_innodb.rb @@ -1,5 +1,3 @@ -require "migrate" - class MoveToInnodb < ActiveRecord::Migration[4.2] @conv_tables = %w[nodes ways way_tags way_nodes current_way_tags relation_members relations relation_tags current_relation_tags] diff --git a/db/migrate/022_key_constraints.rb b/db/migrate/022_key_constraints.rb index 3030ed2cf..e7840b414 100644 --- a/db/migrate/022_key_constraints.rb +++ b/db/migrate/022_key_constraints.rb @@ -1,5 +1,3 @@ -require "migrate" - class KeyConstraints < ActiveRecord::Migration[4.2] def self.up # Primary keys diff --git a/db/migrate/023_add_changesets.rb b/db/migrate/023_add_changesets.rb index d835b22cb..ff6ce2bb4 100644 --- a/db/migrate/023_add_changesets.rb +++ b/db/migrate/023_add_changesets.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddChangesets < ActiveRecord::Migration[4.2] @conv_user_tables = %w[current_nodes current_relations current_ways nodes relations ways] diff --git a/db/migrate/024_order_relation_members.rb b/db/migrate/024_order_relation_members.rb index c2a3ada32..77ef3a559 100644 --- a/db/migrate/024_order_relation_members.rb +++ b/db/migrate/024_order_relation_members.rb @@ -1,5 +1,3 @@ -require "migrate" - class OrderRelationMembers < ActiveRecord::Migration[4.2] def self.up # add sequence column. rails won't let us define an ordering here, diff --git a/db/migrate/025_add_end_time_to_changesets.rb b/db/migrate/025_add_end_time_to_changesets.rb index 985e57285..c25701088 100644 --- a/db/migrate/025_add_end_time_to_changesets.rb +++ b/db/migrate/025_add_end_time_to_changesets.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddEndTimeToChangesets < ActiveRecord::Migration[4.2] def self.up # swap the boolean closed-or-not for a time when the changeset will diff --git a/db/migrate/028_add_more_changeset_indexes.rb b/db/migrate/028_add_more_changeset_indexes.rb index 3a5e941ed..d7a6df7ab 100644 --- a/db/migrate/028_add_more_changeset_indexes.rb +++ b/db/migrate/028_add_more_changeset_indexes.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddMoreChangesetIndexes < ActiveRecord::Migration[4.2] def self.up add_index "changesets", ["created_at"], :name => "changesets_created_at_idx" diff --git a/db/migrate/029_add_user_foreign_keys.rb b/db/migrate/029_add_user_foreign_keys.rb index d91b9a17e..33ba25721 100644 --- a/db/migrate/029_add_user_foreign_keys.rb +++ b/db/migrate/029_add_user_foreign_keys.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddUserForeignKeys < ActiveRecord::Migration[4.2] def change add_foreign_key :changesets, :users, :name => "changesets_user_id_fkey" diff --git a/db/migrate/030_add_foreign_keys.rb b/db/migrate/030_add_foreign_keys.rb index ed7652543..ded44d772 100644 --- a/db/migrate/030_add_foreign_keys.rb +++ b/db/migrate/030_add_foreign_keys.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddForeignKeys < ActiveRecord::Migration[4.2] def self.up add_foreign_key :changeset_tags, :changesets, :column => :id, :name => "changeset_tags_id_fkey" diff --git a/db/migrate/031_create_countries.rb b/db/migrate/031_create_countries.rb index bdb247036..c26bdd08c 100644 --- a/db/migrate/031_create_countries.rb +++ b/db/migrate/031_create_countries.rb @@ -1,4 +1,3 @@ -require "migrate" require "rexml/document" class CreateCountries < ActiveRecord::Migration[4.2] diff --git a/db/migrate/034_create_languages.rb b/db/migrate/034_create_languages.rb index 20b80ec5b..245903551 100644 --- a/db/migrate/034_create_languages.rb +++ b/db/migrate/034_create_languages.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateLanguages < ActiveRecord::Migration[4.2] def change create_table :languages, :id => false do |t| diff --git a/db/migrate/035_change_user_locale.rb b/db/migrate/035_change_user_locale.rb index 3de3492c8..d1315fa06 100644 --- a/db/migrate/035_change_user_locale.rb +++ b/db/migrate/035_change_user_locale.rb @@ -1,5 +1,3 @@ -require "migrate" - class ChangeUserLocale < ActiveRecord::Migration[4.2] def self.up remove_foreign_key :users, :column => :locale, :name => "users_locale_fkey" diff --git a/db/migrate/039_add_more_controls_to_gpx_files.rb b/db/migrate/039_add_more_controls_to_gpx_files.rb index 2c3fee5be..728b56989 100644 --- a/db/migrate/039_add_more_controls_to_gpx_files.rb +++ b/db/migrate/039_add_more_controls_to_gpx_files.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddMoreControlsToGpxFiles < ActiveRecord::Migration[4.2] class Trace < ApplicationRecord self.table_name = "gpx_files" diff --git a/db/migrate/042_add_foreign_keys_to_oauth_tables.rb b/db/migrate/042_add_foreign_keys_to_oauth_tables.rb index b302458c7..a57fe9885 100644 --- a/db/migrate/042_add_foreign_keys_to_oauth_tables.rb +++ b/db/migrate/042_add_foreign_keys_to_oauth_tables.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddForeignKeysToOauthTables < ActiveRecord::Migration[4.2] def change add_foreign_key :oauth_tokens, :users, :name => "oauth_tokens_user_id_fkey" diff --git a/db/migrate/044_create_user_roles.rb b/db/migrate/044_create_user_roles.rb index 0039859bf..ece98a54d 100644 --- a/db/migrate/044_create_user_roles.rb +++ b/db/migrate/044_create_user_roles.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateUserRoles < ActiveRecord::Migration[4.2] class User < ApplicationRecord end diff --git a/db/migrate/045_create_user_blocks.rb b/db/migrate/045_create_user_blocks.rb index 182e2f498..4328e0b97 100644 --- a/db/migrate/045_create_user_blocks.rb +++ b/db/migrate/045_create_user_blocks.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateUserBlocks < ActiveRecord::Migration[4.2] def change create_table :user_blocks do |t| diff --git a/db/migrate/046_alter_user_roles_and_blocks.rb b/db/migrate/046_alter_user_roles_and_blocks.rb index b10fcf144..c1d3cd987 100644 --- a/db/migrate/046_alter_user_roles_and_blocks.rb +++ b/db/migrate/046_alter_user_roles_and_blocks.rb @@ -1,5 +1,3 @@ -require "migrate" - class AlterUserRolesAndBlocks < ActiveRecord::Migration[4.2] class UserRole < ApplicationRecord end diff --git a/db/migrate/051_add_status_to_user.rb b/db/migrate/051_add_status_to_user.rb index 23761f248..f170e0de8 100644 --- a/db/migrate/051_add_status_to_user.rb +++ b/db/migrate/051_add_status_to_user.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddStatusToUser < ActiveRecord::Migration[4.2] class User < ApplicationRecord end diff --git a/db/migrate/053_add_map_bug_tables.rb b/db/migrate/053_add_map_bug_tables.rb index e8e01ec07..6ad3af0eb 100644 --- a/db/migrate/053_add_map_bug_tables.rb +++ b/db/migrate/053_add_map_bug_tables.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddMapBugTables < ActiveRecord::Migration[4.2] def self.up create_enumeration :map_bug_status_enum, %w[open closed hidden] diff --git a/db/migrate/054_refactor_map_bug_tables.rb b/db/migrate/054_refactor_map_bug_tables.rb index 4bd713bd7..23221c7b1 100644 --- a/db/migrate/054_refactor_map_bug_tables.rb +++ b/db/migrate/054_refactor_map_bug_tables.rb @@ -1,5 +1,3 @@ -require "migrate" - class RefactorMapBugTables < ActiveRecord::Migration[4.2] def self.up create_table :map_bug_comment do |t| diff --git a/db/migrate/055_change_map_bug_comment_type.rb b/db/migrate/055_change_map_bug_comment_type.rb index c206325fa..1fab93b44 100644 --- a/db/migrate/055_change_map_bug_comment_type.rb +++ b/db/migrate/055_change_map_bug_comment_type.rb @@ -1,5 +1,3 @@ -require "migrate" - class ChangeMapBugCommentType < ActiveRecord::Migration[4.2] def self.up change_column :map_bug_comment, :comment, :text diff --git a/db/migrate/056_add_date_closed.rb b/db/migrate/056_add_date_closed.rb index 57efa7c8a..b6da41466 100644 --- a/db/migrate/056_add_date_closed.rb +++ b/db/migrate/056_add_date_closed.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddDateClosed < ActiveRecord::Migration[4.2] def self.up add_column :map_bugs, :date_closed, :timestamp diff --git a/db/migrate/057_add_map_bug_comment_event.rb b/db/migrate/057_add_map_bug_comment_event.rb index ecdb967a1..c88544099 100644 --- a/db/migrate/057_add_map_bug_comment_event.rb +++ b/db/migrate/057_add_map_bug_comment_event.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddMapBugCommentEvent < ActiveRecord::Migration[4.2] def self.up create_enumeration :map_bug_event_enum, %w[opened closed reopened commented hidden] diff --git a/db/migrate/20110521142405_rename_bugs_to_notes.rb b/db/migrate/20110521142405_rename_bugs_to_notes.rb index 54b443b32..d3260dfa1 100644 --- a/db/migrate/20110521142405_rename_bugs_to_notes.rb +++ b/db/migrate/20110521142405_rename_bugs_to_notes.rb @@ -1,5 +1,3 @@ -require "migrate" - class RenameBugsToNotes < ActiveRecord::Migration[4.2] def self.up rename_enumeration "map_bug_status_enum", "note_status_enum" diff --git a/db/migrate/20111212183945_add_lowercase_user_indexes.rb b/db/migrate/20111212183945_add_lowercase_user_indexes.rb index 202b23388..df6a48c16 100644 --- a/db/migrate/20111212183945_add_lowercase_user_indexes.rb +++ b/db/migrate/20111212183945_add_lowercase_user_indexes.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddLowercaseUserIndexes < ActiveRecord::Migration[4.2] def up add_index :users, [], :columns => "LOWER(display_name)", :name => "users_display_name_lower_idx" diff --git a/db/migrate/20120214210114_add_text_format.rb b/db/migrate/20120214210114_add_text_format.rb index 6ec84ce44..be8089a74 100644 --- a/db/migrate/20120214210114_add_text_format.rb +++ b/db/migrate/20120214210114_add_text_format.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddTextFormat < ActiveRecord::Migration[4.2] def up create_enumeration :format_enum, %w[html markdown text] diff --git a/db/migrate/20120318201948_create_redactions.rb b/db/migrate/20120318201948_create_redactions.rb index e108ea84b..3f6eec613 100644 --- a/db/migrate/20120318201948_create_redactions.rb +++ b/db/migrate/20120318201948_create_redactions.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateRedactions < ActiveRecord::Migration[4.2] def change create_table :redactions do |t| diff --git a/db/migrate/20120328090602_drop_session_table.rb b/db/migrate/20120328090602_drop_session_table.rb index 5423974e5..7046281df 100644 --- a/db/migrate/20120328090602_drop_session_table.rb +++ b/db/migrate/20120328090602_drop_session_table.rb @@ -1,5 +1,3 @@ -require "migrate" - class DropSessionTable < ActiveRecord::Migration[4.2] def up drop_table "sessions" diff --git a/db/migrate/20120404205604_add_user_and_description_to_redaction.rb b/db/migrate/20120404205604_add_user_and_description_to_redaction.rb index f23bd2ffc..56ef05253 100644 --- a/db/migrate/20120404205604_add_user_and_description_to_redaction.rb +++ b/db/migrate/20120404205604_add_user_and_description_to_redaction.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddUserAndDescriptionToRedaction < ActiveRecord::Migration[4.2] def change add_column :redactions, :user_id, :bigint, :null => false diff --git a/db/migrate/20140115192822_add_text_index_to_note_comments.rb b/db/migrate/20140115192822_add_text_index_to_note_comments.rb index dc17d386e..1c30450ef 100644 --- a/db/migrate/20140115192822_add_text_index_to_note_comments.rb +++ b/db/migrate/20140115192822_add_text_index_to_note_comments.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddTextIndexToNoteComments < ActiveRecord::Migration[4.2] def up add_index :note_comments, [], :columns => "to_tsvector('english', body)", :using => "GIN", :name => "index_note_comments_on_body" diff --git a/db/migrate/20140507110937_create_changeset_comments.rb b/db/migrate/20140507110937_create_changeset_comments.rb index fdcdaf65d..796919c51 100644 --- a/db/migrate/20140507110937_create_changeset_comments.rb +++ b/db/migrate/20140507110937_create_changeset_comments.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateChangesetComments < ActiveRecord::Migration[4.2] def change create_table :changeset_comments do |t| diff --git a/db/migrate/20140519141742_add_join_table_between_users_and_changesets.rb b/db/migrate/20140519141742_add_join_table_between_users_and_changesets.rb index c761af38b..221a740c5 100644 --- a/db/migrate/20140519141742_add_join_table_between_users_and_changesets.rb +++ b/db/migrate/20140519141742_add_join_table_between_users_and_changesets.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddJoinTableBetweenUsersAndChangesets < ActiveRecord::Migration[4.2] def change create_table :changesets_subscribers, :id => false do |t| diff --git a/db/migrate/20160822153055_create_issues_and_reports.rb b/db/migrate/20160822153055_create_issues_and_reports.rb index 544ddbd60..07a549820 100644 --- a/db/migrate/20160822153055_create_issues_and_reports.rb +++ b/db/migrate/20160822153055_create_issues_and_reports.rb @@ -1,5 +1,3 @@ -require "migrate" - class CreateIssuesAndReports < ActiveRecord::Migration[5.0] def up create_enumeration :issue_status_enum, %w[open ignored resolved] diff --git a/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb b/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb index 624eb10f9..4151d19a3 100644 --- a/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb +++ b/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb @@ -1,5 +1,3 @@ -require "migrate" - class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration[4.2] def self.up create_table :diary_entry_subscriptions, :id => false do |t| diff --git a/lib/migrate.rb b/lib/migrate.rb deleted file mode 100644 index d87d14bbb..000000000 --- a/lib/migrate.rb +++ /dev/null @@ -1,57 +0,0 @@ -module OpenStreetMap - module ActiveRecord - module AbstractAdapter - def add_index_options(table_name, column_name, options = {}) - columns = options.delete(:columns) - index_name, index_type, index_columns, index_options, algorithm, using = super(table_name, column_name, options) - [index_name, index_type, columns || index_columns, index_options, algorithm, using] - end - end - - module PostgreSQLAdapter - def quote_column_name(name) - Array(name).map { |n| super(n) }.join(", ") - end - - def add_primary_key(table_name, column_name, _options = {}) - table_name = quote_table_name(table_name) - column_name = quote_column_name(column_name) - - execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{column_name})" - end - - def remove_primary_key(table_name) - table_name = quote_table_name(table_name) - - execute "ALTER TABLE #{table_name} DROP PRIMARY KEY" - end - - def alter_primary_key(table_name, new_columns) - constraint_name = quote_table_name("#{table_name}_pkey") - table_name = quote_table_name(table_name) - new_columns = quote_column_name(new_columns) - - execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint_name}" - execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{new_columns})" - end - - def create_enumeration(enumeration_name, values) - execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')" - end - - def drop_enumeration(enumeration_name) - execute "DROP TYPE #{enumeration_name}" - end - - def rename_enumeration(old_name, new_name) - old_name = quote_table_name(old_name) - new_name = quote_table_name(new_name) - - execute "ALTER TYPE #{old_name} RENAME TO #{new_name}" - end - end - end -end - -ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(OpenStreetMap::ActiveRecord::AbstractAdapter) -ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(OpenStreetMap::ActiveRecord::PostgreSQLAdapter) -- 2.39.5