db: enforce strict version upgrade path
Add a version check that runs before database migrations to ensure users do not skip minor versions or downgrade. This protects database migrations and allows future cleanup of old migration code. Rules enforced: - Same minor version: always allowed (patch changes either way) - Single minor upgrade (e.g. 0.27 -> 0.28): allowed - Multi-minor upgrade (e.g. 0.25 -> 0.28): blocked with guidance - Any minor downgrade: blocked - Major version change: blocked - Dev builds: warn but allow, preserve stored version The version is stored in a purpose-built database_versions table after migrations succeed. The table is created with raw SQL before gormigrate runs to avoid circular dependencies. Updates #3058
This commit is contained in:
parent
9c3a3c5837
commit
82958835ce
4 changed files with 599 additions and 0 deletions
|
|
@ -104,3 +104,9 @@ CREATE TABLE policies(
|
|||
deleted_at datetime
|
||||
);
|
||||
CREATE INDEX idx_policies_deleted_at ON policies(deleted_at);
|
||||
|
||||
CREATE TABLE database_versions(
|
||||
id integer PRIMARY KEY,
|
||||
version text NOT NULL,
|
||||
updated_at datetime
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue