From be83bf4dee205d838a891aaf3b74fa0efc81caa3 Mon Sep 17 00:00:00 2001 From: Adrianna Chang Date: Wed, 10 Aug 2022 14:15:14 -0400 Subject: [PATCH] Expose #schema_creation methods Accessing SchemaCreation instances allows consumers to visit schema definitions and produce DDL / populate the definitions with DDL type information. --- .../connection_adapters/abstract/schema_statements.rb | 10 ++++++---- .../connection_adapters/mysql/schema_statements.rb | 8 ++++---- .../postgresql/schema_statements.rb | 8 ++++---- .../connection_adapters/sqlite3/schema_statements.rb | 8 ++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 8eb4dd9e061fb..53ab229b90f21 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1448,6 +1448,12 @@ def use_foreign_keys? supports_foreign_keys? && foreign_keys_enabled? end + # Returns an instance of SchemaCreation, which can be used to visit a schema definition + # object and return DDL. + def schema_creation # :nodoc: + SchemaCreation.new(self) + end + private def check_constraint_exists?(table_name, **options) check_constraint_for(table_name, **options).present? @@ -1542,10 +1548,6 @@ def rename_column_indexes(table_name, column_name, new_column_name) end end - def schema_creation - SchemaCreation.new(self) - end - def create_table_definition(name, **options) TableDefinition.new(self, name, **options) end diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb index e14aa0b3bc362..67ef8c1ec2d77 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb @@ -125,6 +125,10 @@ def table_alias_length 256 # https://dev.mysql.com/doc/refman/en/identifiers.html end + def schema_creation # :nodoc: + MySQL::SchemaCreation.new(self) + end + private CHARSETS_OF_4BYTES_MAXLEN = ["utf8mb4", "utf16", "utf16le", "utf32"] @@ -150,10 +154,6 @@ def default_row_format @default_row_format end - def schema_creation - MySQL::SchemaCreation.new(self) - end - def create_table_definition(name, **options) MySQL::TableDefinition.new(self, name, **options) end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 6ea900c9a2454..120822f3dcd49 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -759,11 +759,11 @@ def foreign_key_column_for(table_name) # :nodoc: super end - private - def schema_creation - PostgreSQL::SchemaCreation.new(self) - end + def schema_creation # :nodoc: + PostgreSQL::SchemaCreation.new(self) + end + private def create_table_definition(name, **options) PostgreSQL::TableDefinition.new(self, name, **options) end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb index fff5e1095e7b1..f3f46b6025030 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb @@ -115,11 +115,11 @@ def create_schema_dumper(options) SQLite3::SchemaDumper.create(self, options) end - private - def schema_creation - SQLite3::SchemaCreation.new(self) - end + def schema_creation # :nodoc + SQLite3::SchemaCreation.new(self) + end + private def create_table_definition(name, **options) SQLite3::TableDefinition.new(self, name, **options) end