62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
|
|
import pg from 'pg';
|
||
|
|
import { config } from '../src/config/config.js';
|
||
|
|
|
||
|
|
const { Pool } = pg;
|
||
|
|
|
||
|
|
const verify = async () => {
|
||
|
|
const pool = new Pool({
|
||
|
|
host: config.db.host,
|
||
|
|
port: config.db.port,
|
||
|
|
user: config.db.user,
|
||
|
|
password: config.db.password,
|
||
|
|
database: config.db.database,
|
||
|
|
ssl: config.db.ssl,
|
||
|
|
});
|
||
|
|
|
||
|
|
try {
|
||
|
|
console.log('Verifying partitions for table onoffline_record...');
|
||
|
|
const client = await pool.connect();
|
||
|
|
|
||
|
|
// Check parent table
|
||
|
|
const parentRes = await client.query(`
|
||
|
|
SELECT to_regclass('onoffline.onoffline_record') as oid;
|
||
|
|
`);
|
||
|
|
if (!parentRes.rows[0].oid) {
|
||
|
|
console.error('Parent table onoffline.onoffline_record DOES NOT EXIST.');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
console.log('Parent table onoffline.onoffline_record exists.');
|
||
|
|
|
||
|
|
// Check partitions
|
||
|
|
const res = await client.query(`
|
||
|
|
SELECT
|
||
|
|
child.relname AS partition_name
|
||
|
|
FROM pg_inherits
|
||
|
|
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
|
||
|
|
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
|
||
|
|
JOIN pg_namespace ns ON parent.relnamespace = ns.oid
|
||
|
|
WHERE parent.relname = 'onoffline_record' AND ns.nspname = 'onoffline'
|
||
|
|
ORDER BY child.relname;
|
||
|
|
`);
|
||
|
|
|
||
|
|
console.log(`Found ${res.rowCount} partitions.`);
|
||
|
|
res.rows.forEach(row => {
|
||
|
|
console.log(`- ${row.partition_name}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
if (res.rowCount >= 30) {
|
||
|
|
console.log('SUCCESS: At least 30 partitions exist.');
|
||
|
|
} else {
|
||
|
|
console.warn(`WARNING: Expected 30+ partitions, found ${res.rowCount}.`);
|
||
|
|
}
|
||
|
|
|
||
|
|
client.release();
|
||
|
|
} catch (err) {
|
||
|
|
console.error('Verification failed:', err);
|
||
|
|
} finally {
|
||
|
|
await pool.end();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
verify();
|