activerecord-spanner-adapter 1.8.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/acceptance-tests-on-emulator.yaml +4 -6
  3. data/.github/workflows/ci.yaml +4 -6
  4. data/.github/workflows/nightly-acceptance-tests-on-emulator.yaml +4 -6
  5. data/.github/workflows/nightly-unit-tests.yaml +4 -6
  6. data/.github/workflows/rubocop.yaml +1 -1
  7. data/.github/workflows/samples.yaml +30 -0
  8. data/.kokoro/release.sh +1 -3
  9. data/.release-please-manifest.json +1 -1
  10. data/.rubocop.yml +2 -2
  11. data/CHANGELOG.md +18 -0
  12. data/Gemfile +6 -5
  13. data/README.md +11 -9
  14. data/acceptance/cases/migration/command_recorder_test.rb +7 -38
  15. data/acceptance/cases/migration/references_index_test.rb +2 -11
  16. data/acceptance/cases/models/binary_identifiers.rb +97 -0
  17. data/acceptance/models/binary_project.rb +20 -0
  18. data/acceptance/models/string_io.rb +28 -0
  19. data/acceptance/models/user.rb +20 -0
  20. data/acceptance/test_helper.rb +1 -0
  21. data/activerecord-spanner-adapter.gemspec +3 -3
  22. data/benchmarks/application.rb +3 -7
  23. data/examples/snippets/Rakefile +27 -5
  24. data/examples/snippets/array-data-type/application.rb +1 -5
  25. data/examples/snippets/array-data-type/config/database.yml +1 -0
  26. data/examples/snippets/bit-reversed-sequence/application.rb +0 -4
  27. data/examples/snippets/bit-reversed-sequence/config/database.yml +1 -0
  28. data/examples/snippets/bit-reversed-sequence/db/seeds.rb +2 -2
  29. data/examples/snippets/bulk-insert/application.rb +1 -5
  30. data/examples/snippets/bulk-insert/config/database.yml +1 -0
  31. data/examples/snippets/commit-timestamp/application.rb +0 -4
  32. data/examples/snippets/commit-timestamp/config/database.yml +1 -0
  33. data/examples/snippets/config/environment.rb +5 -0
  34. data/examples/snippets/create-records/application.rb +1 -5
  35. data/examples/snippets/create-records/config/database.yml +1 -0
  36. data/examples/snippets/date-data-type/application.rb +1 -5
  37. data/examples/snippets/date-data-type/config/database.yml +1 -0
  38. data/examples/snippets/date-data-type/db/seeds.rb +1 -1
  39. data/examples/snippets/generated-column/application.rb +0 -4
  40. data/examples/snippets/generated-column/config/database.yml +1 -0
  41. data/examples/snippets/generated-column/db/seeds.rb +1 -1
  42. data/examples/snippets/hints/application.rb +0 -4
  43. data/examples/snippets/hints/config/database.yml +1 -0
  44. data/examples/snippets/hints/db/seeds.rb +1 -1
  45. data/examples/snippets/interleaved-tables/application.rb +1 -5
  46. data/examples/snippets/interleaved-tables/config/database.yml +1 -0
  47. data/examples/snippets/interleaved-tables/db/seeds.rb +1 -1
  48. data/examples/snippets/interleaved-tables/models/album.rb +6 -2
  49. data/examples/snippets/interleaved-tables/models/track.rb +5 -1
  50. data/examples/snippets/interleaved-tables-before-7.1/application.rb +1 -5
  51. data/examples/snippets/interleaved-tables-before-7.1/config/database.yml +1 -0
  52. data/examples/snippets/interleaved-tables-before-7.1/db/seeds.rb +1 -1
  53. data/examples/snippets/migrations/application.rb +0 -4
  54. data/examples/snippets/migrations/config/database.yml +1 -0
  55. data/examples/snippets/mutations/application.rb +1 -5
  56. data/examples/snippets/mutations/config/database.yml +1 -0
  57. data/examples/snippets/mutations/db/seeds.rb +1 -1
  58. data/examples/snippets/optimistic-locking/application.rb +0 -4
  59. data/examples/snippets/optimistic-locking/config/database.yml +1 -0
  60. data/examples/snippets/optimistic-locking/db/seeds.rb +1 -1
  61. data/examples/snippets/partitioned-dml/application.rb +0 -4
  62. data/examples/snippets/partitioned-dml/config/database.yml +1 -0
  63. data/examples/snippets/partitioned-dml/db/seeds.rb +1 -1
  64. data/examples/snippets/query-logs/application.rb +15 -13
  65. data/examples/snippets/query-logs/config/database.yml +1 -0
  66. data/examples/snippets/query-logs/db/seeds.rb +1 -1
  67. data/examples/snippets/quickstart/application.rb +0 -4
  68. data/examples/snippets/quickstart/config/database.yml +1 -0
  69. data/examples/snippets/quickstart/db/seeds.rb +1 -1
  70. data/examples/snippets/read-only-transactions/application.rb +0 -4
  71. data/examples/snippets/read-only-transactions/config/database.yml +1 -0
  72. data/examples/snippets/read-only-transactions/db/seeds.rb +1 -1
  73. data/examples/snippets/read-write-transactions/application.rb +2 -6
  74. data/examples/snippets/read-write-transactions/config/database.yml +1 -0
  75. data/examples/snippets/read-write-transactions/db/seeds.rb +1 -1
  76. data/examples/snippets/stale-reads/application.rb +0 -4
  77. data/examples/snippets/stale-reads/config/database.yml +1 -0
  78. data/examples/snippets/stale-reads/db/seeds.rb +1 -1
  79. data/examples/snippets/tags/application.rb +0 -4
  80. data/examples/snippets/tags/config/database.yml +1 -0
  81. data/examples/snippets/tags/db/seeds.rb +1 -1
  82. data/examples/snippets/timestamp-data-type/application.rb +0 -4
  83. data/examples/snippets/timestamp-data-type/config/database.yml +1 -0
  84. data/lib/active_record/connection_adapters/spanner/column.rb +3 -3
  85. data/lib/active_record/connection_adapters/spanner/database_statements.rb +34 -22
  86. data/lib/active_record/connection_adapters/spanner/quoting.rb +2 -1
  87. data/lib/active_record/connection_adapters/spanner/schema_creation.rb +7 -9
  88. data/lib/active_record/connection_adapters/spanner/schema_definitions.rb +12 -2
  89. data/lib/active_record/connection_adapters/spanner/schema_statements.rb +17 -46
  90. data/lib/active_record/connection_adapters/spanner/type_metadata.rb +4 -6
  91. data/lib/active_record/connection_adapters/spanner_adapter.rb +20 -7
  92. data/lib/active_record/tasks/spanner_database_tasks.rb +4 -4
  93. data/lib/active_record/type/spanner/array.rb +4 -0
  94. data/lib/active_record/type/spanner/bytes.rb +10 -0
  95. data/lib/activerecord_spanner_adapter/base.rb +12 -18
  96. data/lib/activerecord_spanner_adapter/connection.rb +9 -5
  97. data/lib/activerecord_spanner_adapter/foreign_key.rb +9 -2
  98. data/lib/activerecord_spanner_adapter/index/column.rb +6 -1
  99. data/lib/activerecord_spanner_adapter/index.rb +10 -2
  100. data/lib/activerecord_spanner_adapter/information_schema.rb +1 -1
  101. data/lib/activerecord_spanner_adapter/primary_key.rb +2 -2
  102. data/lib/activerecord_spanner_adapter/table/column.rb +12 -3
  103. data/lib/activerecord_spanner_adapter/table.rb +8 -2
  104. data/lib/activerecord_spanner_adapter/transaction.rb +1 -1
  105. data/lib/activerecord_spanner_adapter/version.rb +1 -1
  106. data/lib/arel/visitors/spanner.rb +16 -11
  107. data/lib/spanner_client_ext.rb +4 -3
  108. metadata +13 -32
  109. data/examples/snippets/array-data-type/db/schema.rb +0 -31
  110. data/examples/snippets/bit-reversed-sequence/db/schema.rb +0 -31
  111. data/examples/snippets/bulk-insert/db/schema.rb +0 -31
  112. data/examples/snippets/commit-timestamp/db/schema.rb +0 -34
  113. data/examples/snippets/create-records/db/schema.rb +0 -31
  114. data/examples/snippets/date-data-type/db/schema.rb +0 -26
  115. data/examples/snippets/generated-column/db/schema.rb +0 -26
  116. data/examples/snippets/hints/db/schema.rb +0 -33
  117. data/examples/snippets/interleaved-tables/db/schema.rb +0 -39
  118. data/examples/snippets/interleaved-tables-before-7.1/db/schema.rb +0 -37
  119. data/examples/snippets/migrations/db/schema.rb +0 -38
  120. data/examples/snippets/mutations/db/schema.rb +0 -32
  121. data/examples/snippets/optimistic-locking/db/schema.rb +0 -34
  122. data/examples/snippets/partitioned-dml/db/schema.rb +0 -31
  123. data/examples/snippets/query-logs/db/schema.rb +0 -31
  124. data/examples/snippets/quickstart/db/schema.rb +0 -31
  125. data/examples/snippets/read-only-transactions/db/schema.rb +0 -31
  126. data/examples/snippets/read-write-transactions/db/schema.rb +0 -32
  127. data/examples/snippets/stale-reads/db/schema.rb +0 -31
  128. data/examples/snippets/tags/db/schema.rb +0 -31
  129. data/examples/snippets/timestamp-data-type/db/schema.rb +0 -26
