* lifecycle: improve reliability of system migrations better transaction handling which allows for re-trying migrations without needing manual intervention Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix lint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove explicit commit --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
		
			
				
	
	
		
			19 lines
		
	
	
		
			687 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			687 B
		
	
	
	
		
			Python
		
	
	
	
	
	
# flake8: noqa
 | 
						|
from lifecycle.migrate import BaseMigration
 | 
						|
 | 
						|
SQL_STATEMENT = """ALTER TABLE authentik_audit_event RENAME TO authentik_events_event;
 | 
						|
UPDATE django_migrations SET app = replace(app, 'authentik_audit', 'authentik_events');
 | 
						|
UPDATE django_content_type SET app_label = replace(app_label, 'authentik_audit', 'authentik_events');"""
 | 
						|
 | 
						|
 | 
						|
class Migration(BaseMigration):
 | 
						|
    def needs_migration(self) -> bool:
 | 
						|
        self.cur.execute(
 | 
						|
            "select * from information_schema.tables where table_name = 'authentik_audit_event';"
 | 
						|
        )
 | 
						|
        return bool(self.cur.rowcount)
 | 
						|
 | 
						|
    def run(self):
 | 
						|
        with self.con.transaction():
 | 
						|
            self.cur.execute(SQL_STATEMENT)
 |