This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2023-11-06 11:46:14 +00:00
|
|
|
# flake8: noqa
|
|
|
|
from lifecycle.migrate import BaseMigration
|
|
|
|
|
|
|
|
SQL_STATEMENT = """
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
ALTER TABLE authentik_tenants_tenant RENAME TO authentik_brands_brand;
|
|
|
|
UPDATE django_migrations SET app = replace(app, 'authentik_tenants', 'authentik_brands');
|
|
|
|
UPDATE django_content_type SET app_label = replace(app_label, 'authentik_tenants', 'authentik_brands');
|
|
|
|
COMMIT;
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(BaseMigration):
|
|
|
|
def needs_migration(self) -> bool:
|
|
|
|
self.cur.execute(
|
2023-12-05 16:42:28 +00:00
|
|
|
"select * from information_schema.tables where table_name = 'django_migrations';"
|
2023-11-06 11:46:14 +00:00
|
|
|
)
|
|
|
|
# No migration table, assume new installation
|
|
|
|
if not bool(self.cur.rowcount):
|
|
|
|
return False
|
|
|
|
self.cur.execute("select * from django_migrations where app = 'authentik_brands';")
|
|
|
|
return not bool(self.cur.rowcount)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.cur.execute(SQL_STATEMENT)
|