@@ -7,19 +7,37 @@
7
7
  require_relative "config/environment"
8
8
  require "docker"
9
9
 
10
- desc "Lists all available samples."
11
- task :list do
12
- samples = Dir.entries(".").select do |entry|
10
+ def fetch_samples
11
+ Dir.entries(".").select do |entry|
13
12
  File.directory?(File.join(".", entry)) \
14
- && !%w[. ..].include?(entry) \
15
- && File.exist?(File.join(".", entry, "application.rb"))
13
+ && !%w[. ..].include?(entry) \
14
+ && File.exist?(File.join(".", entry, "application.rb"))
16
15
  end
16
+ end
17
+
18
+ desc "Lists all available samples."
19
+ task :list do
20
+ samples = fetch_samples
17
21
  puts "Available samples: "
18
22
  samples.sort.each { |dir| puts " #{dir}" }
19
23
  puts ""
20
24
  puts "Run a sample with the command `bundle exec rake run\\[<sample-name>\\]`"
21
25
  end
22
26
 
27
+ desc "Runs all samples."
28
+ task :all do
29
+ samples = fetch_samples
30
+ ar_version = ENV.fetch "AR_VERSION", "~> 7.1.0"
31
+ less_than_7_1 = ar_version.dup.to_s.sub("~>", "").strip < "7.1.0"
32
+ samples.delete "interleaved-tables" if less_than_7_1
33
+ samples.delete "interleaved-tables-before-7.1" unless less_than_7_1
34
+ samples.delete "bit-reversed-sequence" if less_than_7_1
35
+ samples.delete "query-logs" if less_than_7_1
36
+ samples.each do |sample|
37
+ run_sample sample
38
+ end
39
+ end
40
+
23
41
  desc "Runs a simple ActiveRecord tutorial on a Spanner emulator."
