You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -218,8 +243,53 @@ export class SqliteCredentialVault implements CredentialVault {
218
243
219
244
privatemigrate(): void{
220
245
this.db.exec(`CREATE TABLE IF NOT EXISTS credentials (credential_id TEXT PRIMARY KEY, provider TEXT NOT NULL, type TEXT NOT NULL CHECK(type IN ('api_key','oauth')), identity_key TEXT NOT NULL, material TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, disabled_at TEXT, disabled_cause TEXT, UNIQUE(provider, type, identity_key));
221
-
CREATE TABLE IF NOT EXISTS leases (lease_id TEXT PRIMARY KEY, credential_id TEXT NOT NULL REFERENCES credentials(credential_id), authentication_hash TEXT NOT NULL, selector TEXT NOT NULL, pool TEXT NOT NULL, session_id TEXT, consumed_at TEXT, outcome TEXT);
246
+
CREATE TABLE IF NOT EXISTS leases (lease_id TEXT PRIMARY KEY, credential_id TEXT NOT NULL REFERENCES credentials(credential_id), authentication_hash TEXT NOT NULL, selector TEXT NOT NULL, pool TEXT NOT NULL, session_id TEXT, issued_at TEXT NOT NULL DEFAULT '', expires_at TEXT NOT NULL DEFAULT '', consumed_at TEXT, outcome TEXT);
222
247
CREATE TABLE IF NOT EXISTS state (key TEXT PRIMARY KEY, value TEXT NOT NULL);`);
248
+
this.ensureLeaseColumns();
249
+
}
250
+
251
+
privateensureLeaseColumns(): void{
252
+
constcolumns=this.db
253
+
.prepare("PRAGMA table_info(leases)")
254
+
.all()
255
+
.map((row)=>(rowas{name?: unknown}).name)
256
+
.filter((name): name is string=>typeofname==="string");
257
+
if(!columns.includes("issued_at"))this.db.exec("ALTER TABLE leases ADD COLUMN issued_at TEXT NOT NULL DEFAULT ''");
258
+
if(!columns.includes("expires_at"))this.db.exec("ALTER TABLE leases ADD COLUMN expires_at TEXT NOT NULL DEFAULT ''");
259
+
this.db.exec("CREATE INDEX IF NOT EXISTS leases_expires_at_idx ON leases(expires_at)");
260
+
}
261
+
262
+
/** Drop expired unconsumed leases and old consumed leases past retention. */
0 commit comments