Add ISAC Skill Chips data module
This commit is contained in:
@@ -93,6 +93,58 @@ for (const [name, definition] of [
|
||||
await database.exec("UPDATE data_change_proposals SET draft_entity_id=id WHERE draft_entity_id IS NULL AND entity_id IS NULL");
|
||||
await database.exec('CREATE UNIQUE INDEX IF NOT EXISTS data_change_proposals_draft_entity_idx ON data_change_proposals(draft_entity_id) WHERE draft_entity_id IS NOT NULL');
|
||||
|
||||
const proposalDefinition = await (await database.prepare(
|
||||
"SELECT sql FROM sqlite_master WHERE type='table' AND name='data_change_proposals'"
|
||||
)).get();
|
||||
if (typeof proposalDefinition?.sql === 'string' && !proposalDefinition.sql.includes("'attributes'")) {
|
||||
console.log('Renaming the moderated Stats module to Attributes.');
|
||||
await database.exec('PRAGMA foreign_keys=OFF');
|
||||
await database.exec(`CREATE TABLE data_change_proposals_expanded (
|
||||
id TEXT PRIMARY KEY,
|
||||
module TEXT NOT NULL CHECK(module IN ('attributes','talents','brands','gear','weapons','protocols','skillchips')),
|
||||
action TEXT NOT NULL,
|
||||
entity_id TEXT,
|
||||
draft_entity_id TEXT,
|
||||
applied_entity_id TEXT,
|
||||
summary TEXT NOT NULL,
|
||||
payload_json TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','approved','rejected','failed')),
|
||||
proposed_by TEXT NOT NULL REFERENCES users(id),
|
||||
reviewed_by TEXT REFERENCES users(id),
|
||||
review_note TEXT,
|
||||
created_at TEXT NOT NULL,
|
||||
reviewed_at TEXT,
|
||||
applied_at TEXT
|
||||
)`);
|
||||
await database.exec(`INSERT INTO data_change_proposals_expanded
|
||||
SELECT id,CASE module WHEN 'stats' THEN 'attributes' ELSE module END,action,entity_id,draft_entity_id,applied_entity_id,summary,payload_json,status,proposed_by,reviewed_by,review_note,created_at,reviewed_at,applied_at
|
||||
FROM data_change_proposals`);
|
||||
await database.exec('DROP TABLE data_change_proposals');
|
||||
await database.exec('ALTER TABLE data_change_proposals_expanded RENAME TO data_change_proposals');
|
||||
await database.exec('PRAGMA foreign_keys=ON');
|
||||
}
|
||||
await database.exec('CREATE INDEX IF NOT EXISTS data_change_proposals_status_created_idx ON data_change_proposals(status,created_at DESC)');
|
||||
await database.exec('CREATE INDEX IF NOT EXISTS data_change_proposals_module_status_idx ON data_change_proposals(module,status)');
|
||||
await database.exec('CREATE UNIQUE INDEX IF NOT EXISTS data_change_proposals_draft_entity_idx ON data_change_proposals(draft_entity_id) WHERE draft_entity_id IS NOT NULL');
|
||||
|
||||
const iconDefinition = await (await database.prepare(
|
||||
"SELECT sql FROM sqlite_master WHERE type='table' AND name='game_data_icons'"
|
||||
)).get();
|
||||
if (typeof iconDefinition?.sql === 'string' && !iconDefinition.sql.includes("'skill_chip'")) {
|
||||
console.log('Adding Skill Chip icon storage support.');
|
||||
await database.exec(`CREATE TABLE game_data_icons_expanded (
|
||||
entity_type TEXT NOT NULL CHECK(entity_type IN ('talent', 'brand_set', 'os_protocol', 'skill_chip')),
|
||||
entity_id TEXT NOT NULL,
|
||||
storage_key TEXT NOT NULL UNIQUE,
|
||||
byte_size INTEGER NOT NULL CHECK(byte_size > 0),
|
||||
updated_at TEXT NOT NULL,
|
||||
PRIMARY KEY(entity_type, entity_id)
|
||||
)`);
|
||||
await database.exec(`INSERT INTO game_data_icons_expanded SELECT entity_type,entity_id,storage_key,byte_size,updated_at FROM game_data_icons`);
|
||||
await database.exec('DROP TABLE game_data_icons');
|
||||
await database.exec('ALTER TABLE game_data_icons_expanded RENAME TO game_data_icons');
|
||||
}
|
||||
|
||||
console.log(`Applied ${statements.length} schema statements to ${databasePath}`);
|
||||
|
||||
if (!databaseAlreadyExisted) {
|
||||
|
||||
Reference in New Issue
Block a user