24
42
  task :run, [:sample] do |_t, args|
25
43
  sample = args[:sample]
@@ -28,7 +46,11 @@ task :run, [:sample] do |_t, args|
28
46
  puts ""
29
47
  sample = "quickstart"
30
48
  end
49
+ run_sample sample
50
+ end
31
51
 
52
+ def run_sample sample
53
+ puts "Running #{sample}"
32
54
  puts "Downloading Spanner emulator image..."
33
55
  Docker::Image.create "fromImage" => "gcr.io/cloud-spanner-emulator/emulator:latest"
34
56
  puts "Creating Spanner emulator container..."
@@ -9,7 +9,7 @@ require_relative "../config/environment"
9
9
  require_relative "models/entity_with_array_types"
10
10
 
11
11
  class Application
12
- def self.run # rubocop:disable Metrics/AbcSize
12
+ def self.run
13
13
  # Create a record with all array types.
14
14
  record = EntityWithArrayTypes.create \
15
15
  col_array_string: ["value1", "value2", "value3"],
@@ -35,10 +35,6 @@ class Application
35
35
  puts "Bytes array: #{record.col_array_bytes.map(&:read)}"
36
36
  puts "Date array: #{record.col_array_date}"
37
37
  puts "Timestamp array: #{record.col_array_timestamp}"
38
-
39
- puts ""
40
- puts "Press any key to end the application"
41
- STDIN.getch
42
38
  end
43
39
  end
44
40
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -22,10 +22,6 @@ class Application
22
22
 
23
23
  # List all singers, albums and tracks.
24
24
  list_singers_albums
25
-
26
- puts ""
27
- puts "Press any key to end the application"
28
- STDIN.getch
29
25
  end
30
26
 
31
27
  def self.find_album singerid, albumid
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
 
@@ -14,7 +14,7 @@ last_names = %w[Wendelson Allison Peterson Johnson Henderson Ericsson Aronson Te
14
14
  adjectives = %w[daily happy blue generous cooked bad open]
15
15
  nouns = %w[windows potatoes bank street tree glass bottle]
16
16
 
17
- # Note: We do not use mutations to insert these rows, because letting the database generate the primary key means that
17
+ # NOTE: We do not use mutations to insert these rows, because letting the database generate the primary key means that
18
18
  # we rely on a `THEN RETURN id` clause in the insert statement. This is only supported for DML statements, and not for
19
19
  # mutations.
20
20
  ActiveRecord::Base.transaction do
@@ -46,7 +46,7 @@ class Application
46
46
  ]
47
47
  end
48
48
  puts ""
49
- puts "Created a batch of #{singers.length} singers and #{albums.length} "\
49
+ puts "Created a batch of #{singers.length} singers and #{albums.length} " \
50
50
  "albums using a transaction with buffered mutations:"
51
51
  singers.each do |s|
52
52
  puts " Created singer #{s.first_name} #{s.last_name} with id #{s.id}"
@@ -54,10 +54,6 @@ class Application
54
54
  puts " with album #{a.title} with id #{a.id}"
55
55
  end
56
56
  end
57
-
58
- puts ""
59
- puts "Press any key to end the application"
60
- STDIN.getch
61
57
  end
62
58
  end
63
59
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -43,10 +43,6 @@ class Application
43
43
  puts "Singer and album updated:"
44
44
  puts "#{singer.first_name} #{singer.last_name} (Last updated: #{singer.last_updated.strftime format})"
45
45
  puts " #{album.title} (Last updated: #{album.last_updated.strftime format})"
46
-
47
- puts ""
48
- puts "Press any key to end the application"
49
- STDIN.getch
50
46
  end
51
47
  end
52
48
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,11 +4,16 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
+ require "logger" # https://github.com/rails/rails/issues/54260
7
8
  require "active_record"
8
9
  require "bundler"
9
10
 
10
11
  Dir["../../lib/*.rb"].each { |file| require file }
11
12
 
13
+ if ActiveRecord.version >= Gem::Version.create("7.2.0")
14
+ ActiveRecord::ConnectionAdapters.register "spanner", "ActiveRecord::ConnectionAdapters::SpannerAdapter"
15
+ end
16
+
12
17
  Bundler.require
13
18
 
