diff --git a/.rubocop.yml b/.rubocop.yml index 73cc354..250a432 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,4 +5,5 @@ AllCops: Exclude: - test/dummy/db/schema.rb - test/dummy/db/queue_schema.rb + - test/dummy/db/persistent_schema.rb - test/dummy/db/migrate/**/* diff --git a/app/models/upright/persistent_record.rb b/app/models/upright/persistent_record.rb new file mode 100644 index 0000000..dad823b --- /dev/null +++ b/app/models/upright/persistent_record.rb @@ -0,0 +1,6 @@ +# Durable, replicated source-of-truth data (rollups, later incidents/maintenance) on the persistent DB. +class Upright::PersistentRecord < ActiveRecord::Base + self.abstract_class = true + + connects_to database: { writing: :persistent, reading: :persistent } +end diff --git a/app/models/upright/rollups/probe_rollup.rb b/app/models/upright/rollups/probe_rollup.rb index 4d69588..e80a8ff 100644 --- a/app/models/upright/rollups/probe_rollup.rb +++ b/app/models/upright/rollups/probe_rollup.rb @@ -1,4 +1,4 @@ -class Upright::Rollups::ProbeRollup < Upright::ApplicationRecord +class Upright::Rollups::ProbeRollup < Upright::PersistentRecord self.table_name = "upright_rollups_probe_rollups" enum :status, Upright::Status::VALUES, default: :operational diff --git a/db/migrate/20260512000001_create_upright_rollups.rb b/db/persistent_migrate/20260512000001_create_upright_rollups.rb similarity index 100% rename from db/migrate/20260512000001_create_upright_rollups.rb rename to db/persistent_migrate/20260512000001_create_upright_rollups.rb diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml index e1c41fc..aa31409 100644 --- a/test/dummy/config/database.yml +++ b/test/dummy/config/database.yml @@ -1,9 +1,10 @@ -# SQLite. Versions 3.8.0 and up are supported. -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem "sqlite3" -# +# SQLite, for the engine's dummy test app. Three databases mirror production's +# logical split: +# primary - per-site probe results + Active Storage artifacts (the default +# connection; engine's create_upright_probe_results lives in +# ../../db/migrate, Active Storage in db/migrate) +# persistent - durable source-of-truth rollups (../../db/persistent_migrate) +# queue - Solid Queue (db/queue_migrate) default: &default adapter: sqlite3 max_connections: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> @@ -13,33 +14,30 @@ development: primary: <<: *default database: storage/development.sqlite3 + migrations_paths: + - db/migrate + - ../../db/migrate + persistent: + <<: *default + database: storage/development_persistent.sqlite3 + migrations_paths: ../../db/persistent_migrate queue: <<: *default database: storage/development_queue.sqlite3 migrations_paths: db/queue_migrate -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. test: primary: <<: *default database: storage/test.sqlite3 - queue: - <<: *default - database: storage/test_queue.sqlite3 - migrations_paths: db/queue_migrate - - -# SQLite3 write its data on the local filesystem, as such it requires -# persistent disks. If you are deploying to a managed service, you should -# make sure it provides disk persistence, as many don't. -# -# Similarly, if you deploy your application as a Docker container, you must -# ensure the database is located in a persisted volume. -production: - primary: + migrations_paths: + - db/migrate + - ../../db/migrate + persistent: <<: *default + database: storage/test_persistent.sqlite3 + migrations_paths: ../../db/persistent_migrate queue: <<: *default + database: storage/test_queue.sqlite3 migrations_paths: db/queue_migrate diff --git a/test/dummy/db/persistent_schema.rb b/test/dummy/db/persistent_schema.rb new file mode 100644 index 0000000..c415e6c --- /dev/null +++ b/test/dummy/db/persistent_schema.rb @@ -0,0 +1,25 @@ +# 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[8.1].define(version: 2026_05_12_000001) do + create_table "upright_rollups_probe_rollups", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "period_start", null: false + t.string "probe_name", null: false + t.string "probe_service" + t.integer "status", default: 0, null: false + t.datetime "updated_at", null: false + t.float "uptime_fraction", null: false + t.index ["probe_name", "period_start"], name: "idx_on_probe_name_period_start_3a6029f64e", unique: true + t.index ["probe_service", "period_start"], name: "idx_on_probe_service_period_start_c65e2bccc5" + end +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 4bc95c4..c671aa7 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_05_12_000001) do +ActiveRecord::Schema[8.1].define(version: 2025_01_14_000001) do create_table "active_storage_attachments", force: :cascade do |t| t.bigint "blob_id", null: false t.datetime "created_at", null: false @@ -54,18 +54,6 @@ t.index ["status"], name: "index_upright_probe_results_on_status" end - create_table "upright_rollups_probe_rollups", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "period_start", null: false - t.string "probe_name", null: false - t.string "probe_service" - t.integer "status", default: 0, null: false - t.datetime "updated_at", null: false - t.float "uptime_fraction", null: false - t.index ["probe_name", "period_start"], name: "idx_on_probe_name_period_start_3a6029f64e", unique: true - t.index ["probe_service", "period_start"], name: "idx_on_probe_service_period_start_c65e2bccc5" - end - add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" end diff --git a/test/test_helper.rb b/test/test_helper.rb index 96c8153..88ea979 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,8 +2,6 @@ ENV["RAILS_ENV"] = "test" require_relative "../test/dummy/config/environment" -ActiveRecord::Migrator.migrations_paths = [ File.expand_path("../test/dummy/db/migrate", __dir__) ] -ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__) require "rails/test_help" require "mocha/minitest" require "webmock/minitest"