activerecord-spanner-adapter 1.2.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/blunderbuss.yml +1 -1
  4. data/.github/workflows/acceptance-tests-on-emulator.yaml +8 -8
  5. data/.github/workflows/ci.yaml +6 -4
  6. data/.github/workflows/nightly-acceptance-tests-on-emulator.yaml +14 -6
  7. data/.github/workflows/nightly-unit-tests.yaml +14 -6
  8. data/.release-please-manifest.json +1 -1
  9. data/CHANGELOG.md +28 -0
  10. data/Gemfile +1 -1
  11. data/README.md +4 -0
  12. data/acceptance/cases/migration/change_table_test.rb +23 -13
  13. data/acceptance/cases/migration/schema_dumper_test.rb +69 -0
  14. data/acceptance/cases/models/generated_column_test.rb +21 -7
  15. data/acceptance/cases/models/interleave_test.rb +36 -0
  16. data/acceptance/cases/models/logging_test.rb +57 -0
  17. data/acceptance/cases/models/query_test.rb +6 -1
  18. data/acceptance/cases/tasks/database_tasks_test.rb +407 -0
  19. data/acceptance/models/album_partial_disabled.rb +17 -0
  20. data/acceptance/schema/schema.rb +139 -134
  21. data/acceptance/test_helper.rb +2 -0
  22. data/examples/snippets/array-data-type/db/schema.rb +8 -3
  23. data/examples/snippets/bulk-insert/db/schema.rb +9 -4
  24. data/examples/snippets/commit-timestamp/db/schema.rb +11 -6
  25. data/examples/snippets/create-records/db/schema.rb +9 -4
  26. data/examples/snippets/date-data-type/db/schema.rb +8 -3
  27. data/examples/snippets/generated-column/db/schema.rb +6 -1
  28. data/examples/snippets/hints/db/schema.rb +6 -1
  29. data/examples/snippets/interleaved-tables/README.md +2 -2
  30. data/examples/snippets/interleaved-tables/db/schema.rb +5 -0
  31. data/examples/snippets/migrations/db/schema.rb +10 -5
  32. data/examples/snippets/mutations/db/schema.rb +9 -4
  33. data/examples/snippets/optimistic-locking/db/schema.rb +9 -4
  34. data/examples/snippets/partitioned-dml/db/schema.rb +5 -0
  35. data/examples/snippets/quickstart/db/schema.rb +9 -4
  36. data/examples/snippets/read-only-transactions/db/schema.rb +5 -0
  37. data/examples/snippets/read-write-transactions/db/schema.rb +9 -4
  38. data/examples/snippets/stale-reads/db/schema.rb +5 -0
  39. data/examples/snippets/timestamp-data-type/db/schema.rb +8 -3
  40. data/lib/active_record/connection_adapters/spanner/column.rb +23 -0
  41. data/lib/active_record/connection_adapters/spanner/database_statements.rb +7 -4
  42. data/lib/active_record/connection_adapters/spanner/quoting.rb +9 -0
  43. data/lib/active_record/connection_adapters/spanner/schema_creation.rb +17 -4
  44. data/lib/active_record/connection_adapters/spanner/schema_definitions.rb +11 -2
  45. data/lib/active_record/connection_adapters/spanner/schema_dumper.rb +56 -0
  46. data/lib/active_record/connection_adapters/spanner/schema_statements.rb +56 -9
  47. data/lib/active_record/connection_adapters/spanner/type_metadata.rb +19 -4
  48. data/lib/active_record/connection_adapters/spanner_adapter.rb +11 -0
  49. data/lib/active_record/tasks/spanner_database_tasks.rb +18 -4
  50. data/lib/active_record/type/spanner/spanner_active_record_converter.rb +10 -0
  51. data/lib/active_record/type/spanner/time.rb +10 -3
  52. data/lib/activerecord_spanner_adapter/base.rb +41 -27
  53. data/lib/activerecord_spanner_adapter/connection.rb +8 -3
  54. data/lib/activerecord_spanner_adapter/information_schema.rb +52 -3
  55. data/lib/activerecord_spanner_adapter/table/column.rb +7 -2
  56. data/lib/activerecord_spanner_adapter/version.rb +1 -1
  57. data/lib/arel/visitors/spanner.rb +8 -2
  58. metadata +9 -3
@@ -6,140 +6,145 @@
6
6
 
7
7
  # frozen_string_literal: true
8
8
 
9
- ActiveRecord::Schema.define do
10
- ActiveRecord::Base.connection.ddl_batch do
11
- create_table :all_types do |t|
12
- t.column :col_string, :string
13
- t.column :col_int64, :bigint
14
- t.column :col_float64, :float
15
- t.column :col_numeric, :numeric
16
- t.column :col_bool, :boolean
17
- t.column :col_bytes, :binary
18
- t.column :col_date, :date
19
- t.column :col_timestamp, :datetime
20
- t.column :col_json, :json
21
-
22
- t.column :col_array_string, :string, array: true
23
- t.column :col_array_int64, :bigint, array: true
24
- t.column :col_array_float64, :float, array: true
25
- t.column :col_array_numeric, :numeric, array: true
26
- t.column :col_array_bool, :boolean, array: true
27
- t.column :col_array_bytes, :binary, array: true
28
- t.column :col_array_date, :date, array: true
29
- t.column :col_array_timestamp, :datetime, array: true
30
- t.column :col_array_json, :json, array: true
31
- end
32
-
33
- create_table :firms do |t|
34
- t.string :name
35
- t.integer :rating
36
- t.string :description
37
- t.references :account
38
- end
39
-
40
- create_table :customers do |t|
41
- t.string :name
42
- end
43
-
44
- create_table :accounts do |t|
45
- t.references :customer, index: false
46
- t.references :firm, index: false
47
- t.string :name
48
- t.integer :credit_limit
49
- t.integer :transactions_count
50
- end
51
-
52
- create_table :transactions do |t|
53
- t.float :amount
54
- t.references :account, index: false
55
- end
56
-
57
- create_table :departments do |t|
58
- t.string :name
59
- t.references :resource, polymorphic: true
60
- end
61
-
62
- create_table :member_types do |t|
63
- t.string :name
64
- end
65
-
66
- create_table :members do |t|
67
- t.string :name
68
- t.references :member_type, index: false
69
- t.references :admittable, polymorphic: true, index: false
70
- end
71
-
72
- create_table :memberships do |t|
73
- t.datetime :joined_on
74
- t.references :club, index: false
75
- t.references :member, index: false
76
- t.boolean :favourite
77
- end
78
-
79
- create_table :clubs do |t|
80
- t.string :name
81
- end
82
-
83
- create_table :authors do |t|
84
- t.string :name, null: false
85
- t.date :registered_date
86
- t.references :organization, index: false
87
- end
88
-
89
- create_table :posts do |t|
90
- t.string :title
91
- t.string :content
92
- t.references :author
93
- t.integer :comments_count
94
- t.date :post_date
95
- t.time :published_time
96
- end
97
-
98
- create_table :comments do |t|
99
- t.string :comment
100
- t.references :post, index: false, foreign_key: true
101
- end
102
-
103
- create_table :addresses do |t|
104
- t.string :line1
105
- t.string :postal_code
106
- t.string :city
107
- t.references :author, index: false
108
- end
109
-
110
- create_table :organizations do |t|
111
- t.string :name
112
- t.datetime :last_updated, allow_commit_timestamp: true
113
- end
114
-
115
- create_table :singers, id: false do |t|
116
- t.primary_key :singerid
117
- t.column :first_name, :string, limit: 200
118
- t.string :last_name
119
- t.integer :tracks_count
120
- t.integer :lock_version
121
- t.string :full_name, as: "COALESCE(first_name || ' ', '') || last_name", stored: true
122
- end
123
-
124
- create_table :albums, id: false do |t|
125
- t.interleave_in :singers
126
- t.primary_key :albumid
127
- # `singerid` is part of the primary key in the table definition, but it is not visible to ActiveRecord as part of
128
- # the primary key, to prevent ActiveRecord from considering this to be an entity with a composite primary key.
129
- t.parent_key :singerid
130
- t.string :title
131
- t.integer :lock_version
132
- end
9
+ def create_tables_in_test_schema
10
+ ActiveRecord::Schema.define(version: 1) do
11
+ ActiveRecord::Base.connection.ddl_batch do
12
+ create_table :all_types, id: { limit: 8 } do |t|
13
+ t.column :col_string, :string
14
+ t.column :col_int64, :bigint
15
+ t.column :col_float64, :float
16
+ t.column :col_numeric, :numeric
17
+ t.column :col_bool, :boolean
18
+ t.column :col_bytes, :binary
19
+ t.column :col_date, :date
20
+ t.column :col_timestamp, :datetime
21
+ t.column :col_json, :json
22
+
23
+ t.column :col_array_string, :string, array: true
24
+ t.column :col_array_int64, :bigint, array: true
25
+ t.column :col_array_float64, :float, array: true
26
+ t.column :col_array_numeric, :numeric, array: true
27
+ t.column :col_array_bool, :boolean, array: true
28
+ t.column :col_array_bytes, :binary, array: true
29
+ t.column :col_array_date, :date, array: true
30
+ t.column :col_array_timestamp, :datetime, array: true
31
+ t.column :col_array_json, :json, array: true
32
+ end
33
+
34
+ create_table :firms do |t|
35
+ t.string :name
36
+ t.integer :rating
37
+ t.string :description
38
+ t.references :account
39
+ end
40
+
41
+ create_table :customers do |t|
42
+ t.string :name
43
+ end
44
+
45
+ create_table :accounts do |t|
46
+ t.references :customer, index: false
47
+ t.references :firm, index: false
48
+ t.string :name
49
+ t.integer :credit_limit
50
+ t.integer :transactions_count
51
+ end
52
+
53
+ create_table :transactions do |t|
54
+ t.float :amount
55
+ t.references :account, index: false
56
+ end
57
+
58
+ create_table :departments do |t|
59
+ t.string :name
60
+ t.references :resource, polymorphic: true, index: { name: "index_departments_on_resource" }
61
+ end
62
+
63
+ create_table :member_types do |t|
64
+ t.string :name
65
+ end
66
+
67
+ create_table :members do |t|
68
+ t.string :name
69
+ t.references :member_type, index: false
70
+ t.references :admittable, polymorphic: true, index: false
71
+ end
72
+
73
+ create_table :memberships do |t|
74
+ t.datetime :joined_on
75
+ t.references :club, index: false
76
+ t.references :member, index: false
77
+ t.boolean :favourite
78
+ end
79
+
80
+ create_table :clubs do |t|
81
+ t.string :name
82
+ end
83
+
84
+ create_table :authors do |t|
85
+ t.string :name, null: false
86
+ t.date :registered_date
87
+ t.references :organization, index: false
88
+ end
89
+
90
+ create_table :posts do |t|
91
+ t.string :title
92
+ t.string :content
93
+ t.references :author
94
+ t.integer :comments_count
95
+ t.date :post_date
96
+ t.time :published_time
97
+ end
98
+
99
+ create_table :comments do |t|
100
+ t.string :comment
101
+ t.references :post, index: false, foreign_key: true
102
+ end
103
+
104
+ create_table :addresses do |t|
105
+ t.string :line1
106
+ t.string :postal_code
107
+ t.string :city
108
+ t.references :author, index: false
109
+ end
110
+
111
+ create_table :organizations do |t|
112
+ t.string :name
113
+ t.datetime :last_updated, allow_commit_timestamp: true
114
+ end
115
+
116
+ create_table :singers, id: false do |t|
117
+ t.primary_key :singerid
118
+ t.column :first_name, :string, limit: 200
119
+ t.string :last_name
120
+ t.integer :tracks_count
121
+ t.integer :lock_version
122
+ t.virtual :full_name, type: :string, as: "COALESCE(first_name || ' ', '') || last_name", stored: true
123
+ end
124
+
125
+ create_table :albums, id: false do |t|
126
+ t.interleave_in :singers
127
+ t.primary_key :albumid
128
+ # `singerid` is part of the primary key in the table definition, but it is not visible to ActiveRecord as part of
129
+ # the primary key, to prevent ActiveRecord from considering this to be an entity with a composite primary key.
130
+ t.parent_key :singerid
131
+ t.string :title
132
+ t.integer :lock_version
133
+ end
134
+
135
+ create_table :tracks, id: false do |t|
136
+ # `:cascade` causes all tracks that belong to an album to automatically be deleted when an album is deleted.
137
+ t.interleave_in :albums, :cascade
138
+ t.primary_key :trackid
139
+ t.parent_key :singerid
140
+ t.parent_key :albumid
141
+ t.string :title
142
+ t.numeric :duration
143
+ t.integer :lock_version
144
+ end
145
+
146
+ add_index :tracks, [:singerid, :albumid, :title], interleave_in: :albums, null_filtered: true, unique: false
133
147
 
134
- create_table :tracks, id: false do |t|
135
- # `:cascade` causes all tracks that belong to an album to automatically be deleted when an album is deleted.
136
- t.interleave_in :albums, :cascade
137
- t.primary_key :trackid
138
- t.parent_key :singerid
139
- t.parent_key :albumid
140
- t.string :title
141
- t.numeric :duration
142
- t.integer :lock_version
143
148
  end
144
149
  end
145
- end
150
+ end
@@ -64,6 +64,7 @@ def create_test_database
64
64
  puts "Loading test schema..."
65
65
  ActiveRecord::Base.establish_connection connector_config
66
66
  require_relative "schema/schema"
67
+ create_tables_in_test_schema
67
68
  end
68
69
 
69
70
  def drop_test_database
@@ -83,6 +84,7 @@ def load_test_schema
83
84
  ActiveRecord::Base.establish_connection connector_config
84
85
 
85
86
  require_relative "schema/schema"
87
+ create_tables_in_test_schema
86
88
  end
87
89
 
88
90
  module SpannerAdapter
@@ -2,8 +2,8 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
@@ -11,8 +11,9 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
- create_table "entity_with_array_types", force: :cascade do |t|
16
+ create_table "entity_with_array_types", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "col_array_string"
17
18
  t.integer "col_array_int64", limit: 8
