fix(satp-hermes): migrate all DBs on startup#4378
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes SATP Hermes gateway startup failures caused by un-migrated databases by ensuring all configured repositories (local, remote, audit, oracle) are validated, passed through the CLI, and migrated during gateway startup.
Changes:
- CLI now validates and forwards
auditRepositoryandoracleLogRepositoryfrom the JSON config intoSATPGatewayConfig. - Gateway startup migration logic is extended from “local only” to include all configured repositories.
- Integration coverage is added to assert that DB tables are created after
startup()across the configured repositories.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway/gateway-init-startup.test.ts |
Adds an integration test to verify that DB migrations create the expected tables on startup. |
packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts |
Updates createDBRepository() to migrate more than just the local repository. |
packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway-cli.ts |
Validates and passes audit/oracle repository configs so they don’t fall back to unintended defaults. |
| @@ -1257,15 +1257,25 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { | |||
| this.logger.info( | |||
| `${fnTag}: Created migration source: ${JSON.stringify(migrationSource)}`, | |||
| ); | |||
There was a problem hiding this comment.
@mskrzypkows could you please address this comment as well?
There was a problem hiding this comment.
Yes, I have a fix for it. Testing it and will push.
There was a problem hiding this comment.
Based on the comment create better solution, calling repository.migrate for each repository from SATPGateway. This way we don't need additional connection to the DB.
There was a problem hiding this comment.
Thank you @mskrzypkows. Looking better! Can you please make sure that:
- errors initializing each DB or its migration are propagated up and handled
- can you please add the DB cleanup to the
onShutdownhook on the SATP gateway?
… on startup The CLI only forwarded localRepository and remoteRepository to SATPGatewayConfig, leaving auditRepository and oracleLogRepository to fall back to a random UUID-named SQLite file. Those databases were never migrated, causing the gateway to crash on the first write to the audit or oracle log tables. - Validate and pass auditRepository and oracleLogRepository from the config JSON in the CLI, consistent with how local/remote repos are already handled - Extend createDBRepository() to run migrate.latest() across all four configured repositories instead of localRepository only - Add integration test asserting that startup() creates the expected tables (logs, remote-logs, audit_entries, oracle_logs) in all four databases Assisted-by: anthropic:claude-sonnet-4.6 Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
createDBRepository() created temporary Knex instances from config to run migrate.latest(), then destroyed them. This caused three bugs: - For SQLite :memory: databases each Knex() call opens a separate in-memory DB, so migrations ran on a throwaway connection while the repository's own connection stayed unmigrated. - database.destroy() was not in a finally block, leaking connections when migrate.latest() threw. - auditRepository had no default fallback, unlike localRepository. Add migrate() to IRepository and implement it in all four concrete repositories so createDBRepository() migrates the actual runtime connections directly. Assisted-by: anthropic:claude-sonnet-4.6 Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
for the IPFSRemoteLogRepository Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
f9869c8 to
8e0461d
Compare
db_init_at_startup_pr Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
7dbfd6b to
684170f
Compare
| this.remoteRepository, | ||
| this.auditRepository, | ||
| this.oracleLogRepository, | ||
| ].filter((r): r is NonNullable<typeof r> => r != null); |
There was a problem hiding this comment.
Can you make the condition more explicit (on the filtering do the check if the database is non null and valid) instead of doing a non nullable type enforcement?
There was a problem hiding this comment.
I moved explicit check into the loop.
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
RafaelAPB
left a comment
There was a problem hiding this comment.
@mskrzypkows I mean what is on the suggestions rest LGTM
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
|
Combined suggestions into one commit and added warning log. |
|
@mskrzypkows thank you once again. I think we are good to go. Please 1) rebase with main; 2) squash your commits into one. |
The CLI only forwarded localRepository and remoteRepository to SATPGatewayConfig, leaving auditRepository and oracleLogRepository to fall back to a random UUID-named SQLite file. Those databases were never migrated, causing the gateway to crash on the first write to the audit or oracle log tables.