Skip to content

Commit

Permalink
Add forceCommitUpdates after manual cli import
Browse files Browse the repository at this point in the history
  • Loading branch information
u12206050 committed Feb 27, 2024
1 parent fb14587 commit aef1d29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
init('app.before', async () => {
try {
const meta = await ExportHelper.getExportMeta();
if (!meta) return logger.info('Nothing exported yet it seems'); // No export meta, nothing to do
if (!meta) return logger.info('Nothing exported yet it seems');
if (!(await updateManager.lockForUpdates(meta.hash, meta.ts))) return; // Schema is locked / no change, nothing to do

logger.info(`Updating schema and data with hash: ${meta.hash}`);
Expand Down Expand Up @@ -129,9 +129,13 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
.description('Import only the schema file')
.action(async () => {
logger.info('Importing schema...');
const meta = await ExportHelper.getExportMeta();
if (!meta) return logger.info('Nothing exported yet it seems');

const exportSchema = new SchemaExporter(getSchemaService, logger);
await exportSchema.load();

await updateManager.forceCommitUpdates(meta.hash, meta.ts);
logger.info('Done!');
process.exit(0);
});
Expand Down
11 changes: 11 additions & 0 deletions src/updateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export class UpdateManager {
return true;
}

public async forceCommitUpdates(newHash: string, isoTS: string) {
await this.db(this.tableName).where('id', this.rowId).update({
mv_hash: newHash,
mv_ts: isoTS,
mv_locked: false,
});

this._locked = false;
return true;
}

public async releaseLock() {
if (!this._locked) return false;

Expand Down

0 comments on commit aef1d29

Please sign in to comment.