From 1223669ba8df38f9bf927ae78e8a573b07d50893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Fri, 20 Dec 2024 18:17:41 +0100 Subject: [PATCH] build: run samples during tests Automatically run all samples as part of the tests. --- .github/workflows/samples.yaml | 30 ++++++++++++++ Gemfile | 4 +- examples/snippets/Rakefile | 32 ++++++++++++--- .../snippets/array-data-type/application.rb | 6 +-- .../array-data-type/config/database.yml | 1 + .../snippets/array-data-type/db/schema.rb | 31 --------------- .../bit-reversed-sequence/application.rb | 4 -- .../bit-reversed-sequence/config/database.yml | 1 + .../bit-reversed-sequence/db/schema.rb | 31 --------------- examples/snippets/bulk-insert/application.rb | 4 -- .../snippets/bulk-insert/config/database.yml | 1 + examples/snippets/bulk-insert/db/schema.rb | 31 --------------- .../snippets/commit-timestamp/application.rb | 4 -- .../commit-timestamp/config/database.yml | 1 + .../snippets/commit-timestamp/db/schema.rb | 34 ---------------- examples/snippets/config/environment.rb | 4 ++ .../snippets/create-records/application.rb | 6 +-- .../create-records/config/database.yml | 1 + examples/snippets/create-records/db/schema.rb | 31 --------------- .../snippets/date-data-type/application.rb | 6 +-- .../date-data-type/config/database.yml | 1 + examples/snippets/date-data-type/db/schema.rb | 26 ------------- .../snippets/generated-column/application.rb | 4 -- .../generated-column/config/database.yml | 1 + .../snippets/generated-column/db/schema.rb | 26 ------------- examples/snippets/hints/application.rb | 4 -- examples/snippets/hints/config/database.yml | 1 + examples/snippets/hints/db/schema.rb | 33 ---------------- .../application.rb | 6 +-- .../config/database.yml | 1 + .../db/schema.rb | 37 ------------------ .../interleaved-tables/application.rb | 6 +-- .../interleaved-tables/config/database.yml | 1 + .../snippets/interleaved-tables/db/schema.rb | 39 ------------------- .../interleaved-tables/models/album.rb | 8 +++- .../interleaved-tables/models/track.rb | 6 ++- examples/snippets/migrations/application.rb | 4 -- .../snippets/migrations/config/database.yml | 1 + examples/snippets/migrations/db/schema.rb | 38 ------------------ examples/snippets/mutations/application.rb | 4 -- .../snippets/mutations/config/database.yml | 1 + examples/snippets/mutations/db/schema.rb | 32 --------------- .../optimistic-locking/application.rb | 4 -- .../optimistic-locking/config/database.yml | 1 + .../snippets/optimistic-locking/db/schema.rb | 34 ---------------- .../snippets/partitioned-dml/application.rb | 4 -- .../partitioned-dml/config/database.yml | 1 + .../snippets/partitioned-dml/db/schema.rb | 31 --------------- examples/snippets/query-logs/application.rb | 8 +--- .../snippets/query-logs/config/database.yml | 1 + examples/snippets/query-logs/db/schema.rb | 31 --------------- examples/snippets/quickstart/application.rb | 4 -- .../snippets/quickstart/config/database.yml | 1 + examples/snippets/quickstart/db/schema.rb | 31 --------------- .../read-only-transactions/application.rb | 4 -- .../config/database.yml | 1 + .../read-only-transactions/db/schema.rb | 31 --------------- .../read-write-transactions/application.rb | 6 +-- .../config/database.yml | 1 + .../read-write-transactions/db/schema.rb | 32 --------------- examples/snippets/stale-reads/application.rb | 4 -- .../snippets/stale-reads/config/database.yml | 1 + examples/snippets/stale-reads/db/schema.rb | 31 --------------- examples/snippets/tags/application.rb | 4 -- examples/snippets/tags/config/database.yml | 1 + examples/snippets/tags/db/schema.rb | 31 --------------- .../timestamp-data-type/application.rb | 4 -- .../timestamp-data-type/config/database.yml | 1 + .../snippets/timestamp-data-type/db/schema.rb | 26 ------------- 69 files changed, 103 insertions(+), 769 deletions(-) create mode 100644 .github/workflows/samples.yaml delete mode 100644 examples/snippets/array-data-type/db/schema.rb delete mode 100644 examples/snippets/bit-reversed-sequence/db/schema.rb delete mode 100644 examples/snippets/bulk-insert/db/schema.rb delete mode 100644 examples/snippets/commit-timestamp/db/schema.rb delete mode 100644 examples/snippets/create-records/db/schema.rb delete mode 100644 examples/snippets/date-data-type/db/schema.rb delete mode 100644 examples/snippets/generated-column/db/schema.rb delete mode 100644 examples/snippets/hints/db/schema.rb delete mode 100644 examples/snippets/interleaved-tables-before-7.1/db/schema.rb delete mode 100644 examples/snippets/interleaved-tables/db/schema.rb delete mode 100644 examples/snippets/migrations/db/schema.rb delete mode 100644 examples/snippets/mutations/db/schema.rb delete mode 100644 examples/snippets/optimistic-locking/db/schema.rb delete mode 100644 examples/snippets/partitioned-dml/db/schema.rb delete mode 100644 examples/snippets/query-logs/db/schema.rb delete mode 100644 examples/snippets/quickstart/db/schema.rb delete mode 100644 examples/snippets/read-only-transactions/db/schema.rb delete mode 100644 examples/snippets/read-write-transactions/db/schema.rb delete mode 100644 examples/snippets/stale-reads/db/schema.rb delete mode 100644 examples/snippets/tags/db/schema.rb delete mode 100644 examples/snippets/timestamp-data-type/db/schema.rb diff --git a/.github/workflows/samples.yaml b/.github/workflows/samples.yaml new file mode 100644 index 00000000..e237daed --- /dev/null +++ b/.github/workflows/samples.yaml @@ -0,0 +1,30 @@ +on: + pull_request: +name: samples +jobs: + test: + runs-on: ubuntu-latest + + strategy: + max-parallel: 4 + matrix: + ruby: ["3.1", "3.2", "3.3"] + ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"] + # Exclude combinations that are not supported. + exclude: + - ruby: "3.1" + ar: "~> 8.0.0" + env: + AR_VERSION: ${{ matrix.ar }} + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: false + ruby-version: ${{ matrix.ruby }} + - name: Install dependencies + run: bundle install + - name: Run samples + run: bundle exec rake all + working-directory: examples/snippets diff --git a/Gemfile b/Gemfile index 25477334..607c61ac 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,8 @@ gem "activerecord", ar_version gem "ostruct" gem "minitest", "~> 5.25.0" gem "minitest-rg", "~> 5.3.0" -gem "pry", "~> 0.13.0" -gem "pry-byebug", "~> 3.9.0" +gem "pry", "~> 0.14.2" +gem "pry-byebug", "~> 3.10.1" # Add sqlite3 for testing for compatibility with other adapters. gem 'sqlite3' diff --git a/examples/snippets/Rakefile b/examples/snippets/Rakefile index 35b98d6d..5acc07b6 100644 --- a/examples/snippets/Rakefile +++ b/examples/snippets/Rakefile @@ -7,19 +7,37 @@ require_relative "config/environment" require "docker" -desc "Lists all available samples." -task :list do - samples = Dir.entries(".").select do |entry| +def fetch_samples + Dir.entries(".").select do |entry| File.directory?(File.join(".", entry)) \ - && !%w[. ..].include?(entry) \ - && File.exist?(File.join(".", entry, "application.rb")) + && !%w[. ..].include?(entry) \ + && File.exist?(File.join(".", entry, "application.rb")) end +end + +desc "Lists all available samples." +task :list do + samples = fetch_samples puts "Available samples: " samples.sort.each { |dir| puts " #{dir}" } puts "" puts "Run a sample with the command `bundle exec rake run\\[\\]`" end +desc "Runs all samples." +task :all do + samples = fetch_samples + ar_version = ENV.fetch "AR_VERSION", "~> 7.1.0" + less_than_7_1 = ar_version.dup.to_s.sub("~>", "").strip < "7.1.0" + samples.delete "interleaved-tables" if less_than_7_1 + samples.delete "interleaved-tables-before-7.1" unless less_than_7_1 + samples.delete "bit-reversed-sequence" if less_than_7_1 + samples.delete "query-logs" if less_than_7_1 + samples.each do |sample| + run_sample sample + end +end + desc "Runs a simple ActiveRecord tutorial on a Spanner emulator." task :run, [:sample] do |_t, args| sample = args[:sample] @@ -28,7 +46,11 @@ task :run, [:sample] do |_t, args| puts "" sample = "quickstart" end + run_sample sample +end +def run_sample sample + puts "Running #{sample}" puts "Downloading Spanner emulator image..." Docker::Image.create "fromImage" => "gcr.io/cloud-spanner-emulator/emulator:latest" puts "Creating Spanner emulator container..." diff --git a/examples/snippets/array-data-type/application.rb b/examples/snippets/array-data-type/application.rb index cebf8fd7..f32c4190 100644 --- a/examples/snippets/array-data-type/application.rb +++ b/examples/snippets/array-data-type/application.rb @@ -9,7 +9,7 @@ require_relative "models/entity_with_array_types" class Application - def self.run # rubocop:disable Metrics/AbcSize + def self.run # Create a record with all array types. record = EntityWithArrayTypes.create \ col_array_string: ["value1", "value2", "value3"], @@ -35,10 +35,6 @@ def self.run # rubocop:disable Metrics/AbcSize puts "Bytes array: #{record.col_array_bytes.map(&:read)}" puts "Date array: #{record.col_array_date}" puts "Timestamp array: #{record.col_array_timestamp}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/array-data-type/config/database.yml b/examples/snippets/array-data-type/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/array-data-type/config/database.yml +++ b/examples/snippets/array-data-type/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/array-data-type/db/schema.rb b/examples/snippets/array-data-type/db/schema.rb deleted file mode 100644 index 918e0d0d..00000000 --- a/examples/snippets/array-data-type/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "entity_with_array_types", id: { limit: 8 }, force: :cascade do |t| - t.string "col_array_string" - t.integer "col_array_int64", limit: 8 - t.float "col_array_float64" - t.decimal "col_array_numeric" - t.boolean "col_array_bool" - t.binary "col_array_bytes" - t.date "col_array_date" - t.time "col_array_timestamp" - end - - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/bit-reversed-sequence/application.rb b/examples/snippets/bit-reversed-sequence/application.rb index 89504bde..1b00caa1 100644 --- a/examples/snippets/bit-reversed-sequence/application.rb +++ b/examples/snippets/bit-reversed-sequence/application.rb @@ -22,10 +22,6 @@ def self.run # List all singers, albums and tracks. list_singers_albums - - puts "" - puts "Press any key to end the application" - $stdin.getch end def self.find_album singerid, albumid diff --git a/examples/snippets/bit-reversed-sequence/config/database.yml b/examples/snippets/bit-reversed-sequence/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/bit-reversed-sequence/config/database.yml +++ b/examples/snippets/bit-reversed-sequence/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/bit-reversed-sequence/db/schema.rb b/examples/snippets/bit-reversed-sequence/db/schema.rb deleted file mode 100644 index 227d2ebd..00000000 --- a/examples/snippets/bit-reversed-sequence/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[7.1].define(version: 1) do - connection.start_batch_ddl - - create_table "albums", primary_key: ["singerid", "albumid"], force: :cascade do |t| - t.integer "singerid", limit: 8, null: false - t.integer "albumid", limit: 8, null: false - t.string "title" - end - - create_table "singers", primary_key: "singerid", default: -> { "GET_NEXT_SEQUENCE_VALUE(SEQUENCE singer_sequence)" }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/bulk-insert/application.rb b/examples/snippets/bulk-insert/application.rb index 5a332488..34acf2d3 100644 --- a/examples/snippets/bulk-insert/application.rb +++ b/examples/snippets/bulk-insert/application.rb @@ -54,10 +54,6 @@ def self.run # rubocop:disable Metrics/AbcSize puts " with album #{a.title} with id #{a.id}" end end - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/bulk-insert/config/database.yml b/examples/snippets/bulk-insert/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/bulk-insert/config/database.yml +++ b/examples/snippets/bulk-insert/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/bulk-insert/db/schema.rb b/examples/snippets/bulk-insert/db/schema.rb deleted file mode 100644 index 44205d95..00000000 --- a/examples/snippets/bulk-insert/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/commit-timestamp/application.rb b/examples/snippets/commit-timestamp/application.rb index 62ea01c1..1116fef1 100644 --- a/examples/snippets/commit-timestamp/application.rb +++ b/examples/snippets/commit-timestamp/application.rb @@ -43,10 +43,6 @@ def self.run # rubocop:disable Metrics/AbcSize puts "Singer and album updated:" puts "#{singer.first_name} #{singer.last_name} (Last updated: #{singer.last_updated.strftime format})" puts " #{album.title} (Last updated: #{album.last_updated.strftime format})" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/commit-timestamp/config/database.yml b/examples/snippets/commit-timestamp/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/commit-timestamp/config/database.yml +++ b/examples/snippets/commit-timestamp/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/commit-timestamp/db/schema.rb b/examples/snippets/commit-timestamp/db/schema.rb deleted file mode 100644 index 3bce4e80..00000000 --- a/examples/snippets/commit-timestamp/db/schema.rb +++ /dev/null @@ -1,34 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.decimal "marketing_budget" - t.integer "singer_id", limit: 8 - t.time "last_updated", allow_commit_timestamp: true - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - t.time "last_updated", allow_commit_timestamp: true - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/config/environment.rb b/examples/snippets/config/environment.rb index 29ed328f..899d32c1 100644 --- a/examples/snippets/config/environment.rb +++ b/examples/snippets/config/environment.rb @@ -9,6 +9,10 @@ Dir["../../lib/*.rb"].each { |file| require file } +if ActiveRecord.version >= Gem::Version.create("7.2.0") + ActiveRecord::ConnectionAdapters.register "spanner", "ActiveRecord::ConnectionAdapters::SpannerAdapter" +end + Bundler.require ActiveRecord::Base.establish_connection( diff --git a/examples/snippets/create-records/application.rb b/examples/snippets/create-records/application.rb index 95183f45..d1a19805 100644 --- a/examples/snippets/create-records/application.rb +++ b/examples/snippets/create-records/application.rb @@ -13,7 +13,7 @@ class Application def self.run # Creating a single record without an explicit transaction will automatically save it to the database. # It is not recommended to call Entity.create repeatedly to insert multiple records, as each call will - # use a separate Spanner transaction. Instead multiple records should be created by passing an array of + # use a separate Spanner transaction. Instead, multiple records should be created by passing an array of # entities to the Entity.create method. singer = Singer.create first_name: "Dave", last_name: "Allison" puts "" @@ -32,10 +32,6 @@ def self.run singers.each do |s| puts " Created singer #{s.first_name} #{s.last_name} with id #{s.id}" end - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/create-records/config/database.yml b/examples/snippets/create-records/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/create-records/config/database.yml +++ b/examples/snippets/create-records/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/create-records/db/schema.rb b/examples/snippets/create-records/db/schema.rb deleted file mode 100644 index 44205d95..00000000 --- a/examples/snippets/create-records/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/date-data-type/application.rb b/examples/snippets/date-data-type/application.rb index 81ecadc0..b07b2b07 100644 --- a/examples/snippets/date-data-type/application.rb +++ b/examples/snippets/date-data-type/application.rb @@ -17,7 +17,7 @@ def self.run puts "#{"#{singer.first_name} #{singer.last_name}".ljust 30}#{singer.birth_date}" end - # Update the birth date of a random singer using the current system time. Any time and timezone information will be + # Update the birthdate of a random singer using the current system time. Any time and timezone information will be # lost after saving the record as a DATE only contains the year, month and day-of-month information. singer = Singer.all.sample singer.update birth_date: Time.now @@ -25,10 +25,6 @@ def self.run puts "" puts "Updated birth date to current system time:" puts "#{"#{singer.first_name} #{singer.last_name}".ljust 30}#{singer.birth_date}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/date-data-type/config/database.yml b/examples/snippets/date-data-type/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/date-data-type/config/database.yml +++ b/examples/snippets/date-data-type/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/date-data-type/db/schema.rb b/examples/snippets/date-data-type/db/schema.rb deleted file mode 100644 index 77bfb5ef..00000000 --- a/examples/snippets/date-data-type/db/schema.rb +++ /dev/null @@ -1,26 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - t.date "birth_date" - end - - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/generated-column/application.rb b/examples/snippets/generated-column/application.rb index 1ab132c9..c686b592 100644 --- a/examples/snippets/generated-column/application.rb +++ b/examples/snippets/generated-column/application.rb @@ -27,10 +27,6 @@ def self.run singer.reload puts "" puts "Singer updated: #{singer.full_name}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/generated-column/config/database.yml b/examples/snippets/generated-column/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/generated-column/config/database.yml +++ b/examples/snippets/generated-column/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/generated-column/db/schema.rb b/examples/snippets/generated-column/db/schema.rb deleted file mode 100644 index 347c57af..00000000 --- a/examples/snippets/generated-column/db/schema.rb +++ /dev/null @@ -1,26 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name", limit: 100 - t.string "last_name", limit: 200, null: false - t.virtual "full_name", type: :string, limit: 300, null: false, as: "COALESCE(first_name || ' ', '') || last_name", stored: true - end - - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/hints/application.rb b/examples/snippets/hints/application.rb index fd1375cf..26ef7002 100644 --- a/examples/snippets/hints/application.rb +++ b/examples/snippets/hints/application.rb @@ -37,10 +37,6 @@ def self.run .distinct.order("last_name, first_name").each do |singer| puts singer.full_name end - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/hints/config/database.yml b/examples/snippets/hints/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/hints/config/database.yml +++ b/examples/snippets/hints/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/hints/db/schema.rb b/examples/snippets/hints/db/schema.rb deleted file mode 100644 index f0377638..00000000 --- a/examples/snippets/hints/db/schema.rb +++ /dev/null @@ -1,33 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name", limit: 100 - t.string "last_name", limit: 200, null: false - t.virtual "full_name", type: :string, limit: 300, null: false, as: "COALESCE(first_name || ' ', '') || last_name", stored: true - t.index ["full_name"], name: "index_singers_on_full_name", order: { full_name: :asc } - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/interleaved-tables-before-7.1/application.rb b/examples/snippets/interleaved-tables-before-7.1/application.rb index cc41cc50..b80f3121 100644 --- a/examples/snippets/interleaved-tables-before-7.1/application.rb +++ b/examples/snippets/interleaved-tables-before-7.1/application.rb @@ -13,7 +13,7 @@ class Application def self.run # List all singers, albums and tracks. - list_singers_albums_tracks + list_singers_albums # Create a new album with some tracks. create_new_album @@ -28,10 +28,6 @@ def self.run # Try to delete an album that has at least one track. This IS possible as tracks IS marked with # ON DELETE CASCADE. delete_album_with_tracks - - puts "" - puts "Press any key to end the application" - $stdin.getch end def self.find_singer diff --git a/examples/snippets/interleaved-tables-before-7.1/config/database.yml b/examples/snippets/interleaved-tables-before-7.1/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/interleaved-tables-before-7.1/config/database.yml +++ b/examples/snippets/interleaved-tables-before-7.1/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/interleaved-tables-before-7.1/db/schema.rb b/examples/snippets/interleaved-tables-before-7.1/db/schema.rb deleted file mode 100644 index 7b5fe1e7..00000000 --- a/examples/snippets/interleaved-tables-before-7.1/db/schema.rb +++ /dev/null @@ -1,37 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", primary_key: "albumid", force: :cascade do |t| - t.integer "singerid", limit: 8, null: false - t.string "title" - end - - create_table "singers", primary_key: "singerid", force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - create_table "tracks", primary_key: "trackid", force: :cascade do |t| - t.integer "singerid", limit: 8, null: false - t.integer "albumid", limit: 8, null: false - t.string "title" - t.decimal "duration" - end - - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/interleaved-tables/application.rb b/examples/snippets/interleaved-tables/application.rb index 9e325cc1..3d351ba6 100644 --- a/examples/snippets/interleaved-tables/application.rb +++ b/examples/snippets/interleaved-tables/application.rb @@ -13,7 +13,7 @@ class Application def self.run # List all singers, albums and tracks. - list_singers_albums_tracks + list_singers_albums # Create a new album with some tracks. create_new_album @@ -28,10 +28,6 @@ def self.run # Try to delete an album that has at least one track. This IS possible as tracks IS marked with # ON DELETE CASCADE. delete_album_with_tracks - - puts "" - puts "Press any key to end the application" - $stdin.getch end def self.find_singer diff --git a/examples/snippets/interleaved-tables/config/database.yml b/examples/snippets/interleaved-tables/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/interleaved-tables/config/database.yml +++ b/examples/snippets/interleaved-tables/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/interleaved-tables/db/schema.rb b/examples/snippets/interleaved-tables/db/schema.rb deleted file mode 100644 index 4f031c25..00000000 --- a/examples/snippets/interleaved-tables/db/schema.rb +++ /dev/null @@ -1,39 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[7.1].define(version: 1) do - connection.start_batch_ddl - - create_table "albums", primary_key: ["singerid", "albumid"], force: :cascade do |t| - t.integer "singerid", limit: 8 - t.integer "albumid", limit: 8 - t.string "title" - end - - create_table "singers", primary_key: "singerid", force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - create_table "tracks", primary_key: ["singerid", "albumid", "trackid"], force: :cascade do |t| - t.integer "singerid", limit: 8 - t.integer "albumid", limit: 8 - t.integer "trackid", limit: 8 - t.string "title" - t.decimal "duration" - end - - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/interleaved-tables/models/album.rb b/examples/snippets/interleaved-tables/models/album.rb index 2f94f52d..12077f04 100644 --- a/examples/snippets/interleaved-tables/models/album.rb +++ b/examples/snippets/interleaved-tables/models/album.rb @@ -11,6 +11,10 @@ class Album < ActiveRecord::Base # `tracks` is defined as INTERLEAVE IN PARENT `albums`. # The primary key of `albums` is (`singerid`, `albumid`). - # Rails 7.1 requires using query_constraints to define a composite foreign key. - has_many :tracks, query_constraints: [:singerid, :albumid] + if ActiveRecord::VERSION::MAJOR >= 8 + has_many :tracks, foreign_key: [:singerid, :albumid] + else + # Rails 7.1 requires using query_constraints to define a composite foreign key. + has_many :tracks, query_constraints: [:singerid, :albumid] + end end diff --git a/examples/snippets/interleaved-tables/models/track.rb b/examples/snippets/interleaved-tables/models/track.rb index f095f861..17125979 100644 --- a/examples/snippets/interleaved-tables/models/track.rb +++ b/examples/snippets/interleaved-tables/models/track.rb @@ -8,7 +8,11 @@ class Track < ActiveRecord::Base # `tracks` is defined as INTERLEAVE IN PARENT `albums`. # The primary key of `albums` is (`singerid`, `albumid`). # Rails 7.1 requires a composite primary key in a belongs_to relationship to be specified as query_constraints. - belongs_to :album, query_constraints: [:singerid, :albumid] + if ActiveRecord::VERSION::MAJOR >= 8 + belongs_to :album, foreign_key: [:singerid, :albumid] + else + belongs_to :album, query_constraints: [:singerid, :albumid] + end # `tracks` also has a `singerid` column that can be used to associate a Track with a Singer. belongs_to :singer, foreign_key: :singerid diff --git a/examples/snippets/migrations/application.rb b/examples/snippets/migrations/application.rb index ccbdfa7f..bcce3d20 100644 --- a/examples/snippets/migrations/application.rb +++ b/examples/snippets/migrations/application.rb @@ -16,10 +16,6 @@ def self.run tables.rows.each do |row| puts row[:TABLE_NAME] end - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/migrations/config/database.yml b/examples/snippets/migrations/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/migrations/config/database.yml +++ b/examples/snippets/migrations/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/migrations/db/schema.rb b/examples/snippets/migrations/db/schema.rb deleted file mode 100644 index 93f4bf6f..00000000 --- a/examples/snippets/migrations/db/schema.rb +++ /dev/null @@ -1,38 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singers_id", limit: 8 - t.index ["singers_id"], name: "index_albums_on_singers_id", order: { singers_id: :asc } - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - create_table "tracks", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.decimal "duration" - t.integer "albums_id", limit: 8 - t.index ["albums_id"], name: "index_tracks_on_albums_id", order: { albums_id: :asc } - end - - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/mutations/application.rb b/examples/snippets/mutations/application.rb index d520a4f0..74e8f472 100644 --- a/examples/snippets/mutations/application.rb +++ b/examples/snippets/mutations/application.rb @@ -37,10 +37,6 @@ def self.run # rubocop:disable Metrics/AbcSize puts "Budgets after commit:" puts "Marketing budget #{from_album.title}: #{from_album.reload.marketing_budget}" puts "Marketing budget #{to_album.title}: #{to_album.reload.marketing_budget}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/mutations/config/database.yml b/examples/snippets/mutations/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/mutations/config/database.yml +++ b/examples/snippets/mutations/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/mutations/db/schema.rb b/examples/snippets/mutations/db/schema.rb deleted file mode 100644 index 72a2302c..00000000 --- a/examples/snippets/mutations/db/schema.rb +++ /dev/null @@ -1,32 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.decimal "marketing_budget" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/optimistic-locking/application.rb b/examples/snippets/optimistic-locking/application.rb index 0724110e..a3ff8d13 100644 --- a/examples/snippets/optimistic-locking/application.rb +++ b/examples/snippets/optimistic-locking/application.rb @@ -38,10 +38,6 @@ def self.run singer.reload puts "Reloaded singer data: #{singer.first_name} #{singer.last_name}, version: #{singer.lock_version}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/optimistic-locking/config/database.yml b/examples/snippets/optimistic-locking/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/optimistic-locking/config/database.yml +++ b/examples/snippets/optimistic-locking/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/optimistic-locking/db/schema.rb b/examples/snippets/optimistic-locking/db/schema.rb deleted file mode 100644 index f3209f44..00000000 --- a/examples/snippets/optimistic-locking/db/schema.rb +++ /dev/null @@ -1,34 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.decimal "marketing_budget" - t.integer "singer_id", limit: 8 - t.integer "lock_version", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - t.integer "lock_version", limit: 8 - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/partitioned-dml/application.rb b/examples/snippets/partitioned-dml/application.rb index 77962022..83a4f792 100644 --- a/examples/snippets/partitioned-dml/application.rb +++ b/examples/snippets/partitioned-dml/application.rb @@ -38,10 +38,6 @@ def self.run puts "" puts "Singers in the database: #{singer_count}" puts "Albums in the database: #{album_count}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/partitioned-dml/config/database.yml b/examples/snippets/partitioned-dml/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/partitioned-dml/config/database.yml +++ b/examples/snippets/partitioned-dml/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/partitioned-dml/db/schema.rb b/examples/snippets/partitioned-dml/db/schema.rb deleted file mode 100644 index 15764fa4..00000000 --- a/examples/snippets/partitioned-dml/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name", limit: 100 - t.string "last_name", limit: 200, null: false - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/query-logs/application.rb b/examples/snippets/query-logs/application.rb index 101e90df..d60ac7a2 100644 --- a/examples/snippets/query-logs/application.rb +++ b/examples/snippets/query-logs/application.rb @@ -17,10 +17,6 @@ def self.run puts "Query all Albums and include an automatically generated request tag" albums = Album.all puts "Queried #{albums.length} albums using an automatically generated request tag" - - puts "" - puts "Press any key to end the application" - $stdin.getch end def self.enable_query_logs @@ -55,14 +51,14 @@ def self.enable_query_logs def self.enable_query_logs_without_rails # This block manually enables Query Logs without a full Rails application. # This should normally not be needed in your application. - ActiveRecord::QueryLogs.taggings.merge!( + ActiveRecord::QueryLogs.taggings = { application: "example-app", action: "run-test-application", pid: -> { Process.pid.to_s }, socket: ->(context) { context[:connection].pool.db_config.socket }, db_host: ->(context) { context[:connection].pool.db_config.host }, database: ->(context) { context[:connection].pool.db_config.database } - ) + } end end diff --git a/examples/snippets/query-logs/config/database.yml b/examples/snippets/query-logs/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/query-logs/config/database.yml +++ b/examples/snippets/query-logs/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/query-logs/db/schema.rb b/examples/snippets/query-logs/db/schema.rb deleted file mode 100644 index dc7b860a..00000000 --- a/examples/snippets/query-logs/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[7.1].define(version: 1) do - connection.start_batch_ddl - - create_table "albums", force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/quickstart/application.rb b/examples/snippets/quickstart/application.rb index 1269961f..80fb5482 100644 --- a/examples/snippets/quickstart/application.rb +++ b/examples/snippets/quickstart/application.rb @@ -41,10 +41,6 @@ def self.run # rubocop:disable Metrics/AbcSize Singer.where(last_name.matches("A%")).each do |s| puts "#{s.first_name} #{s.last_name}" end - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/quickstart/config/database.yml b/examples/snippets/quickstart/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/quickstart/config/database.yml +++ b/examples/snippets/quickstart/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/quickstart/db/schema.rb b/examples/snippets/quickstart/db/schema.rb deleted file mode 100644 index 44205d95..00000000 --- a/examples/snippets/quickstart/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/read-only-transactions/application.rb b/examples/snippets/read-only-transactions/application.rb index cd0c43aa..16a7223d 100644 --- a/examples/snippets/read-only-transactions/application.rb +++ b/examples/snippets/read-only-transactions/application.rb @@ -67,10 +67,6 @@ def self.run # rubocop:disable Metrics/AbcSize puts "This error is expected." end end - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/read-only-transactions/config/database.yml b/examples/snippets/read-only-transactions/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/read-only-transactions/config/database.yml +++ b/examples/snippets/read-only-transactions/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/read-only-transactions/db/schema.rb b/examples/snippets/read-only-transactions/db/schema.rb deleted file mode 100644 index 44205d95..00000000 --- a/examples/snippets/read-only-transactions/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/read-write-transactions/application.rb b/examples/snippets/read-write-transactions/application.rb index 38e8bb02..4f0db251 100644 --- a/examples/snippets/read-write-transactions/application.rb +++ b/examples/snippets/read-write-transactions/application.rb @@ -10,7 +10,7 @@ require_relative "models/album" class Application - def self.run # rubocop:disable Metrics/AbcSize + def self.run from_album = nil to_album = nil # Use a read/write transaction to execute multiple statements as an atomic unit. @@ -29,10 +29,6 @@ def self.run # rubocop:disable Metrics/AbcSize puts "Budgets after update:" puts "Marketing budget #{from_album.title}: #{from_album.reload.marketing_budget}" puts "Marketing budget #{to_album.title}: #{to_album.reload.marketing_budget}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/read-write-transactions/config/database.yml b/examples/snippets/read-write-transactions/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/read-write-transactions/config/database.yml +++ b/examples/snippets/read-write-transactions/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/read-write-transactions/db/schema.rb b/examples/snippets/read-write-transactions/db/schema.rb deleted file mode 100644 index 72a2302c..00000000 --- a/examples/snippets/read-write-transactions/db/schema.rb +++ /dev/null @@ -1,32 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.decimal "marketing_budget" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/stale-reads/application.rb b/examples/snippets/stale-reads/application.rb index d767354b..59bd0ac2 100644 --- a/examples/snippets/stale-reads/application.rb +++ b/examples/snippets/stale-reads/application.rb @@ -53,10 +53,6 @@ def self.run # rubocop:disable Metrics/AbcSize puts "" puts "Updated album title: #{album.title}" puts "Title somewhere during the last 10 seconds: #{album_max_staleness&.title}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/stale-reads/config/database.yml b/examples/snippets/stale-reads/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/stale-reads/config/database.yml +++ b/examples/snippets/stale-reads/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/stale-reads/db/schema.rb b/examples/snippets/stale-reads/db/schema.rb deleted file mode 100644 index 44205d95..00000000 --- a/examples/snippets/stale-reads/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/tags/application.rb b/examples/snippets/tags/application.rb index cdd82269..525a8c2a 100644 --- a/examples/snippets/tags/application.rb +++ b/examples/snippets/tags/application.rb @@ -22,10 +22,6 @@ def self.run albums = Album.annotate("request_tag: query-all-albums", "transaction_tag: sample-transaction").all puts "Queried #{albums.length} albums using a request and a transaction tag" end - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/tags/config/database.yml b/examples/snippets/tags/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/tags/config/database.yml +++ b/examples/snippets/tags/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/tags/db/schema.rb b/examples/snippets/tags/db/schema.rb deleted file mode 100644 index 44205d95..00000000 --- a/examples/snippets/tags/db/schema.rb +++ /dev/null @@ -1,31 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "albums", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.integer "singer_id", limit: 8 - end - - create_table "singers", id: { limit: 8 }, force: :cascade do |t| - t.string "first_name" - t.string "last_name" - end - - add_foreign_key "albums", "singers" - connection.run_batch -rescue - abort_batch - raise -end diff --git a/examples/snippets/timestamp-data-type/application.rb b/examples/snippets/timestamp-data-type/application.rb index 84684278..7437ac16 100644 --- a/examples/snippets/timestamp-data-type/application.rb +++ b/examples/snippets/timestamp-data-type/application.rb @@ -32,10 +32,6 @@ def self.run # Simulate that the application is now running in the timezone America/Los_Angeles. Time.zone = "America/Los_Angeles" puts "#{'Meeting time in the local timezone (America/Los_Angeles):'.ljust 60} #{meeting.local_meeting_time}" - - puts "" - puts "Press any key to end the application" - $stdin.getch end end diff --git a/examples/snippets/timestamp-data-type/config/database.yml b/examples/snippets/timestamp-data-type/config/database.yml index 905be603..f9f072b8 100644 --- a/examples/snippets/timestamp-data-type/config/database.yml +++ b/examples/snippets/timestamp-data-type/config/database.yml @@ -6,3 +6,4 @@ development: database: testdb pool: 5 timeout: 5000 + schema_dump: false diff --git a/examples/snippets/timestamp-data-type/db/schema.rb b/examples/snippets/timestamp-data-type/db/schema.rb deleted file mode 100644 index f68d7cb5..00000000 --- a/examples/snippets/timestamp-data-type/db/schema.rb +++ /dev/null @@ -1,26 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 1) do - connection.start_batch_ddl - - create_table "meetings", id: { limit: 8 }, force: :cascade do |t| - t.string "title" - t.time "meeting_time" - t.string "meeting_timezone" - end - - connection.run_batch -rescue - abort_batch - raise -end