forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define #build_create_table_definition on connection adapter
Define API on connection adapter for building a TableDefinition. The provided TableDefinition object offers insight into what a table created using the migration method #create_table would look like, including information on primary keys, column types, etc. As a part of this PR, we extract TableDefinition#set_primary_key to handle some of the primary key setting logic currently being performed in #create_table.
- Loading branch information
1 parent
fa7f977
commit d747b0f
Showing
4 changed files
with
75 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
activerecord/test/cases/migration/schema_definitions_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
|
||
module ActiveRecord | ||
class Migration | ||
class SchemaDefinitionsTest < ActiveRecord::TestCase | ||
attr_reader :connection | ||
|
||
def setup | ||
@connection = ActiveRecord::Base.connection | ||
end | ||
|
||
def test_build_create_table_definition_with_block | ||
td = connection.build_create_table_definition :test do |t| | ||
t.column :foo, :string | ||
end | ||
|
||
id_column = td.columns.find { |col| col.name == "id" } | ||
assert_predicate id_column, :present? | ||
assert id_column.type | ||
assert id_column.sql_type | ||
|
||
foo_column = td.columns.find { |col| col.name == "foo" } | ||
assert_predicate foo_column, :present? | ||
assert foo_column.type | ||
assert foo_column.sql_type | ||
end | ||
|
||
def test_build_create_table_definition_without_block | ||
td = connection.build_create_table_definition(:test) | ||
|
||
id_column = td.columns.find { |col| col.name == "id" } | ||
assert_predicate id_column, :present? | ||
assert id_column.type | ||
assert id_column.sql_type | ||
end | ||
end | ||
end | ||
end |