18
19
  t.float "col_array_float64"
@@ -23,4 +24,8 @@ ActiveRecord::Schema.define(version: 1) do
23
24
  t.time "col_array_timestamp"
24
25
  end
25
26
 
27
+ connection.run_batch
28
+ rescue
29
+ abort_batch
30
+ raise
26
31
  end
@@ -2,8 +2,8 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
@@ -11,16 +11,21 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
- create_table "albums", force: :cascade do |t|
16
+ create_table "albums", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "title"
17
18
  t.integer "singer_id", limit: 8
18
19
  end
19
20
 
20
- create_table "singers", force: :cascade do |t|
21
+ create_table "singers", id: { limit: 8 }, force: :cascade do |t|
21
22
  t.string "first_name"
22
23
  t.string "last_name"
23
24
  end
24
25
 
25
26
  add_foreign_key "albums", "singers"
27
+ connection.run_batch
28
+ rescue
29
+ abort_batch
30
+ raise
26
31
  end
@@ -2,8 +2,8 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
@@ -11,19 +11,24 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
- create_table "albums", force: :cascade do |t|
16
+ create_table "albums", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "title"
17
18
  t.decimal "marketing_budget"
18
19
  t.integer "singer_id", limit: 8
19
- t.time "last_updated"
20
+ t.time "last_updated", allow_commit_timestamp: true
20
21
  end
21
22
 
22
- create_table "singers", force: :cascade do |t|
23
+ create_table "singers", id: { limit: 8 }, force: :cascade do |t|
23
24
  t.string "first_name"
24
25
  t.string "last_name"
25
- t.time "last_updated"
26
+ t.time "last_updated", allow_commit_timestamp: true
26
27
  end
27
28
 
28
29
  add_foreign_key "albums", "singers"
30
+ connection.run_batch
31
+ rescue
32
+ abort_batch
33
+ raise
29
34
  end
@@ -2,8 +2,8 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
@@ -11,16 +11,21 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
- create_table "albums", force: :cascade do |t|
16
+ create_table "albums", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "title"
17
18
  t.integer "singer_id", limit: 8
18
19
  end
19
20
 
20
- create_table "singers", force: :cascade do |t|
21
+ create_table "singers", id: { limit: 8 }, force: :cascade do |t|
21
22
  t.string "first_name"
22
23
  t.string "last_name"
23
24
  end
24
25
 
25
26
  add_foreign_key "albums", "singers"
27
+ connection.run_batch
28
+ rescue
29
+ abort_batch
30
+ raise
26
31
  end
@@ -2,8 +2,8 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
@@ -11,11 +11,16 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
- create_table "singers", force: :cascade do |t|
16
+ create_table "singers", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "first_name"
17
18
  t.string "last_name"
18
19
  t.date "birth_date"
19
20
  end
20
21
 
22
+ connection.run_batch
23
+ rescue
24
+ abort_batch
25
+ raise
21
26
  end
@@ -11,11 +11,16 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
16
  create_table "singers", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "first_name", limit: 100
