Skip to content

feat: Verify migration rollback contracts against current schema - #1198

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Devadakene:fix/migration-rollback-contracts
Aug 29, 2026
Merged

feat: Verify migration rollback contracts against current schema#1198
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Devadakene:fix/migration-rollback-contracts

Conversation

@Devadakene

Copy link
Copy Markdown
Contributor

Closes #1192

Description

Closes #

This PR implements verification of migration rollback contracts and ensures deterministic checking of boundaries without destructive transformation. It updates the initial application startup logic to validate the state of the schema deterministically.

Key Changes

  • Migration Application (src/migrate.ts):

    • Extracted the main migration logic into a reusable applyMigrations function.
    • Added a new validateSchemaState function that ensures the app database does not have unapplied schema drifts or unexecuted migrations relative to the .sql files.
  • Initialization Logic (src/db/index.ts):

    • Replaced the hardcoded, single-migration script approach with a deterministic check utilizing applyMigrations() and validateSchemaState().
    • On application startup (initializeDb), it will now deterministically apply or validate the expected layout, fulfilling the fresh-install and upgrade-paths criteria.
  • Automated Rolling Verification (src/migrations.test.ts):

    • Implemented a complete verification suite (Migration Rollback Contracts) using an in-memory db.
    • Runs every discovered migration UP, then runs DOWN (if the rollback script is present), and verifies that the sqlite_master metadata reverts identically to the pre-migration state.
    • Finally, replays the UP migration to proceed up the sequence, ensuring ordering, compatibility, and rollback boundaries are correct and strictly valid for the codebase.

Verification Checklist

  • Implementation matches issue description
  • All tests created and passing
  • Fresh-install and upgrade paths validate expected schema/state before application work proceeds
  • Ordering, compatibility, rollback boundaries, and destructive changes are checked deterministically
  • Existing deployed data remains readable without implicit destructive transformation

Closes #xyz (Implement Verify migration rollback contracts)

- Extracted applyMigrations and validateSchemaState in src/migrate.ts
- Updated src/db/index.ts to validate expected schema/state before app work proceeds
- Added deterministic test suite in src/migrations.test.ts to verify rollback boundaries and ensure destructive changes are checked
@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Devadakene Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit 4a16045 into CalloraOrg:main Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Quality-2][High] Verify migration rollback contracts against current schema

2 participants