Provision instance bank credentials automatically (Refs #146)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
|
||||
export function migrateBankCredentials(handle: Database.Database): void {
|
||||
handle.exec(`
|
||||
CREATE TABLE IF NOT EXISTS bank_credentials (
|
||||
instance_id TEXT PRIMARY KEY, server TEXT NOT NULL,
|
||||
token TEXT NOT NULL, token_hash TEXT NOT NULL UNIQUE, created_at TEXT NOT NULL
|
||||
);
|
||||
`);
|
||||
if (
|
||||
!(handle.pragma('table_info(bank_requests)') as { name: string }[]).some(
|
||||
(column) => column.name === 'instance_id'
|
||||
)
|
||||
) {
|
||||
handle.exec(`
|
||||
ALTER TABLE bank_requests ADD COLUMN instance_id TEXT;
|
||||
UPDATE bank_requests SET instance_id = (
|
||||
SELECT id FROM native_instances WHERE server = bank_requests.server AND retired_at IS NULL
|
||||
);
|
||||
`);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { migrateGameFileSchema } from '../game-files/schema.js';
|
||||
import { migrateLeaderboardReports } from './leaderboard-reports.js';
|
||||
import { migratePlayerScoreTotal } from './player-score-total.js';
|
||||
import { migrateBank } from './bank.js';
|
||||
import { migrateBankCredentials } from './bank-credentials.js';
|
||||
import type { Migration } from './migration-runner.js';
|
||||
|
||||
// Append only: never renumber entries or change an applied migration to add an
|
||||
@@ -111,7 +112,8 @@ export const migrations: readonly Migration[] = [
|
||||
name: 'cumulative player score per match',
|
||||
run: migratePlayerScoreTotal
|
||||
},
|
||||
{ version: 20, name: 'persistent player bank and transfer ledger', run: migrateBank }
|
||||
{ version: 20, name: 'persistent player bank and transfer ledger', run: migrateBank },
|
||||
{ version: 21, name: 'instance-owned bank credentials', run: migrateBankCredentials }
|
||||
];
|
||||
|
||||
export const databaseVersion = migrations.length;
|
||||
|
||||
Reference in New Issue
Block a user