Skip to content

SaaS Flyway: timestamp-based migration naming to end version clashes#6871

Open
ConnorYoh wants to merge 1 commit into
mainfrom
claude/priceless-saha-a7b0bf
Open

SaaS Flyway: timestamp-based migration naming to end version clashes#6871
ConnorYoh wants to merge 1 commit into
mainfrom
claude/priceless-saha-a7b0bf

Conversation

@ConnorYoh

Copy link
Copy Markdown
Member

@

Problem

SaaS Flyway migrations (app/saas/src/main/resources/db/migration/saas/) use a shared integer version counter — currently up to V26. Whenever two branches are in flight, each grabs "the next number" (both pick V27), so they collide the moment both merge: a duplicate version or a checksum failure that breaks CI. The gaps in the current sequence (no V7, V10, V18, …) are the fingerprint of this churn.

Change (stage 1 of 2)

Adopt UTC-timestamp naming for new migrations:

V<YYYYMMDDHHMMSS>__short_description.sql      e.g. V20260703143012__resource_grants.sql
  • Timestamps are per-author and monotonic, so independent branches never pick the same version (a clash needs two authors in the same second).
  • A 14-digit timestamp sorts numerically after the legacy integers (26 < 20260703143012), so both schemes coexist and apply in order.
  • Enables spring.flyway.out-of-order=true — under timestamps, merge order no longer matches version order, so without it Flyway would reject a just-merged migration whose timestamp predates one already applied. Safe here because the saas migrations are additive and idempotent (IF NOT EXISTS).

Deliberately not renaming V2..V26

They are already applied in deployed/dev environments and tracked by version in flyway_schema_history; renaming would make Flyway re-run them or fail the checksum check. They stay as integers; only new migrations use timestamps.

Files

  • application-saas.properties — add spring.flyway.out-of-order=true (+ rationale comment)
  • db/migration/saas/README.md — document the convention

Follow-up (stage 2, later)

Missed-migration / schema-drift detection in CI (the pg_dump-diff-against-Supabase idea) is intentionally out of scope here and will be a separate PR.
@

@
SaaS Flyway: switch new migrations to timestamp-based naming

The shared integer version counter (V25, V26, ...) collides whenever two
branches are in flight: each grabs "the next number" and they clash on merge,
breaking CI. Adopt UTC-timestamp naming (VYYYYMMDDHHMMSS__desc.sql) for new
migrations so parallel branches never pick the same version.

Enable spring.flyway.out-of-order so a just-merged migration whose timestamp
predates one already applied is still run (merge order != version order under
timestamps). Safe because the saas migrations are additive and idempotent.

Existing V2..V26 files are intentionally left as-is: they are already applied
and tracked by version in flyway_schema_history, so renaming would re-run them
or fail checksums. Timestamps sort after the legacy integers, so both coexist.

Convention documented in db/migration/saas/README.md.
@
@dosubot dosubot Bot added size:M This PR changes 30-99 lines ignoring generated files. enhancement New feature or request labels Jul 3, 2026
@stirlingbot stirlingbot Bot added Documentation Improvements or additions to documentation and removed enhancement New feature or request labels Jul 3, 2026
@stirlingbot

stirlingbot Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚀 V2 Auto-Deployment Complete!

Your V2 PR with embedded architecture has been deployed!

🔗 Direct Test URL (non-SSL) http://54.175.155.236:6871

🔐 Secure HTTPS URL: https://6871.ssl.stirlingpdf.cloud

This deployment will be automatically cleaned up when the PR is closed.

🔄 Auto-deployed for approved V2 contributors.

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

Labels

Documentation Improvements or additions to documentation size:M This PR changes 30-99 lines ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant