Simplify patching

This commit is contained in:
Donal McBreen
2025-11-21 09:08:52 +00:00
parent 33ef482189
commit dd18b6641d
+9 -22
View File
@@ -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)