Skip to content

Fresh-database baseline schema + Data/Engine migration ownership split #143

Description

@DutchJaFO

Problem

  1. Every brand-new database replays all 6 migrations in sequence, even though several steps are now pointless for a fresh install (migration002 repairs pre-existing bad data; migration003's pre-seed INSERTs are WHERE EXISTS-guarded no-ops; migration004 creates a table that migration006 immediately renames moments later in the same startup). A fresh database should be created directly at the current schema in one step.

  2. Migration ownership is tangled. AuditMigrations.CreateAuditEntriesTable/RenameAuditEntriesToSystemAuditEntries (the SQL text) physically live in Quotinator.Data — but when they run is decided by Quotinator.Engine's QuotinatorMigrations.All, which interleaves them at arbitrary positions among its own domain migrations. Quotinator.Data should own and maintain the scripts for its own tables (System_AuditEntries, System_SchemaVersion, and any future System_* table), and DatabaseInitializer should always apply Data's own scripts first, before the consuming project's scripts — not interleaved, and not controlled by the consumer.

  3. Version numbering must stay stable per project. With Data and Engine sharing one counter, "version N" is only meaningful relative to however many Data-owned migrations currently exist — if Data adds a migration later, every one of Engine's migration numbers silently shifts. Separate version-tracking tables fix this: System_SchemaVersion tracks only Data's own migrations, a new System_ConsumerSchemaVersion tracks the consumer's own migrations independently.

Scope

  • Quotinator.Data's DatabaseInitializer gets its own fixed, internal DataOwnedMigrations list (not passed via constructor) and its own baseline fragment (DataBaselineSql) for System_AuditEntries — always applied/created first.
  • Two separate version tables: System_SchemaVersion (Data's own count) and System_ConsumerSchemaVersion (new — the consumer's own count).
  • A fresh (zero-table) database takes a one-step baseline path instead of replaying migration history; an existing database continues through the unchanged incremental path.
  • Drift-detection tests ensure the baseline can never silently go stale relative to the numbered migrations, on both the Data side and the Engine side.
  • Quotinator.Engine's migration constant names are renumbered to match their actual local position (no more "Migration005 is actually the 4th migration").

Full design: see the plan doc under docs/milestones/data-import-sources/.

Since nothing has shipped in a release yet, existing dev databases picking up this restructuring via a Reset (already a supported admin operation) is acceptable — no upgrade-in-place path is required.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions