Centralize durable schema migration ownership
This commit is contained in:
parent
cc328237f4
commit
069f3813ae
6 changed files with 354 additions and 350 deletions
|
|
@ -18,5 +18,6 @@ sqlx.workspace = true
|
|||
thiserror.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
remora-schema.workspace = true
|
||||
remora-target = { path = "../remora-target", features = ["test-utils"] }
|
||||
tokio.workspace = true
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
CREATE TABLE result_inventories (
|
||||
attempt_id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'closed', 'sealed')),
|
||||
manifest_schema_version INTEGER,
|
||||
manifest_id TEXT,
|
||||
manifest_store TEXT,
|
||||
manifest_bucket TEXT,
|
||||
manifest_key TEXT,
|
||||
manifest_version_id TEXT,
|
||||
manifest_sha256 TEXT,
|
||||
manifest_size BIGINT,
|
||||
member_count BIGINT NOT NULL DEFAULT 0 CHECK (member_count >= 0),
|
||||
total_bytes BIGINT NOT NULL DEFAULT 0 CHECK (total_bytes >= 0),
|
||||
CHECK (
|
||||
(state <> 'sealed' AND manifest_schema_version IS NULL AND manifest_id IS NULL
|
||||
AND manifest_store IS NULL AND manifest_bucket IS NULL AND manifest_key IS NULL
|
||||
AND manifest_version_id IS NULL AND manifest_sha256 IS NULL AND manifest_size IS NULL)
|
||||
OR
|
||||
(state = 'sealed' AND manifest_schema_version IS NOT NULL AND manifest_id IS NOT NULL
|
||||
AND manifest_store IS NOT NULL AND manifest_bucket IS NOT NULL AND manifest_key IS NOT NULL
|
||||
AND manifest_sha256 IS NOT NULL AND manifest_size IS NOT NULL)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE result_inventory_members (
|
||||
attempt_id TEXT NOT NULL REFERENCES result_inventories(attempt_id) ON DELETE CASCADE,
|
||||
member_id TEXT COLLATE "C" NOT NULL,
|
||||
path TEXT COLLATE "C" NOT NULL,
|
||||
size BIGINT NOT NULL CHECK (size >= 0),
|
||||
object_store TEXT NOT NULL,
|
||||
object_bucket TEXT NOT NULL,
|
||||
object_key TEXT NOT NULL,
|
||||
object_version_id TEXT,
|
||||
object_sha256 TEXT NOT NULL,
|
||||
PRIMARY KEY (attempt_id, member_id),
|
||||
UNIQUE (attempt_id, path)
|
||||
);
|
||||
|
||||
CREATE INDEX result_inventory_members_order_idx
|
||||
ON result_inventory_members (attempt_id, path, member_id);
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
ALTER TABLE result_inventory_members
|
||||
DROP CONSTRAINT result_inventory_members_attempt_id_fkey,
|
||||
ADD CONSTRAINT result_inventory_members_attempt_id_fkey
|
||||
FOREIGN KEY (attempt_id)
|
||||
REFERENCES result_inventories (attempt_id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
ALTER TABLE result_inventories
|
||||
ADD COLUMN staging_origin_attempt_id TEXT,
|
||||
ADD COLUMN target_prefix TEXT,
|
||||
ADD CONSTRAINT result_inventories_staging_binding_check CHECK (
|
||||
(staging_origin_attempt_id IS NULL) = (target_prefix IS NULL)
|
||||
);
|
||||
|
||||
UPDATE result_inventories
|
||||
SET staging_origin_attempt_id = attempt_id,
|
||||
target_prefix = '';
|
||||
|
|
@ -2,12 +2,10 @@
|
|||
|
||||
mod error;
|
||||
mod inventory;
|
||||
mod migrate;
|
||||
mod types;
|
||||
|
||||
pub use error::ResultError;
|
||||
pub use inventory::ResultInventory;
|
||||
pub use migrate::{migrate, migrator};
|
||||
pub use types::{
|
||||
CommittedResult, MANIFEST_SCHEMA_VERSION, ManifestBuildMetrics, ManifestObjectIdentity,
|
||||
PageSize, PublicationInput, ResultMember, ResultMemberPage,
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
use remora_durable::DurableError;
|
||||
use sqlx::PgPool;
|
||||
|
||||
const MIGRATION_TABLE: &str = "_remora_result_migrations";
|
||||
|
||||
pub async fn migrate(pool: &PgPool) -> Result<(), DurableError> {
|
||||
let mut migrator = sqlx::migrate!("./migrations");
|
||||
migrator.dangerous_set_table_name(MIGRATION_TABLE);
|
||||
migrator.run(pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn migrator() -> sqlx::migrate::Migrator {
|
||||
let mut migrator = sqlx::migrate!("./migrations");
|
||||
migrator.dangerous_set_table_name(MIGRATION_TABLE);
|
||||
migrator
|
||||
}
|
||||
|
|
@ -2,11 +2,11 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use remora_domain::OpaqueId;
|
||||
use remora_durable::{PoolConfig, connect, migrate as durable_migrate};
|
||||
use remora_durable::{PoolConfig, connect};
|
||||
use remora_result::{
|
||||
MANIFEST_SCHEMA_VERSION, PageSize, ResultError, ResultInventory, ResultMember,
|
||||
migrate as result_migrate,
|
||||
};
|
||||
use remora_schema::migrate as migrate_schema;
|
||||
use remora_stream::TargetBody;
|
||||
use remora_target::{
|
||||
ContentSha256, CreateObjectRequest, ObjectIdentity, StoredObject, TargetStore,
|
||||
|
|
@ -46,8 +46,7 @@ async fn test_pool() -> Option<PgPool> {
|
|||
)
|
||||
.await
|
||||
.expect("connect postgres");
|
||||
durable_migrate(&pool).await.expect("durable migration");
|
||||
result_migrate(&pool).await.expect("result migration");
|
||||
migrate_schema(&pool).await.expect("schema migration");
|
||||
Some(pool)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue