Skip to content

Commit

Permalink
Switch to using the zeitwork autoloader
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Dec 30, 2020
1 parent 786b8cc commit eada36f
Show file tree
Hide file tree
Showing 50 changed files with 71 additions and 148 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class Application < Rails::Application
# 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
Expand Down
59 changes: 59 additions & 0 deletions config/initializers/migrate.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions config/initializers/zeitwerk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Rails.autoloaders.each do |autoloader|
autoloader.inflector.inflect(
"gpx" => "GPX",
"id" => "ID",
"osm" => "OSM",
"rubyvm" => "RubyVM",
"utf8" => "UTF8"
)
end
2 changes: 0 additions & 2 deletions db/migrate/001_create_osm_db.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateOsmDb < ActiveRecord::Migration[4.2]
def self.up
create_table "current_nodes", :id => false do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/002_cleanup_osm_db.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/003_sql_session_store_setup.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class SqlSessionStoreSetup < ActiveRecord::Migration[4.2]
def self.up
create_table "sessions" do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/004_user_enhancements.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class UserEnhancements < ActiveRecord::Migration[4.2]
def self.up
add_column "diary_entries", "latitude", :float, :limit => 53
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/005_tile_tracepoints.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class TileTracepoints < ActiveRecord::Migration[4.2]
class Tracepoint < ApplicationRecord
self.table_name = "gps_points"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/006_tile_nodes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class TileNodes < ActiveRecord::Migration[4.2]
class Node < ApplicationRecord
self.table_name = "current_nodes"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/007_add_relations.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddRelations < ActiveRecord::Migration[4.2]
def self.up
# enums work like strings but are more efficient
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/008_remove_segments.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/010_diary_comments.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class DiaryComments < ActiveRecord::Migration[4.2]
def self.up
create_table "diary_comments", :id => false do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/018_create_acls.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateAcls < ActiveRecord::Migration[4.2]
def self.up
create_table "acls", :id => false do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/020_populate_node_tags_and_remove.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/021_move_to_innodb.rb
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
2 changes: 0 additions & 2 deletions db/migrate/022_key_constraints.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class KeyConstraints < ActiveRecord::Migration[4.2]
def self.up
# Primary keys
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/023_add_changesets.rb
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
2 changes: 0 additions & 2 deletions db/migrate/024_order_relation_members.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/025_add_end_time_to_changesets.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/028_add_more_changeset_indexes.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/029_add_user_foreign_keys.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddUserForeignKeys < ActiveRecord::Migration[4.2]
def change
add_foreign_key :changesets, :users, :name => "changesets_user_id_fkey"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/030_add_foreign_keys.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 0 additions & 1 deletion db/migrate/031_create_countries.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "migrate"
require "rexml/document"

class CreateCountries < ActiveRecord::Migration[4.2]
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/034_create_languages.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateLanguages < ActiveRecord::Migration[4.2]
def change
create_table :languages, :id => false do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/035_change_user_locale.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/039_add_more_controls_to_gpx_files.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddMoreControlsToGpxFiles < ActiveRecord::Migration[4.2]
class Trace < ApplicationRecord
self.table_name = "gpx_files"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/042_add_foreign_keys_to_oauth_tables.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/044_create_user_roles.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateUserRoles < ActiveRecord::Migration[4.2]
class User < ApplicationRecord
end
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/045_create_user_blocks.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateUserBlocks < ActiveRecord::Migration[4.2]
def change
create_table :user_blocks do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/046_alter_user_roles_and_blocks.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AlterUserRolesAndBlocks < ActiveRecord::Migration[4.2]
class UserRole < ApplicationRecord
end
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/051_add_status_to_user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddStatusToUser < ActiveRecord::Migration[4.2]
class User < ApplicationRecord
end
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/053_add_map_bug_tables.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/054_refactor_map_bug_tables.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class RefactorMapBugTables < ActiveRecord::Migration[4.2]
def self.up
create_table :map_bug_comment do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/055_change_map_bug_comment_type.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class ChangeMapBugCommentType < ActiveRecord::Migration[4.2]
def self.up
change_column :map_bug_comment, :comment, :text
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/056_add_date_closed.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddDateClosed < ActiveRecord::Migration[4.2]
def self.up
add_column :map_bugs, :date_closed, :timestamp
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/057_add_map_bug_comment_event.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20110521142405_rename_bugs_to_notes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class RenameBugsToNotes < ActiveRecord::Migration[4.2]
def self.up
rename_enumeration "map_bug_status_enum", "note_status_enum"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20111212183945_add_lowercase_user_indexes.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20120214210114_add_text_format.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddTextFormat < ActiveRecord::Migration[4.2]
def up
create_enumeration :format_enum, %w[html markdown text]
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20120318201948_create_redactions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateRedactions < ActiveRecord::Migration[4.2]
def change
create_table :redactions do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20120328090602_drop_session_table.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class DropSessionTable < ActiveRecord::Migration[4.2]
def up
drop_table "sessions"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddUserAndDescriptionToRedaction < ActiveRecord::Migration[4.2]
def change
add_column :redactions, :user_id, :bigint, :null => false
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20140115192822_add_text_index_to_note_comments.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20140507110937_create_changeset_comments.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateChangesetComments < ActiveRecord::Migration[4.2]
def change
create_table :changeset_comments do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddJoinTableBetweenUsersAndChangesets < ActiveRecord::Migration[4.2]
def change
create_table :changesets_subscribers, :id => false do |t|
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20160822153055_create_issues_and_reports.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
def up
create_enumeration :issue_status_enum, %w[open ignored resolved]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "migrate"

class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration[4.2]
def self.up
create_table :diary_entry_subscriptions, :id => false do |t|
Expand Down
Loading

0 comments on commit eada36f

Please sign in to comment.