Add login security retention and legal terms
This commit is contained in:
@@ -58,6 +58,28 @@ if (typeof loginEventsDefinition?.sql === 'string' && !loginEventsDefinition.sql
|
||||
await database.exec('DROP TABLE login_events_legacy');
|
||||
await database.exec('CREATE INDEX IF NOT EXISTS login_events_user_created_idx ON login_events(user_id, created_at DESC)');
|
||||
}
|
||||
const loginEventColumns = await (await database.prepare("PRAGMA table_info('login_events')")).all();
|
||||
for (const [name, definition] of [
|
||||
['ip_address', 'TEXT'],
|
||||
['user_agent', 'TEXT'],
|
||||
['client_name', 'TEXT'],
|
||||
['operating_system', 'TEXT'],
|
||||
['device_type', 'TEXT'],
|
||||
['location_country', 'TEXT'],
|
||||
['location_region', 'TEXT'],
|
||||
['location_city', 'TEXT'],
|
||||
['failure_reason', 'TEXT'],
|
||||
['risk_flags', 'TEXT'],
|
||||
['credential_id', 'TEXT'],
|
||||
['session_id', 'TEXT REFERENCES sessions(id) ON DELETE SET NULL'],
|
||||
['session_ended_at', 'TEXT'],
|
||||
['session_end_reason', 'TEXT'],
|
||||
['sensitive_purged_at', 'TEXT']
|
||||
]) {
|
||||
if (!loginEventColumns.some((column) => column.name === name)) {
|
||||
await database.exec(`ALTER TABLE login_events ADD COLUMN ${name} ${definition}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Applied ${statements.length} schema statements to ${databasePath}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user