mirror of
https://github.com/juanfont/headscale.git
synced 2026-04-19 07:19:57 +02:00
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:
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user