refactor: 移除运行时数据库初始化与分区维护
- 删除了服务启动阶段的数据库初始化逻辑,包括创建数据库、表和分区的相关代码。 - 移除了定时分区维护任务,确保服务职责更清晰。 - 更新了数据库分区策略,明确分区由外部脚本管理,服务不再自动创建缺失分区。 - 修改了相关文档,确保数据库结构与分区维护的责任转移到 `SQL_Script/` 目录下的外部脚本。 - 更新了需求和场景,确保符合新的设计规范。
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
CREATE SCHEMA IF NOT EXISTS onoffline;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS onoffline.onoffline_record (
|
||||
guid VARCHAR(32) NOT NULL,
|
||||
ts_ms BIGINT NOT NULL,
|
||||
write_ts_ms BIGINT NOT NULL,
|
||||
hotel_id SMALLINT NOT NULL,
|
||||
mac VARCHAR(21) NOT NULL,
|
||||
device_id VARCHAR(64) NOT NULL,
|
||||
room_id VARCHAR(64) NOT NULL,
|
||||
ip VARCHAR(21),
|
||||
current_status VARCHAR(255),
|
||||
launcher_version VARCHAR(255),
|
||||
reboot_reason VARCHAR(255),
|
||||
PRIMARY KEY (ts_ms, mac, device_id, room_id)
|
||||
) PARTITION BY RANGE (ts_ms);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_onoffline_ts_ms ON onoffline.onoffline_record (ts_ms);
|
||||
CREATE INDEX IF NOT EXISTS idx_onoffline_hotel_id ON onoffline.onoffline_record (hotel_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_onoffline_mac ON onoffline.onoffline_record (mac);
|
||||
CREATE INDEX IF NOT EXISTS idx_onoffline_device_id ON onoffline.onoffline_record (device_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_onoffline_room_id ON onoffline.onoffline_record (room_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_onoffline_current_status ON onoffline.onoffline_record (current_status);
|
||||
@@ -1,61 +0,0 @@
|
||||
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