40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import pg from 'pg';
|
|
|
|
const { Pool } = pg;
|
|
|
|
const pool = new Pool({
|
|
connectionString: process.env.DATABASE_URL,
|
|
});
|
|
|
|
async function setupTable() {
|
|
try {
|
|
// Create the wp_dutchie_api_permissions table if it doesn't exist
|
|
await pool.query(`
|
|
CREATE TABLE IF NOT EXISTS wp_dutchie_api_permissions (
|
|
id SERIAL PRIMARY KEY,
|
|
user_name VARCHAR(255) NOT NULL,
|
|
api_key VARCHAR(255) NOT NULL UNIQUE,
|
|
allowed_ips TEXT,
|
|
allowed_domains TEXT,
|
|
is_active SMALLINT DEFAULT 1,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
last_used_at TIMESTAMP
|
|
)
|
|
`);
|
|
|
|
console.log('✅ Table wp_dutchie_api_permissions created or already exists');
|
|
|
|
// Check if table has any data
|
|
const result = await pool.query('SELECT COUNT(*) FROM wp_dutchie_api_permissions');
|
|
console.log(`✅ Table has ${result.rows[0].count} rows`);
|
|
|
|
await pool.end();
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('❌ Error setting up table:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
setupTable();
|