Skip to content

Atlas migrations#312

Open
bfabio wants to merge 4 commits into
italia:mainfrom
bfabio:atlas-migrations
Open

Atlas migrations#312
bfabio wants to merge 4 commits into
italia:mainfrom
bfabio:atlas-migrations

Conversation

@bfabio

@bfabio bfabio commented Mar 28, 2026

Copy link
Copy Markdown
Member

Fix #72.

cc @tensor5 because this touches the db and the deploy in a potentially risky way + review of the Helm chart

cc @mburri @caebr @ssandino this is a (nice) feature you might want to know about

@bfabio bfabio force-pushed the atlas-migrations branch from dd34780 to b08caef Compare March 28, 2026 16:47
@gitguardian

gitguardian Bot commented Mar 28, 2026

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@bfabio bfabio force-pushed the atlas-migrations branch from b08caef to 68cb7ca Compare March 28, 2026 16:59
@bfabio

bfabio commented Mar 28, 2026

Copy link
Copy Markdown
Member Author

@GitGuardian false positive

@ssandino ssandino mentioned this pull request Mar 28, 2026
bfabio added 4 commits April 28, 2026 08:22
GORM AutoMigrate applies schema changes implicitly at startup. There is
no way to review them before they hit the database and no way to roll
back.

Atlas versioned migrations are explicit SQL files that get committed and
reviewed like any other code change. The binary gains a `migrate`
subcommand that shells out to the Atlas CLI. DSNToURL() converts the
lib/pq key=value DSN to a postgres:// URL that Atlas expects.

AutoMigrate is kept only for SQLite (tests).

Fix italia#72.
Without CI checks a developer could change a model and forget to
generate the migration, or edit a migration file and break the checksum.

atlas-sync runs on PRs that touch models or migrations. It validates
the checksum file then checks that `atlas migrate diff` produces no
new files (no drift between models and committed migrations).

The test workflow now applies migrations with Atlas before running
tests, matching how production databases are set up.
Migrations need to run before the new code starts. A Helm pre-upgrade
hook Job runs `developers-italia-api migrate` before the Deployment is
touched. If it fails the upgrade is aborted and existing pods keep
serving.

backoffLimit 0 and activeDeadlineSeconds 300 ensure the Job either
succeeds or fails definitively within 5 minutes.

migrationBaseline lets operators skip the initial migration on databases
already set up by GORM AutoMigrate.
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.

Add some machinery to run migrations

1 participant