feat: 初始化 bls-onoffline-backend 项目基础结构
添加 Kafka 消费者、数据库写入、Redis 集成等核心模块,实现设备上下线事件处理 - 创建项目基础目录结构与配置文件 - 实现 Kafka 消费逻辑与手动提交偏移量 - 添加 PostgreSQL 数据库连接与分区表管理 - 集成 Redis 用于错误队列和项目心跳 - 包含数据处理逻辑,区分重启与非重启数据 - 提供数据库初始化脚本与分区创建工具 - 添加单元测试与代码校验脚本
This commit is contained in:
61
bls-onoffline-backend/scripts/verify_partitions.js
Normal file
61
bls-onoffline-backend/scripts/verify_partitions.js
Normal file
@@ -0,0 +1,61 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user