aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/schema
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/schema')
-rw-r--r--activerecord/test/schema/mysql2_specific_schema.rb66
-rw-r--r--activerecord/test/schema/oracle_specific_schema.rb24
-rw-r--r--activerecord/test/schema/schema.rb172
-rw-r--r--activerecord/test/schema/sqlite_specific_schema.rb11
4 files changed, 151 insertions, 122 deletions
diff --git a/activerecord/test/schema/mysql2_specific_schema.rb b/activerecord/test/schema/mysql2_specific_schema.rb
index 8371ba9528..b143035213 100644
--- a/activerecord/test/schema/mysql2_specific_schema.rb
+++ b/activerecord/test/schema/mysql2_specific_schema.rb
@@ -14,9 +14,20 @@ ActiveRecord::Schema.define do
end
end
+ create_table :defaults, force: true do |t|
+ t.date :fixed_date, default: "2004-01-01"
+ t.datetime :fixed_time, default: "2004-01-01 00:00:00"
+ t.column :char1, "char(1)", default: "Y"
+ t.string :char2, limit: 50, default: "a varchar field"
+ if supports_default_expression?
+ t.binary :uuid, limit: 36, default: -> { "(uuid())" }
+ end
+ end
+
create_table :binary_fields, force: true do |t|
t.binary :var_binary, limit: 255
t.binary :var_binary_large, limit: 4095
+
t.tinyblob :tiny_blob
t.blob :normal_blob
t.mediumblob :medium_blob
@@ -26,10 +37,17 @@ ActiveRecord::Schema.define do
t.mediumtext :medium_text
t.longtext :long_text
+ t.binary :tiny_blob_2, size: :tiny
+ t.binary :medium_blob_2, size: :medium
+ t.binary :long_blob_2, size: :long
+ t.text :tiny_text_2, size: :tiny
+ t.text :medium_text_2, size: :medium
+ t.text :long_text_2, size: :long
+
t.index :var_binary
end
- create_table :key_tests, force: true, options: "ENGINE=MyISAM" do |t|
+ create_table :key_tests, force: true do |t|
t.string :awesome
t.string :pizza
t.string :snacks
@@ -39,38 +57,30 @@ ActiveRecord::Schema.define do
end
create_table :collation_tests, id: false, force: true do |t|
- t.string :string_cs_column, limit: 1, collation: "utf8_bin"
- t.string :string_ci_column, limit: 1, collation: "utf8_general_ci"
+ t.string :string_cs_column, limit: 1, collation: "utf8mb4_bin"
+ t.string :string_ci_column, limit: 1, collation: "utf8mb4_general_ci"
t.binary :binary_column, limit: 1
end
- ActiveRecord::Base.connection.execute <<-SQL
-DROP PROCEDURE IF EXISTS ten;
-SQL
-
- ActiveRecord::Base.connection.execute <<-SQL
-CREATE PROCEDURE ten() SQL SECURITY INVOKER
-BEGIN
- select 10;
-END
-SQL
+ create_table :enum_tests, id: false, force: true do |t|
+ t.column :enum_column, "ENUM('text','blob','tiny','medium','long','unsigned','bigint')"
+ end
- ActiveRecord::Base.connection.execute <<-SQL
-DROP PROCEDURE IF EXISTS topics;
-SQL
+ execute "DROP PROCEDURE IF EXISTS ten"
- ActiveRecord::Base.connection.execute <<-SQL
-CREATE PROCEDURE topics(IN num INT) SQL SECURITY INVOKER
-BEGIN
- select * from topics limit num;
-END
-SQL
+ execute <<~SQL
+ CREATE PROCEDURE ten() SQL SECURITY INVOKER
+ BEGIN
+ SELECT 10;
+ END
+ SQL
- ActiveRecord::Base.connection.drop_table "enum_tests", if_exists: true
+ execute "DROP PROCEDURE IF EXISTS topics"
- ActiveRecord::Base.connection.execute <<-SQL
-CREATE TABLE enum_tests (
- enum_column ENUM('text','blob','tiny','medium','long','unsigned','bigint')
-)
-SQL
+ execute <<~SQL
+ CREATE PROCEDURE topics(IN num INT) SQL SECURITY INVOKER
+ BEGIN
+ SELECT * FROM topics LIMIT num;
+ END
+ SQL
end
diff --git a/activerecord/test/schema/oracle_specific_schema.rb b/activerecord/test/schema/oracle_specific_schema.rb
index bc1e45ca80..08c6e24555 100644
--- a/activerecord/test/schema/oracle_specific_schema.rb
+++ b/activerecord/test/schema/oracle_specific_schema.rb
@@ -7,23 +7,21 @@ ActiveRecord::Schema.define do
execute "drop table defaults" rescue nil
execute "drop sequence defaults_seq" rescue nil
- execute <<-SQL
-create table test_oracle_defaults (
- id integer not null primary key,
- test_char char(1) default 'X' not null,
- test_string varchar2(20) default 'hello' not null,
- test_int integer default 3 not null
-)
+ execute <<~SQL
+ create table test_oracle_defaults (
+ id integer not null primary key,
+ test_char char(1) default 'X' not null,
+ test_string varchar2(20) default 'hello' not null,
+ test_int integer default 3 not null
+ )
SQL
- execute <<-SQL
-create sequence test_oracle_defaults_seq minvalue 10000
- SQL
+ execute "create sequence test_oracle_defaults_seq minvalue 10000"
execute "create sequence companies_nonstd_seq minvalue 10000"
- execute <<-SQL
- CREATE TABLE defaults (
+ execute <<~SQL
+ CREATE TABLE defaults (
id integer not null,
modified_date date default sysdate,
modified_date_function date default sysdate,
@@ -34,7 +32,7 @@ create sequence test_oracle_defaults_seq minvalue 10000
char1 varchar2(1) default 'Y',
char2 varchar2(50) default 'a varchar field',
char3 clob default 'a text field'
- )
+ )
SQL
execute "create sequence defaults_seq minvalue 10000"
end
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 02520fc0cc..7d9b8afeb6 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -8,10 +8,18 @@ ActiveRecord::Schema.define do
# #
# ------------------------------------------------------------------- #
+ case_sensitive_options =
+ if current_adapter?(:Mysql2Adapter)
+ { collation: "utf8mb4_bin" }
+ else
+ {}
+ end
+
create_table :accounts, force: true do |t|
t.references :firm, index: false
t.string :firm_name
t.integer :credit_limit
+ t.integer "a" * max_identifier_length
end
create_table :admin_accounts, force: true do |t|
@@ -93,19 +101,24 @@ ActiveRecord::Schema.define do
t.integer :pirate_id
end
- create_table :books, force: true do |t|
+ create_table :books, id: :integer, force: true do |t|
+ default_zero = { default: 0 }
t.references :author
t.string :format
t.column :name, :string
- t.column :status, :integer, default: 0
- t.column :read_status, :integer, default: 0
+ t.column :status, :integer, **default_zero
+ t.column :read_status, :integer, **default_zero
t.column :nullable_status, :integer
- t.column :language, :integer, default: 0
- t.column :author_visibility, :integer, default: 0
- t.column :illustrator_visibility, :integer, default: 0
- t.column :font_size, :integer, default: 0
- t.column :difficulty, :integer, default: 0
+ t.column :language, :integer, **default_zero
+ t.column :author_visibility, :integer, **default_zero
+ t.column :illustrator_visibility, :integer, **default_zero
+ t.column :font_size, :integer, **default_zero
+ t.column :difficulty, :integer, **default_zero
t.column :cover, :string, default: "hard"
+ t.string :isbn
+ t.datetime :published_on
+ t.index [:author_id, :name], unique: true
+ t.index :isbn, where: "published_on IS NOT NULL", unique: true
end
create_table :booleans, force: true do |t|
@@ -158,8 +171,9 @@ ActiveRecord::Schema.define do
end
create_table :citations, force: true do |t|
- t.column :book1_id, :integer
- t.column :book2_id, :integer
+ t.references :book1
+ t.references :book2
+ t.references :citation
end
create_table :clubs, force: true do |t|
@@ -215,7 +229,7 @@ ActiveRecord::Schema.define do
t.index [:firm_id, :type, :rating], name: "company_index", length: { type: 10 }, order: { rating: :desc }
t.index [:firm_id, :type], name: "company_partial_index", where: "(rating > 10)"
t.index :name, name: "company_name_index", using: :btree
- t.index "(CASE WHEN rating > 0 THEN lower(name) END)", name: "company_expression_index" if supports_expression_index?
+ t.index "(CASE WHEN rating > 0 THEN lower(name) END) DESC", name: "company_expression_index" if supports_expression_index?
end
create_table :content, force: true do |t|
@@ -246,6 +260,7 @@ ActiveRecord::Schema.define do
create_table :contracts, force: true do |t|
t.references :developer, index: false
t.references :company, index: false
+ t.string :metadata
end
create_table :customers, force: true do |t|
@@ -263,7 +278,7 @@ ActiveRecord::Schema.define do
end
create_table :dashboards, force: true, id: false do |t|
- t.string :dashboard_id
+ t.string :dashboard_id, **case_sensitive_options
t.string :name
end
@@ -327,7 +342,7 @@ ActiveRecord::Schema.define do
end
create_table :essays, force: true do |t|
- t.string :name
+ t.string :name, **case_sensitive_options
t.string :writer_id
t.string :writer_type
t.string :category_id
@@ -335,7 +350,7 @@ ActiveRecord::Schema.define do
end
create_table :events, force: true do |t|
- t.string :title, limit: 5
+ t.string :title, limit: 5, **case_sensitive_options
end
create_table :eyes, force: true do |t|
@@ -377,7 +392,7 @@ ActiveRecord::Schema.define do
end
create_table :guids, force: true do |t|
- t.column :key, :string
+ t.column :key, :string, **case_sensitive_options
end
create_table :guitars, force: true do |t|
@@ -385,8 +400,8 @@ ActiveRecord::Schema.define do
end
create_table :inept_wizards, force: true do |t|
- t.column :name, :string, null: false
- t.column :city, :string, null: false
+ t.column :name, :string, null: false, **case_sensitive_options
+ t.column :city, :string, null: false, **case_sensitive_options
t.column :type, :string
end
@@ -600,33 +615,55 @@ ActiveRecord::Schema.define do
t.integer :non_poly_two_id
end
- create_table :parrots, force: true do |t|
- t.column :name, :string
- t.column :color, :string
- t.column :parrot_sti_class, :string
- t.column :killer_id, :integer
- t.column :updated_count, :integer, default: 0
- if subsecond_precision_supported?
- t.column :created_at, :datetime, precision: 0
- t.column :created_on, :datetime, precision: 0
- t.column :updated_at, :datetime, precision: 0
- t.column :updated_on, :datetime, precision: 0
- else
- t.column :created_at, :datetime
- t.column :created_on, :datetime
- t.column :updated_at, :datetime
- t.column :updated_on, :datetime
+ disable_referential_integrity do
+ create_table :parrots, force: :cascade do |t|
+ t.string :name
+ t.string :color
+ t.string :parrot_sti_class
+ t.integer :killer_id
+ t.integer :updated_count, :integer, default: 0
+ if subsecond_precision_supported?
+ t.datetime :created_at, precision: 0
+ t.datetime :created_on, precision: 0
+ t.datetime :updated_at, precision: 0
+ t.datetime :updated_on, precision: 0
+ else
+ t.datetime :created_at
+ t.datetime :created_on
+ t.datetime :updated_at
+ t.datetime :updated_on
+ end
end
- end
- create_table :parrots_pirates, id: false, force: true do |t|
- t.column :parrot_id, :integer
- t.column :pirate_id, :integer
- end
+ create_table :pirates, force: :cascade do |t|
+ t.string :catchphrase
+ t.integer :parrot_id
+ t.integer :non_validated_parrot_id
+ if subsecond_precision_supported?
+ t.datetime :created_on, precision: 6
+ t.datetime :updated_on, precision: 6
+ else
+ t.datetime :created_on
+ t.datetime :updated_on
+ end
+ end
- create_table :parrots_treasures, id: false, force: true do |t|
- t.column :parrot_id, :integer
- t.column :treasure_id, :integer
+ create_table :treasures, force: :cascade do |t|
+ t.string :name
+ t.string :type
+ t.references :looter, polymorphic: true
+ t.references :ship
+ end
+
+ create_table :parrots_pirates, id: false, force: true do |t|
+ t.references :parrot, foreign_key: true
+ t.references :pirate, foreign_key: true
+ end
+
+ create_table :parrots_treasures, id: false, force: true do |t|
+ t.references :parrot, foreign_key: true
+ t.references :treasure, foreign_key: true
+ end
end
create_table :people, force: true do |t|
@@ -659,11 +696,7 @@ ActiveRecord::Schema.define do
create_table :pets, primary_key: :pet_id, force: true do |t|
t.string :name
t.integer :owner_id, :integer
- if subsecond_precision_supported?
- t.timestamps null: false, precision: 6
- else
- t.timestamps null: false
- end
+ t.timestamps
end
create_table :pets_treasures, force: true do |t|
@@ -672,19 +705,6 @@ ActiveRecord::Schema.define do
t.column :rainbow_color, :string
end
- create_table :pirates, force: true do |t|
- t.column :catchphrase, :string
- t.column :parrot_id, :integer
- t.integer :non_validated_parrot_id
- if subsecond_precision_supported?
- t.column :created_on, :datetime, precision: 6
- t.column :updated_on, :datetime, precision: 6
- else
- t.column :created_on, :datetime
- t.column :updated_on, :datetime
- end
- end
-
create_table :posts, force: true do |t|
t.references :author
t.string :title, null: false
@@ -886,8 +906,8 @@ ActiveRecord::Schema.define do
end
create_table :topics, force: true do |t|
- t.string :title, limit: 250
- t.string :author_name
+ t.string :title, limit: 250, **case_sensitive_options
+ t.string :author_name, **case_sensitive_options
t.string :author_email_address
if subsecond_precision_supported?
t.datetime :written_on, precision: 6
@@ -899,10 +919,10 @@ ActiveRecord::Schema.define do
# use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
# Oracle SELECT WHERE clause which causes many unit test failures
if current_adapter?(:OracleAdapter)
- t.string :content, limit: 4000
+ t.string :content, limit: 4000, **case_sensitive_options
t.string :important, limit: 4000
else
- t.text :content
+ t.text :content, **case_sensitive_options
t.text :important
end
t.boolean :approved, default: true
@@ -912,11 +932,7 @@ ActiveRecord::Schema.define do
t.string :parent_title
t.string :type
t.string :group
- if subsecond_precision_supported?
- t.timestamps null: true, precision: 6
- else
- t.timestamps null: true
- end
+ t.timestamps null: true
end
create_table :toys, primary_key: :toy_id, force: true do |t|
@@ -933,14 +949,6 @@ ActiveRecord::Schema.define do
t.datetime :updated_at
end
- create_table :treasures, force: true do |t|
- t.column :name, :string
- t.column :type, :string
- t.column :looter_id, :integer
- t.column :looter_type, :string
- t.belongs_to :ship
- end
-
create_table :tuning_pegs, force: true do |t|
t.integer :guitar_id
t.float :pitch
@@ -964,7 +972,7 @@ ActiveRecord::Schema.define do
end
[:circles, :squares, :triangles, :non_poly_ones, :non_poly_twos].each do |t|
- create_table(t, force: true) {}
+ create_table(t, force: true) { }
end
create_table :men, force: true do |t|
@@ -1000,14 +1008,16 @@ ActiveRecord::Schema.define do
t.references :wheelable, polymorphic: true
end
- create_table :countries, force: true, id: false, primary_key: "country_id" do |t|
- t.string :country_id
+ create_table :countries, force: true, id: false do |t|
+ t.string :country_id, primary_key: true
t.string :name
end
- create_table :treaties, force: true, id: false, primary_key: "treaty_id" do |t|
- t.string :treaty_id
+
+ create_table :treaties, force: true, id: false do |t|
+ t.string :treaty_id, primary_key: true
t.string :name
end
+
create_table :countries_treaties, force: true, primary_key: [:country_id, :treaty_id] do |t|
t.string :country_id, null: false
t.string :treaty_id, null: false
diff --git a/activerecord/test/schema/sqlite_specific_schema.rb b/activerecord/test/schema/sqlite_specific_schema.rb
new file mode 100644
index 0000000000..18192292e4
--- /dev/null
+++ b/activerecord/test/schema/sqlite_specific_schema.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+ActiveRecord::Schema.define do
+ create_table :defaults, force: true do |t|
+ t.date :fixed_date, default: "2004-01-01"
+ t.datetime :fixed_time, default: "2004-01-01 00:00:00"
+ t.column :char1, "char(1)", default: "Y"
+ t.string :char2, limit: 50, default: "a varchar field"
+ t.text :char3, limit: 50, default: "a text field"
+ end
+end