17
18
  t.string "last_name", limit: 200, null: false
18
- t.string "full_name", limit: 300, null: false
19
+ t.virtual "full_name", type: :string, limit: 300, null: false, as: "COALESCE(first_name || ' ', '') || last_name", stored: true
19
20
  end
20
21
 
22
+ connection.run_batch
23
+ rescue
24
+ abort_batch
25
+ raise
21
26
  end
@@ -11,6 +11,7 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
16
  create_table "albums", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "title"
@@ -20,9 +21,13 @@ ActiveRecord::Schema.define(version: 1) do
20
21
  create_table "singers", id: { limit: 8 }, force: :cascade do |t|
21
22
  t.string "first_name", limit: 100
22
23
  t.string "last_name", limit: 200, null: false
23
- t.string "full_name", limit: 300, null: false
24
+ t.virtual "full_name", type: :string, limit: 300, null: false, as: "COALESCE(first_name || ' ', '') || last_name", stored: true
24
25
  t.index ["full_name"], name: "index_singers_on_full_name", order: { full_name: :asc }
25
26
  end
26
27
 
27
28
  add_foreign_key "albums", "singers"
29
+ connection.run_batch
30
+ rescue
31
+ abort_batch
32
+ raise
28
33
  end
@@ -85,7 +85,7 @@ end
85
85
 
86
86
  ## Models for Interleaved Tables
87
87
  The model definition for an interleaved table (a child table) must use the `primary_keys=col1, col2, ...`
88
- function from the `composite_primary_key` gem.
88
+ function from the `composite_primary_keys` gem.
89
89
 
90
90
  An interleaved table parent/child relationship must be modelled as a `belongs_to`/`has_many` association in
91
91
  ActiveRecord. As the columns that are used to reference a parent record use a custom column name, it is required to also
@@ -161,4 +161,4 @@ Run the application with the command
161
161
 
162
162
  ```bash
163
163
  bundle exec rake run
164
- ```
164
+ ```
@@ -11,6 +11,7 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
16
  create_table "albums", primary_key: "albumid", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.integer "singerid", limit: 8, null: false
@@ -29,4 +30,8 @@ ActiveRecord::Schema.define(version: 1) do
29
30
  t.decimal "duration"
30
31
  end
31
32
 
33
+ connection.run_batch
34
+ rescue
35
+ abort_batch
36
+ raise
32
37
  end
@@ -2,8 +2,8 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
@@ -11,23 +11,28 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
- create_table "albums", force: :cascade do |t|
16
+ create_table "albums", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "title"
17
18
  t.integer "singers_id", limit: 8
18
19
  t.index ["singers_id"], name: "index_albums_on_singers_id", order: { singers_id: :asc }
19
20
  end
20
21
 
21
- create_table "singers", force: :cascade do |t|
22
+ create_table "singers", id: { limit: 8 }, force: :cascade do |t|
22
23
  t.string "first_name"
23
24
  t.string "last_name"
24
25
  end
25
26
 
26
- create_table "tracks", force: :cascade do |t|
27
+ create_table "tracks", id: { limit: 8 }, force: :cascade do |t|
27
28
  t.string "title"
28
29
  t.decimal "duration"
29
30
  t.integer "albums_id", limit: 8
30
31
  t.index ["albums_id"], name: "index_tracks_on_albums_id", order: { albums_id: :asc }
31
32
  end
32
33
 
34
+ connection.run_batch
35
+ rescue
36
+ abort_batch
37
+ raise
33
38
  end
@@ -2,8 +2,8 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
@@ -11,17 +11,22 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema.define(version: 1) do
14
+ connection.start_batch_ddl
14
15
 
15
- create_table "albums", force: :cascade do |t|
16
+ create_table "albums", id: { limit: 8 }, force: :cascade do |t|
16
17
  t.string "title"
17
18
  t.decimal "marketing_budget"
18
19
  t.integer "singer_id", limit: 8
19
20
  end
20
21
 
21
- create_table "singers", force: :cascade do |t|
22
+ create_table "singers", id: { limit: 8 }, force: :cascade do |t|
22
23
  t.string "first_name"
23
24
  t.string "last_name"
24
25
  end
25
26
 
26
27
  add_foreign_key "albums", "singers"
28
+ connection.run_batch
29
+ rescue
30
+ abort_batch
31
+ raise
27
32
  end