feat(collections): 自动同步作品交付集验收状态
This commit is contained in:
@@ -26,7 +26,8 @@ const client = new pg.Client({ connectionString: databaseUrl, ssl: process.env.P
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
await client.query(fs.readFileSync(schemaPath, 'utf8'));
|
||||
const schema = fs.readFileSync(schemaPath, 'utf8');
|
||||
await client.query(schema);
|
||||
const existing = Number((await client.query('SELECT COUNT(*)::int AS count FROM operation_groups')).rows[0].count);
|
||||
if (existing && !replace) throw new Error('PostgreSQL 已有数据。确认覆盖时请显式添加 --replace');
|
||||
await client.query('BEGIN');
|
||||
@@ -45,6 +46,9 @@ try {
|
||||
}
|
||||
if (rows.length) await client.query(`SELECT setval(pg_get_serial_sequence('${table}', 'id'), (SELECT MAX(id) FROM "${table}"), true)`);
|
||||
}
|
||||
const collectionStatusRepair = schema.match(/-- COLLECTION_STATUS_REPAIR_START([\s\S]+?)-- COLLECTION_STATUS_REPAIR_END/)?.[1];
|
||||
if (!collectionStatusRepair) throw new Error('PostgreSQL schema 缺少作品交付集状态修复脚本');
|
||||
await client.query(collectionStatusRepair);
|
||||
await client.query('COMMIT');
|
||||
process.stdout.write(`迁移完成:${tables.length} 张表已从 ${sqlitePath} 导入 PostgreSQL\n`);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user