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,78 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { rootDir } = require('./db-env');
|
||||
|
||||
const DEFAULT_CONFIG_PATH = path.join(rootDir, 'infra', 'deploy', 'harmonize.config.json');
|
||||
const FALLBACK_CONFIG_PATH = path.join(rootDir, 'infra', 'deploy', 'devtoprod.config.json');
|
||||
|
||||
function loadHarmonizeConfig(configPath) {
|
||||
const resolved = configPath
|
||||
? path.resolve(configPath)
|
||||
: (fs.existsSync(DEFAULT_CONFIG_PATH) ? DEFAULT_CONFIG_PATH : FALLBACK_CONFIG_PATH);
|
||||
|
||||
if (!fs.existsSync(resolved)) {
|
||||
return {
|
||||
configPath: resolved,
|
||||
dryRun: false,
|
||||
prefer: null,
|
||||
schemaChanged: false,
|
||||
steps: {
|
||||
backupDev: true,
|
||||
backupProd: true,
|
||||
schema: false,
|
||||
db: true,
|
||||
images: true,
|
||||
verify: false,
|
||||
},
|
||||
smb: {
|
||||
host: '192.168.10.122',
|
||||
share: 'Gallery',
|
||||
user: '',
|
||||
password: '',
|
||||
},
|
||||
paths: {
|
||||
prodImages: '\\\\192.168.10.122\\Gallery\\data\\images',
|
||||
},
|
||||
verify: {},
|
||||
};
|
||||
}
|
||||
|
||||
const raw = JSON.parse(fs.readFileSync(resolved, 'utf8'));
|
||||
const harmonize = raw.harmonize || raw;
|
||||
return {
|
||||
configPath: resolved,
|
||||
dryRun: Boolean(harmonize.dryRun),
|
||||
prefer: harmonize.prefer || null,
|
||||
schemaChanged: Boolean(harmonize.schemaChanged ?? raw.schemaChanged),
|
||||
steps: {
|
||||
backupDev: harmonize.steps?.backupDev ?? true,
|
||||
backupProd: harmonize.steps?.backupProd ?? true,
|
||||
schema: harmonize.steps?.schema ?? Boolean(harmonize.schemaChanged ?? raw.schemaChanged),
|
||||
db: harmonize.steps?.db ?? true,
|
||||
images: harmonize.steps?.images ?? true,
|
||||
verify: harmonize.steps?.verify ?? false,
|
||||
},
|
||||
smb: {
|
||||
host: harmonize.smb?.host ?? raw.smb?.host ?? '192.168.10.122',
|
||||
share: harmonize.smb?.share ?? raw.smb?.share ?? 'Gallery',
|
||||
user: harmonize.smb?.user ?? raw.smb?.user ?? '',
|
||||
password: harmonize.smb?.password ?? raw.smb?.password ?? '',
|
||||
},
|
||||
paths: {
|
||||
prodImages: harmonize.paths?.prodImages
|
||||
?? `\\\\${harmonize.smb?.host ?? raw.smb?.host ?? '192.168.10.122'}\\${harmonize.smb?.share ?? raw.smb?.share ?? 'Gallery'}\\data\\images`,
|
||||
},
|
||||
verify: harmonize.verify ?? raw.verify ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
function prodImagesPath(config) {
|
||||
return config.paths?.prodImages
|
||||
|| `\\\\${config.smb.host}\\${config.smb.share}\\data\\images`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
loadHarmonizeConfig,
|
||||
prodImagesPath,
|
||||
};
|
||||
Reference in New Issue
Block a user