Files
authentik/lifecycle/system_migrations/version_history_update.py
Jens L. a38239509b root: Better version bump (#14905)
Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
2025-08-12 13:50:12 +00:00

39 lines
1.1 KiB
Python

# flake8: noqa
from lifecycle.migrate import BaseMigration
from datetime import datetime
from authentik import authentik_version, authentik_build_hash
class Migration(BaseMigration):
def needs_migration(self) -> bool:
self.cur.execute(
"""
SELECT * FROM authentik_version_history
WHERE version = %s AND build = %s
ORDER BY "timestamp" DESC
LIMIT 1
""",
(authentik_version(), authentik_build_hash()),
)
return not bool(self.cur.rowcount)
def run(self):
self.cur.execute(
"""
INSERT INTO authentik_version_history ("timestamp", version, build)
VALUES (%s, %s, %s)
""",
(datetime.now(), authentik_version(), authentik_build_hash()),
)
self.cur.execute(
"""
DELETE FROM authentik_version_history WHERE id NOT IN (
SELECT id FROM authentik_version_history
ORDER BY "timestamp" DESC
LIMIT 1000
)
"""
)
self.con.commit()