14
19
  ActiveRecord::Base.establish_connection(
@@ -13,7 +13,7 @@ class Application
13
13
  def self.run
14
14
  # Creating a single record without an explicit transaction will automatically save it to the database.
15
15
  # It is not recommended to call Entity.create repeatedly to insert multiple records, as each call will
16
- # use a separate Spanner transaction. Instead multiple records should be created by passing an array of
16
+ # use a separate Spanner transaction. Instead, multiple records should be created by passing an array of
17
17
  # entities to the Entity.create method.
18
18
  singer = Singer.create first_name: "Dave", last_name: "Allison"
19
19
  puts ""
@@ -32,10 +32,6 @@ class Application
32
32
  singers.each do |s|
33
33
  puts " Created singer #{s.first_name} #{s.last_name} with id #{s.id}"
34
34
  end
35
-
36
- puts ""
37
- puts "Press any key to end the application"
38
- STDIN.getch
39
35
  end
40
36
  end
41
37
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -17,7 +17,7 @@ class Application
17
17
  puts "#{"#{singer.first_name} #{singer.last_name}".ljust 30}#{singer.birth_date}"
18
18
  end
19
19
 
20
- # Update the birth date of a random singer using the current system time. Any time and timezone information will be
20
+ # Update the birthdate of a random singer using the current system time. Any time and timezone information will be
21
21
  # lost after saving the record as a DATE only contains the year, month and day-of-month information.
22
22
  singer = Singer.all.sample
23
23
  singer.update birth_date: Time.now
@@ -25,10 +25,6 @@ class Application
25
25
  puts ""
26
26
  puts "Updated birth date to current system time:"
27
27
  puts "#{"#{singer.first_name} #{singer.last_name}".ljust 30}#{singer.birth_date}"
28
-
29
- puts ""
30
- puts "Press any key to end the application"
31
- STDIN.getch
32
28
  end
33
29
  end
34
30
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
  #
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
 
10
10
  first_names = %w[Nelson Todd William Alex Dominique Adenoid Steve Nathan Beverly Annie Amy Norma Diana Regan Phyllis]
@@ -27,10 +27,6 @@ class Application
27
27
  singer.reload
28
28
  puts ""
29
29
  puts "Singer updated: #{singer.full_name}"
30
-
31
- puts ""
32
- puts "Press any key to end the application"
33
- STDIN.getch
34
30
  end
35
31
  end
36
32
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
 
10
10
  first_names = %w[Pete Alice John Ethel Trudy Naomi Wendy Ruben Thomas Elly]
@@ -37,10 +37,6 @@ class Application
37
37
  .distinct.order("last_name, first_name").each do |singer|
38
38
  puts singer.full_name
39
39
  end
40
-
41
- puts ""
42
- puts "Press any key to end the application"
43
- STDIN.getch
44
40
  end
45
41
  end
46
42
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
 
@@ -13,7 +13,7 @@ require_relative "models/track"
13
13
  class Application
14
14
  def self.run
15
15
  # List all singers, albums and tracks.
16
- list_singers_albums_tracks
16
+ list_singers_albums
17
17
 
18
18
  # Create a new album with some tracks.
19
19
  create_new_album
@@ -28,10 +28,6 @@ class Application
28
28
  # Try to delete an album that has at least one track. This IS possible as tracks IS marked with
29
29
  # ON DELETE CASCADE.
30
30
  delete_album_with_tracks
31
-
32
- puts ""
33
- puts "Press any key to end the application"
34
- STDIN.getch
35
31
  end
36
32
 
37
33
  def self.find_singer
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
  require_relative "../models/track"
@@ -11,6 +11,10 @@ class Album < ActiveRecord::Base
11
11
 
12
12
  # `tracks` is defined as INTERLEAVE IN PARENT `albums`.
13
13
  # The primary key of `albums` is (`singerid`, `albumid`).
14
- # Rails 7.1 requires using query_constraints to define a composite foreign key.
15
- has_many :tracks, query_constraints: [:singerid, :albumid]
14
+ if ActiveRecord::VERSION::MAJOR >= 8
15
+ has_many :tracks, foreign_key: [:singerid, :albumid]
16
+ else
17
+ # Rails 7.1 requires using query_constraints to define a composite foreign key.
18
+ has_many :tracks, query_constraints: [:singerid, :albumid]
19
+ end
16
20
  end
@@ -8,7 +8,11 @@ class Track < ActiveRecord::Base
8
8
  # `tracks` is defined as INTERLEAVE IN PARENT `albums`.
9
9
  # The primary key of `albums` is (`singerid`, `albumid`).
10
10
  # Rails 7.1 requires a composite primary key in a belongs_to relationship to be specified as query_constraints.
11
- belongs_to :album, query_constraints: [:singerid, :albumid]
11
+ if ActiveRecord::VERSION::MAJOR >= 8
12
+ belongs_to :album, foreign_key: [:singerid, :albumid]
13
+ else
14
+ belongs_to :album, query_constraints: [:singerid, :albumid]
15
+ end
12
16
 
13
17
  # `tracks` also has a `singerid` column that can be used to associate a Track with a Singer.
14
18
  belongs_to :singer, foreign_key: :singerid
@@ -13,7 +13,7 @@ require_relative "models/track"
13
13
  class Application
14
14
  def self.run
15
15
  # List all singers, albums and tracks.
16
- list_singers_albums_tracks
16
+ list_singers_albums
17
17
 
18
18
  # Create a new album with some tracks.
19
19
  create_new_album
@@ -28,10 +28,6 @@ class Application
28
28
  # Try to delete an album that has at least one track. This IS possible as tracks IS marked with
29
29
  # ON DELETE CASCADE.
30
30
  delete_album_with_tracks
31
-
32
- puts ""
33
- puts "Press any key to end the application"
34
- STDIN.getch
35
31
  end
36
32
 
37
33
  def self.find_singer
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
  require_relative "../models/track"
@@ -16,10 +16,6 @@ class Application
16
16
  tables.rows.each do |row|
17
17
  puts row[:TABLE_NAME]
18
18
  end
19
-
20
- puts ""
21
- puts "Press any key to end the application"
22
- STDIN.getch
23
19
  end
24
20
  end
25
21
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -22,7 +22,7 @@ class Application
22
22
  to_album = Album.where.not(id: from_album.id).sample
23
23
 
24
24
  puts ""
25
- puts "Transferring 10,000 marketing budget from #{from_album.title} (#{from_album.marketing_budget}) "\
25
+ puts "Transferring 10,000 marketing budget from #{from_album.title} (#{from_album.marketing_budget}) " \
26
26
  "to #{to_album.title} (#{to_album.marketing_budget})"
27
27
  from_album.update marketing_budget: from_album.marketing_budget - 10000
28
28
  to_album.update marketing_budget: to_album.marketing_budget + 10000
@@ -37,10 +37,6 @@ class Application
37
37
  puts "Budgets after commit:"
38
38
  puts "Marketing budget #{from_album.title}: #{from_album.reload.marketing_budget}"
39
39
  puts "Marketing budget #{to_album.title}: #{to_album.reload.marketing_budget}"
40
-
41
- puts ""
42
- puts "Press any key to end the application"
43
- STDIN.getch
44
40
  end
45
41
  end
46
42
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
 
@@ -38,10 +38,6 @@ class Application
38
38
 
39
39
  singer.reload
40
40
  puts "Reloaded singer data: #{singer.first_name} #{singer.last_name}, version: #{singer.lock_version}"
41
-
42
- puts ""
43
- puts "Press any key to end the application"
44
- STDIN.getch
45
41
  end
46
42
  end
47
43
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
 
@@ -38,10 +38,6 @@ class Application
38
38
  puts ""
39
39
  puts "Singers in the database: #{singer_count}"
40
40
  puts "Albums in the database: #{album_count}"
41
-
42
- puts ""
43
- puts "Press any key to end the application"
44
- STDIN.getch
45
41
  end
46
42
  end
47
43
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
 
@@ -17,10 +17,6 @@ class Application
17
17
  puts "Query all Albums and include an automatically generated request tag"
18
18
  albums = Album.all
19
19
  puts "Queried #{albums.length} albums using an automatically generated request tag"
20
-
21
- puts ""
22
- puts "Press any key to end the application"
23
- STDIN.getch
24
20
  end
25
21
 
26
22
  def self.enable_query_logs
@@ -31,16 +27,9 @@ class Application
31
27
  # Query log comments *MUST* be prepended to be included as a request tag.
32
28
  ActiveRecord::QueryLogs.prepend_comment = true
33
29
 
34
- # This block manually enables Query Logs without a full Rails application.
30
+ # Enable query logs in a non-Rails application.
35
31
  # This should normally not be needed in your application.
36
- ActiveRecord::QueryLogs.taggings.merge!(
37
- application: "example-app",
38
- action: "run-test-application",
39
- pid: -> { Process.pid.to_s },
40
- socket: ->(context) { context[:connection].pool.db_config.socket },
41
- db_host: ->(context) { context[:connection].pool.db_config.host },
42
- database: ->(context) { context[:connection].pool.db_config.database }
43
- )
32
+ enable_query_logs_without_rails
44
33
 
45
34
  ActiveRecord::QueryLogs.tags = [
46
35
  # The first tag *MUST* be the fixed value 'request_tag:true'.
@@ -58,6 +47,19 @@ class Application
58
47
  :database
59
48
  ]
60
49
  end
50
+
51
+ def self.enable_query_logs_without_rails
52
+ # This block manually enables Query Logs without a full Rails application.
53
+ # This should normally not be needed in your application.
54
+ ActiveRecord::QueryLogs.taggings = {
55
+ application: "example-app",
56
+ action: "run-test-application",
57
+ pid: -> { Process.pid.to_s },
58
+ socket: ->(context) { context[:connection].pool.db_config.socket },
59
+ db_host: ->(context) { context[:connection].pool.db_config.host },
60
+ database: ->(context) { context[:connection].pool.db_config.database }
61
+ }
62
+ end
61
63
  end
62
64
 
63
65
  Application.run
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
 
@@ -41,10 +41,6 @@ class Application
41
41
  Singer.where(last_name.matches("A%")).each do |s|
42
42
  puts "#{s.first_name} #{s.last_name}"
43
43
  end
44
-
45
- puts ""
46
- puts "Press any key to end the application"
47
- STDIN.getch
48
44
  end
49
45
  end
50
46
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10
 
@@ -67,10 +67,6 @@ class Application
67
67
  puts "This error is expected."
68
68
  end
69
69
  end
70
-
71
- puts ""
72
- puts "Press any key to end the application"
73
- STDIN.getch
74
70
  end
75
71
  end
76
72
 
@@ -6,3 +6,4 @@ development:
6
6
  database: testdb
7
7
  pool: 5
8
8
  timeout: 5000
9
+ schema_dump: false
@@ -4,7 +4,7 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
- require_relative "../../config/environment.rb"
7
+ require_relative "../../config/environment"
8
8
  require_relative "../models/singer"
9
9
  require_relative "../models/album"
10
10