Files
picpeak/backend/scripts/add-token-revocation-tables.js
T
paul f38014099e
Test and Lint / backend-test (push) Successful in 1m12s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m16s
Version and Release / version-bump (push) Successful in 35s
Version and Release / trigger-drone (push) Successful in 3s
fix: show hero image in thumbnail grid on hero gallery layout
2025-07-13 20:03:27 +02:00

71 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Add token revocation tables to existing database
*/
const { db } = require('../src/database/db');
async function addTokenRevocationTables() {
console.log('Adding token revocation tables...\n');
try {
// 1. Create revoked_tokens table
const hasRevokedTokens = await db.schema.hasTable('revoked_tokens');
if (!hasRevokedTokens) {
await db.schema.createTable('revoked_tokens', table => {
table.increments('id').primary();
table.string('token_id').notNullable().unique();
table.integer('user_id').nullable();
table.string('token_type', 20);
table.timestamp('revoked_at').defaultTo(db.fn.now());
table.timestamp('expires_at').notNullable();
table.string('reason', 100);
table.text('metadata');
// Indexes
table.index('token_id');
table.index('user_id');
table.index('expires_at');
});
console.log('✓ Created revoked_tokens table');
} else {
console.log('! revoked_tokens table already exists');
}
// 2. Create user_token_revocations table
const hasUserRevocations = await db.schema.hasTable('user_token_revocations');
if (!hasUserRevocations) {
await db.schema.createTable('user_token_revocations', table => {
table.integer('user_id').primary();
table.timestamp('revoked_at').notNullable();
table.string('reason', 100);
table.index('revoked_at');
});
console.log('✓ Created user_token_revocations table');
} else {
console.log('! user_token_revocations table already exists');
}
// 3. Verify tables
console.log('\nVerifying tables...');
const revokedTokensInfo = await db('revoked_tokens').columnInfo();
console.log('✓ revoked_tokens columns:', Object.keys(revokedTokensInfo).join(', '));
const userRevocationsInfo = await db('user_token_revocations').columnInfo();
console.log('✓ user_token_revocations columns:', Object.keys(userRevocationsInfo).join(', '));
console.log('\n✅ Token revocation tables ready!');
await db.destroy();
process.exit(0);
} catch (error) {
console.error('\n❌ Error adding token revocation tables:', error);
await db.destroy();
process.exit(1);
}
}
addTokenRevocationTables();