diff --git a/Cargo.lock b/Cargo.lock index a1be350..d89ce14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -586,7 +586,7 @@ dependencies = [ [[package]] name = "coa-core" -version = "0.7.1" +version = "0.7.3" dependencies = [ "base64 0.22.1", "chrono", @@ -634,7 +634,7 @@ dependencies = [ [[package]] name = "coa-release" -version = "0.7.1" +version = "0.7.3" dependencies = [ "chrono", "coa-core", @@ -643,7 +643,7 @@ dependencies = [ [[package]] name = "coa-server-manager" -version = "0.7.1" +version = "0.7.3" dependencies = [ "coa-control-proto", "coa-core", diff --git a/Cargo.toml b/Cargo.toml index b649774..dc5b343 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["crates/coa-core", "crates/coa-release", "crates/coa-registry-proto", exclude = ["services/coa-registry", "services/coa-registry-e2e", "services/coa-coordinator", "services/coa-relay"] [workspace.package] -version = "0.7.1" +version = "0.7.3" edition = "2021" license = "AGPL-3.0-only" diff --git a/changelog.d/20261024-portable-schema-nine.md b/changelog.d/20261024-portable-schema-nine.md new file mode 100644 index 0000000..a641a7b --- /dev/null +++ b/changelog.d/20261024-portable-schema-nine.md @@ -0,0 +1,7 @@ +--- +area: manager +type: fixed +audience: players +title: Portable characters open again after using an experimental Manager +--- +Preserves saved characters and collections when opening a portable store upgraded by an experimental Manager. diff --git a/crates/coa-core/src/portable/migrations/009_multiruleset.sql b/crates/coa-core/src/portable/migrations/009_multiruleset.sql new file mode 100644 index 0000000..5f2681c --- /dev/null +++ b/crates/coa-core/src/portable/migrations/009_multiruleset.sql @@ -0,0 +1,23 @@ +-- Schema 9: Multi-ruleset partitioned collections and reborn ruleset support. +-- 1. Partition collection table by (profile_id, ruleset, kind) +CREATE TABLE collection_new ( + profile_id TEXT NOT NULL REFERENCES profile(profile_id), + ruleset TEXT NOT NULL CHECK (ruleset IN ('coa', 'wildcard', 'reborn')), + kind TEXT NOT NULL, + collection_revision INTEGER NOT NULL CHECK (collection_revision >= 1), + collection_hash BLOB NOT NULL CHECK (length(collection_hash) = 32), + format_version INTEGER NOT NULL, + item_count INTEGER NOT NULL, + updated_at TEXT NOT NULL, + payload BLOB NOT NULL, + PRIMARY KEY (profile_id, ruleset, kind) +) STRICT; + +INSERT INTO collection_new (profile_id, ruleset, kind, collection_revision, collection_hash, format_version, item_count, updated_at, payload) +SELECT profile_id, 'coa', kind, collection_revision, collection_hash, format_version, item_count, updated_at, payload +FROM collection; + +DROP TABLE collection; +ALTER TABLE collection_new RENAME TO collection; + +CREATE INDEX IF NOT EXISTS character_profile_ruleset ON character(profile_id, ruleset); diff --git a/crates/coa-core/src/portable/store.rs b/crates/coa-core/src/portable/store.rs index 0309da7..5202105 100644 --- a/crates/coa-core/src/portable/store.rs +++ b/crates/coa-core/src/portable/store.rs @@ -27,6 +27,7 @@ const MIGRATIONS: &[&str] = &[ include_str!("migrations/006_collections.sql"), include_str!("migrations/007_capabilities.sql"), include_str!("migrations/008_projection.sql"), + include_str!("migrations/009_multiruleset.sql"), ]; pub const DEFAULT_HISTORY_KEEP: u32 = 20; @@ -657,6 +658,7 @@ impl Store { } // ---- collections ---------------------------------------------------------------------------------------- + // These APIs exchange CoA collections only. Preserve other schema-9 partitions without reading or modifying them. /// `stored = stored U incoming`. Nothing is ever removed. When the union equals what is stored, no revision is /// created and the hash stays the same. @@ -701,9 +703,9 @@ impl Store { let payload = merged.encode(); let at = now(); tx.execute( - "INSERT INTO collection(profile_id, kind, collection_revision, collection_hash, format_version, item_count, updated_at, payload) - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8) - ON CONFLICT(profile_id, kind) DO UPDATE SET collection_revision = excluded.collection_revision, collection_hash = excluded.collection_hash, + "INSERT INTO collection(profile_id, ruleset, kind, collection_revision, collection_hash, format_version, item_count, updated_at, payload) + VALUES (?1, 'coa', ?2, ?3, ?4, ?5, ?6, ?7, ?8) + ON CONFLICT(profile_id, ruleset, kind) DO UPDATE SET collection_revision = excluded.collection_revision, collection_hash = excluded.collection_hash, format_version = excluded.format_version, item_count = excluded.item_count, updated_at = excluded.updated_at, payload = excluded.payload", params![profile.to_string(), kind, (revision + 1) as i64, hash.as_slice(), PORTABLE_COLLECTION_FORMAT_VERSION, merged.len() as i64, at, payload], )?; @@ -730,7 +732,7 @@ impl Store { let row = self .conn .query_row( - "SELECT collection_revision, collection_hash, item_count, updated_at FROM collection WHERE profile_id = ?1 AND kind = ?2", + "SELECT collection_revision, collection_hash, item_count, updated_at FROM collection WHERE profile_id = ?1 AND ruleset = 'coa' AND kind = ?2", params![profile.to_string(), kind], |r| Ok((r.get::<_, i64>(0)?, r.get::<_, Vec>(1)?, r.get::<_, i64>(2)?, r.get::<_, String>(3)?)), ) @@ -780,7 +782,7 @@ fn read_collection( ) -> Result> { let row = conn .query_row( - "SELECT collection_revision, collection_hash, item_count, updated_at, payload FROM collection WHERE profile_id = ?1 AND kind = ?2", + "SELECT collection_revision, collection_hash, item_count, updated_at, payload FROM collection WHERE profile_id = ?1 AND ruleset = 'coa' AND kind = ?2", params![profile.to_string(), kind], |r| Ok((r.get::<_, i64>(0)?, r.get::<_, Vec>(1)?, r.get::<_, i64>(2)?, r.get::<_, String>(3)?, r.get::<_, Vec>(4)?)), ) diff --git a/crates/coa-core/src/portable/store/tests.rs b/crates/coa-core/src/portable/store/tests.rs index 0170c11..4ff7890 100644 --- a/crates/coa-core/src/portable/store/tests.rs +++ b/crates/coa-core/src/portable/store/tests.rs @@ -7,6 +7,101 @@ fn fresh() -> (Store, ProfileId) { (store, profile) } +#[test] +fn schema_nine_upgrade_preserves_characters_and_isolates_collections() { + let dir = tempfile::tempdir().unwrap(); + let conn = Connection::open(Store::path_of(dir.path())).unwrap(); + for sql in &MIGRATIONS[..8] { + conn.execute_batch(sql).unwrap(); + } + conn.pragma_update(None, "application_id", APPLICATION_ID) + .unwrap(); + conn.pragma_update(None, "user_version", 8).unwrap(); + let mut old = Store { conn }; + let profile = old.default_profile().unwrap(); + let id = created(&mut old, profile); + old.bind_server(id, "realm-a", 42, 1, MappingState::Synced) + .unwrap(); + let before = old.load_current(id).unwrap(); + let set = IdSet::from_ids([10, 20]).unwrap(); + let kind = "coa:wardrobe"; + old.conn + .execute( + "INSERT INTO collection VALUES (?1, ?2, 7, ?3, ?4, 2, 'before', ?5)", + params![ + profile.to_string(), + kind, + set.hash(kind).as_slice(), + PORTABLE_COLLECTION_FORMAT_VERSION, + set.encode() + ], + ) + .unwrap(); + drop(old); + + let mut store = Store::open(dir.path()).unwrap(); + assert_eq!(store.schema_version().unwrap(), 9); + assert_eq!(store.load_current(id).unwrap(), before); + assert_eq!(store.server_mappings(id).unwrap()[0].local_guid, 42); + assert_eq!(store.collection(profile, kind).unwrap().unwrap().1, set); + assert_eq!( + store + .collection_info(profile, kind) + .unwrap() + .unwrap() + .revision, + 7 + ); + // An experimental Manager may already have populated another partition. + store.conn.execute( + "INSERT INTO collection SELECT profile_id, 'reborn', kind, collection_revision, collection_hash, format_version, item_count, updated_at, payload FROM collection WHERE ruleset = 'coa'", + [], + ).unwrap(); + store + .merge_collection(profile, kind, &IdSet::from_ids([30]).unwrap()) + .unwrap(); + assert_eq!( + store.collection(profile, kind).unwrap().unwrap().1, + IdSet::from_ids([10, 20, 30]).unwrap() + ); + let foreign: (i64, Vec) = store + .conn + .query_row( + "SELECT collection_revision, payload FROM collection WHERE ruleset = 'reborn'", + [], + |r| Ok((r.get(0)?, r.get(1)?)), + ) + .unwrap(); + assert_eq!(foreign, (7, set.encode())); + drop(store); + assert_eq!( + Store::open(dir.path()).unwrap().load_current(id).unwrap(), + before + ); +} + +#[test] +#[ignore = "Requires a disposable SQLite backup in COA_PORTABLE_SCHEMA9_FIXTURE"] +fn schema_nine_existing_store_and_runtime_smoke() { + let root = std::path::PathBuf::from( + std::env::var_os("COA_PORTABLE_SCHEMA9_FIXTURE").expect("fixture path"), + ); + for role in ["owner", "host"] { + let store = Store::open(&root.join(role)).unwrap(); + assert_eq!(store.schema_version().unwrap(), 9); + let records = store.list_characters_all().unwrap(); + assert!(!records.is_empty()); + for record in records { + store.load_current(record.character_id).unwrap(); + store.list_revisions(record.character_id).unwrap(); + } + } + let runtime = + crate::portable::service::PortableRuntime::start(&root, Box::new(Vec::new), None).unwrap(); + runtime.call(|_| ()).unwrap(); + runtime.shutdown(); +} + fn created(store: &mut Store, profile: ProfileId) -> CharacterId { store .create_character(profile, fixtures::geared_level_eighty(), "realm-a") diff --git a/package-lock.json b/package-lock.json index f8316e9..2202435 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coa-server-manager", - "version": "0.7.1", + "version": "0.7.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coa-server-manager", - "version": "0.7.1", + "version": "0.7.3", "dependencies": { "@tauri-apps/api": "^2.12.0", "@tauri-apps/plugin-dialog": "^2.8.0", @@ -1325,7 +1325,7 @@ } }, "node_modules/class-variance-authority": { - "version": "0.7.1", + "version": "0.7.2", "resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.7.1.tgz", "integrity": "sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg==", "license": "Apache-2.0", diff --git a/package.json b/package.json index 000d99c..af3a7a5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coa-server-manager", "private": true, - "version": "0.7.1", + "version": "0.7.3", "license": "AGPL-3.0-only", "type": "module", "scripts": { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f70dc4a..bcf95e2 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "CoA Server Manager", - "version": "0.7.1", + "version": "0.7.3", "identifier": "com.coa.servermanager", "build": { "beforeDevCommand": "npm run dev",