Add dev-prod harmonize tool for bidirectional catalog and image sync.
Schema migrates dev to prod only; catalog rows merge by updated_at and images by mtime with union merge and conflict reporting. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
81ebad2120
commit
f247b418d8
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Migrate prod schema from dev migrations (schema dev → prod only).
|
||||
*
|
||||
* Usage: npm run harmonize:schema
|
||||
*/
|
||||
const { spawnSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const { rootDir, loadProdPgConfig, confirmProdAction } = require('./db-env');
|
||||
const { printCliResult } = require('./lib/cli-result');
|
||||
|
||||
async function main() {
|
||||
if (process.env.CONFIRM_PROD !== '1') {
|
||||
await confirmProdAction('Apply dev migrations to gallery_prod schema?');
|
||||
}
|
||||
|
||||
const prodConfig = loadProdPgConfig();
|
||||
const env = {
|
||||
...process.env,
|
||||
DB_HOST: prodConfig.host,
|
||||
DB_PORT: String(prodConfig.port),
|
||||
DB_USER: prodConfig.user,
|
||||
DB_PASSWORD: prodConfig.password,
|
||||
DB_NAME: prodConfig.database,
|
||||
};
|
||||
|
||||
const result = spawnSync(process.execPath, [path.join(rootDir, 'server', 'migrate.js')], {
|
||||
cwd: rootDir,
|
||||
env,
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
if (result.status !== 0) {
|
||||
printCliResult({
|
||||
script: 'harmonize-schema',
|
||||
ok: false,
|
||||
summary: 'Prod schema migration failed.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
printCliResult({
|
||||
script: 'harmonize-schema',
|
||||
ok: true,
|
||||
summary: 'Prod schema migrated from dev migration files (gallery_prod).',
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
printCliResult({
|
||||
script: 'harmonize-schema',
|
||||
ok: false,
|
||||
summary: err.message,
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user