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>
This commit is contained in:
		| @ -1,7 +1,7 @@ | ||||
| # flake8: noqa | ||||
| from lifecycle.migrate import BaseMigration | ||||
|  | ||||
| SQL_STATEMENT = """BEGIN TRANSACTION; | ||||
| SQL_STATEMENT = """ | ||||
| ALTER TABLE authentik_stages_otp_static_otpstaticstage RENAME TO authentik_stages_authenticator_static_otpstaticstage; | ||||
| UPDATE django_migrations SET app = replace(app, 'authentik_stages_otp_static', 'authentik_stages_authenticator_static'); | ||||
| UPDATE django_content_type SET app_label = replace(app_label, 'authentik_stages_otp_static', 'authentik_stages_authenticator_static'); | ||||
| @ -13,8 +13,7 @@ UPDATE django_content_type SET app_label = replace(app_label, 'authentik_stages_ | ||||
| ALTER TABLE authentik_stages_otp_validate_otpvalidatestage RENAME TO authentik_stages_authenticator_validate_otpvalidatestage; | ||||
| UPDATE django_migrations SET app = replace(app, 'authentik_stages_otp_validate', 'authentik_stages_authenticator_validate'); | ||||
| UPDATE django_content_type SET app_label = replace(app_label, 'authentik_stages_otp_validate', 'authentik_stages_authenticator_validate'); | ||||
|  | ||||
| END TRANSACTION;""" | ||||
| """ | ||||
|  | ||||
|  | ||||
| class Migration(BaseMigration): | ||||
| @ -26,5 +25,5 @@ class Migration(BaseMigration): | ||||
|         return bool(self.cur.rowcount) | ||||
|  | ||||
|     def run(self): | ||||
|         self.cur.execute(SQL_STATEMENT) | ||||
|         self.con.commit() | ||||
|         with self.con.transaction(): | ||||
|             self.cur.execute(SQL_STATEMENT) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer