diff --git a/config/initializers/uuid_primary_keys.rb b/config/initializers/uuid_primary_keys.rb index 1b41315ec..698da184f 100644 --- a/config/initializers/uuid_primary_keys.rb +++ b/config/initializers/uuid_primary_keys.rb @@ -1,15 +1,5 @@ # Automatically use UUID type for all binary(16) columns -# Define schema dumper module outside on_load so it can be prepended -module SchemaDumperUuidType - # Map binary(16) and blob(16) columns to :uuid type in schema.rb - def schema_type(column) - return :uuid if column.sql_type == "binary(16)" - return :uuid if column.sql_type == "blob(16)" - super - end -end - ActiveSupport.on_load(:active_record) do module MysqlUuidAdapter # Add UUID to MySQL's native database types @@ -32,7 +22,6 @@ ActiveSupport.on_load(:active_record) do end module SqliteUuidAdapter - # Add UUID to SQLite's native database types (instance method) def native_database_types @native_database_types_with_uuid ||= super.merge(uuid: { name: "blob", limit: 16 }) end @@ -77,17 +66,15 @@ ActiveSupport.on_load(:active_record) do end end - # Ensure schema dumper classes are loaded before prepending - begin - require 'active_record/connection_adapters/mysql/schema_dumper' - rescue LoadError - # MySQL adapter not available - end - - begin - require 'active_record/connection_adapters/sqlite3/schema_dumper' - rescue LoadError - # SQLite3 adapter not available + module SchemaDumperUuidType + # Map binary(16) and blob(16) columns to :uuid type in schema.rb + def schema_type(column) + if column.sql_type == "binary(16)" || column.sql_type == "blob(16)" + :uuid + else + super + end + end end if defined?(ActiveRecord::ConnectionAdapters::MySQL::SchemaDumper)