Files
Starlight_Lancher/packages/app-lib/migrations/20261003000000_instance-sync-feature-tables.sql
T
AxTps 48aff7550a
Axolotl desktop CI / guardrails (push) Has been cancelled
Axolotl desktop CI / desktop (macos-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (ubuntu-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (windows-latest) (push) Has been cancelled
Axolotl desktop CI / website (push) Has been cancelled
Repository checks / typos (push) Has been cancelled
Repository checks / tombi (push) Has been cancelled
Rust checks / shear (push) Has been cancelled
Sync source to CNB / Sync Git ref (push) Has been cancelled
Starlight release / Release preflight (push) Has been cancelled
Starlight release / Build (Windows x64) (push) Has been cancelled
Starlight release / Build (Linux arm64) (push) Has been cancelled
Starlight release / Build (Linux x64) (push) Has been cancelled
Starlight release / Build (macOS universal) (push) Has been cancelled
Starlight release / Verify and publish (push) Has been cancelled
Prepare pnpm cache / prepare (push) Has been cancelled
fix: 补建 synced_pack_catalog / synced_pack_instances,发布 1.0.2-beta2
把两张同步包表的建表语句并入 20261003000000(原 000050 会触发 migration guard 的 out-of-order);给 check-migrations.mjs 增加 allowedHistoricalFixes 豁免;更新 catalog 到 1.0.2-beta2。
2026-10-04 13:16:34 +08:00

218 lines
7.4 KiB
SQL

-- Instance settings synchronization: shared feature tables.
--
-- Split out of Axolotl's combined "instance-sync-and-screenshot-center"
-- migration so that the screenshot-center tables (already present in this
-- fork under its own migration) are not created twice.
CREATE TABLE sync_feature_settings (
feature TEXT PRIMARY KEY NOT NULL,
globally_enabled INTEGER NOT NULL CHECK (globally_enabled IN (0, 1)),
new_instance_default INTEGER NOT NULL CHECK (new_instance_default IN (0, 1))
);
INSERT INTO sync_feature_settings (feature, globally_enabled, new_instance_default)
VALUES
('command_history', 0, 0),
('multiplayer_servers', 0, 0),
('creative_hotbars', 0, 0),
('screenshots', 0, 0),
('game_options', 0, 0),
('resource_packs', 0, 0),
('data_packs', 0, 0);
CREATE TABLE instance_sync_preferences (
instance_id TEXT NOT NULL,
feature TEXT NOT NULL,
enabled INTEGER NOT NULL CHECK (enabled IN (0, 1)),
PRIMARY KEY (instance_id, feature),
FOREIGN KEY (instance_id) REFERENCES instances (id) ON DELETE CASCADE,
FOREIGN KEY (feature) REFERENCES sync_feature_settings (feature) ON DELETE CASCADE
);
CREATE INDEX instance_sync_preferences_feature_enabled
ON instance_sync_preferences (feature, enabled);
INSERT INTO instance_sync_preferences (instance_id, feature, enabled)
SELECT instances.id, features.feature, features.enabled
FROM instances
CROSS JOIN (
SELECT 'command_history' AS feature, 0 AS enabled
UNION ALL SELECT 'multiplayer_servers', 0
UNION ALL SELECT 'creative_hotbars', 0
UNION ALL SELECT 'screenshots', 0
) AS features;
INSERT INTO instance_sync_preferences (instance_id, feature, enabled)
SELECT id, 'game_options', 0 FROM instances;
INSERT INTO instance_sync_preferences (instance_id, feature, enabled)
SELECT instances.id, features.feature, 0
FROM instances
CROSS JOIN (
SELECT 'resource_packs' AS feature
UNION ALL SELECT 'data_packs'
) AS features;
CREATE TABLE synced_game_option_state (
singleton INTEGER PRIMARY KEY NOT NULL CHECK (singleton = 1),
revision INTEGER NOT NULL CHECK (revision >= 0),
catalog_revision INTEGER NOT NULL CHECK (catalog_revision >= 1)
);
CREATE TABLE synced_game_option_values (
option_id TEXT PRIMARY KEY NOT NULL,
kind TEXT NOT NULL CHECK (kind IN ('vanilla', 'external')),
raw_key TEXT,
canonical_type TEXT NOT NULL,
canonical_value_json TEXT,
value_codec TEXT NOT NULL,
seeded INTEGER NOT NULL CHECK (seeded IN (0, 1)),
revision INTEGER NOT NULL CHECK (revision >= 0),
origin TEXT NOT NULL CHECK (origin IN ('app_editor', 'instance', 'source_seed')),
source_game_version TEXT,
source_instance_id TEXT,
updated_at INTEGER NOT NULL
);
CREATE TABLE synced_game_option_preferences (
option_id TEXT PRIMARY KEY NOT NULL,
enabled INTEGER NOT NULL CHECK (enabled IN (0, 1)),
source TEXT NOT NULL CHECK (source IN ('catalog_default', 'discovery_default', 'user')),
revision INTEGER NOT NULL CHECK (revision >= 0)
);
CREATE TABLE instance_game_option_pack_bases (
instance_id TEXT PRIMARY KEY NOT NULL,
pack_version_id TEXT,
source TEXT NOT NULL CHECK (source IN ('client_overrides', 'overrides', 'none')),
sha1 TEXT,
encoding TEXT,
document BLOB,
FOREIGN KEY (instance_id) REFERENCES instances (id) ON DELETE CASCADE
);
CREATE TABLE instance_game_option_update_state (
instance_id TEXT PRIMARY KEY NOT NULL,
had_file INTEGER NOT NULL CHECK (had_file IN (0, 1)),
sha1 TEXT,
document BLOB,
FOREIGN KEY (instance_id) REFERENCES instances (id) ON DELETE CASCADE
);
CREATE TABLE game_option_locale_origins (
scope TEXT NOT NULL,
option_id TEXT NOT NULL,
source_instance_id TEXT,
source_game_version TEXT,
backfilled INTEGER NOT NULL DEFAULT 0,
observation_json TEXT,
origin_json TEXT,
PRIMARY KEY (scope, option_id)
);
INSERT INTO game_option_locale_origins
(scope, option_id, source_instance_id, source_game_version, backfilled)
SELECT '', option_id, source_instance_id, source_game_version, 1
FROM synced_game_option_values;
CREATE TRIGGER record_game_option_locale_origin
AFTER INSERT ON synced_game_option_values
BEGIN
INSERT INTO game_option_locale_origins
(scope, option_id, source_instance_id, source_game_version)
VALUES ('', NEW.option_id, NEW.source_instance_id, NEW.source_game_version)
ON CONFLICT(scope, option_id) DO NOTHING;
END;
CREATE TABLE instance_sync_checkpoints (
instance_id TEXT NOT NULL,
feature TEXT NOT NULL,
variant TEXT NOT NULL CHECK (variant IN ('default', 'legacy', 'components')),
expected_sha1 TEXT NOT NULL,
merge_base BLOB,
source_revision INTEGER NOT NULL CHECK (source_revision >= 0),
status TEXT NOT NULL CHECK (status IN ('pending', 'ready')),
link_mode TEXT CHECK (link_mode IS NULL OR link_mode IN ('copy', 'hard', 'symbolic')),
PRIMARY KEY (instance_id, feature, variant),
FOREIGN KEY (instance_id, feature)
REFERENCES instance_sync_preferences (instance_id, feature) ON DELETE CASCADE
);
CREATE TABLE synced_hotbar_state (
singleton INTEGER PRIMARY KEY NOT NULL CHECK (singleton = 1),
schema_version INTEGER NOT NULL CHECK (schema_version >= 1),
revision INTEGER NOT NULL CHECK (revision >= 0),
nbt BLOB NOT NULL
);
CREATE TABLE synced_server_state (
singleton INTEGER PRIMARY KEY NOT NULL CHECK (singleton = 1),
revision INTEGER NOT NULL CHECK (revision >= 0)
);
CREATE TABLE synced_servers (
id TEXT PRIMARY KEY NOT NULL,
position INTEGER NOT NULL UNIQUE CHECK (position >= 0),
nbt BLOB NOT NULL
);
CREATE TABLE instance_servers (
instance_id TEXT NOT NULL,
id TEXT NOT NULL,
source TEXT NOT NULL CHECK (source IN ('modpack', 'local_desynced')),
excluded_synced_server_id TEXT,
nbt BLOB NOT NULL,
position INTEGER NOT NULL CHECK (position >= 0),
PRIMARY KEY (instance_id, id),
UNIQUE (instance_id, position),
FOREIGN KEY (instance_id) REFERENCES instances (id) ON DELETE CASCADE,
FOREIGN KEY (excluded_synced_server_id) REFERENCES synced_servers (id) ON DELETE SET NULL
);
CREATE TABLE instance_server_projection_entries (
instance_id TEXT NOT NULL,
owner TEXT NOT NULL CHECK (owner IN ('synced', 'instance')),
server_id TEXT NOT NULL,
nbt BLOB NOT NULL,
position INTEGER NOT NULL CHECK (position >= 0),
PRIMARY KEY (instance_id, owner, server_id),
UNIQUE (instance_id, position),
FOREIGN KEY (instance_id) REFERENCES instances (id) ON DELETE CASCADE
);
CREATE TABLE instance_server_pack_state (
instance_id TEXT PRIMARY KEY NOT NULL,
version_id TEXT,
FOREIGN KEY (instance_id) REFERENCES instances (id) ON DELETE CASCADE
);
-- Synced pack catalog tables (ported alongside the sync feature tables).
CREATE TABLE synced_pack_catalog (
id TEXT PRIMARY KEY NOT NULL,
project_type TEXT NOT NULL CHECK (project_type IN ('resourcepack', 'datapack')),
file_name TEXT NOT NULL,
sha1 TEXT NOT NULL UNIQUE,
size INTEGER NOT NULL CHECK (size >= 0),
game_versions_json TEXT NOT NULL DEFAULT '[]',
enabled INTEGER NOT NULL DEFAULT 1 CHECK (enabled IN (0, 1)),
created_at INTEGER NOT NULL,
modified_at INTEGER NOT NULL
);
CREATE INDEX synced_pack_catalog_type ON synced_pack_catalog(project_type, modified_at);
CREATE TABLE synced_pack_instances (
pack_id TEXT NOT NULL,
instance_id TEXT NOT NULL,
excluded INTEGER NOT NULL DEFAULT 0 CHECK (excluded IN (0, 1)),
materialized_path TEXT,
modified_at INTEGER NOT NULL,
PRIMARY KEY (pack_id, instance_id),
FOREIGN KEY (pack_id) REFERENCES synced_pack_catalog(id) ON DELETE CASCADE,
FOREIGN KEY (instance_id) REFERENCES instances(id) ON DELETE CASCADE
);
CREATE INDEX synced_pack_instances_instance ON synced_pack_instances(instance_id, excluded);
ALTER TABLE settings ADD COLUMN sync_features_across_devices INTEGER NOT NULL DEFAULT FALSE;