From d2a33aacda3d3d727feff310794bff5635413214 Mon Sep 17 00:00:00 2001 From: Tal Borenstein Date: Sun, 24 Nov 2024 12:57:47 +0200 Subject: [PATCH] fix: fix --- keep/api/config.py | 5 +++ .../versions/2024-07-29-12-51_c91b348b94f2.py | 36 ++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/keep/api/config.py b/keep/api/config.py index 54387cf86..a27c4b66d 100644 --- a/keep/api/config.py +++ b/keep/api/config.py @@ -6,6 +6,7 @@ from keep.api.core.db_on_start import migrate_db, try_create_single_tenant from keep.api.core.dependencies import SINGLE_TENANT_UUID from keep.identitymanager.identitymanagerfactory import IdentityManagerTypes +from keep.providers.providers_factory import ProvidersFactory PORT = int(os.environ.get("PORT", 8080)) @@ -18,6 +19,10 @@ def on_starting(server=None): logger.info("Keep server starting") migrate_db() + # Load this early and use preloading + # https://www.joelsleppy.com/blog/gunicorn-application-preloading/ + # @tb: 👏 @Matvey-Kuk + ProvidersFactory.get_all_providers() # Create single tenant if it doesn't exist if AUTH_TYPE in [ diff --git a/keep/api/models/db/migrations/versions/2024-07-29-12-51_c91b348b94f2.py b/keep/api/models/db/migrations/versions/2024-07-29-12-51_c91b348b94f2.py index 181119744..8b1d38d99 100644 --- a/keep/api/models/db/migrations/versions/2024-07-29-12-51_c91b348b94f2.py +++ b/keep/api/models/db/migrations/versions/2024-07-29-12-51_c91b348b94f2.py @@ -23,41 +23,53 @@ # Direct table definition for Incident incident_table = sa.Table( - 'incident', + "incident", migration_metadata, - sa.Column('id', UUID(as_uuid=False), primary_key=True), - sa.Column('description', sa.String), - sa.Column('user_summary', sa.String), + sa.Column("id", UUID(as_uuid=False), primary_key=True), + sa.Column("description", sa.String), + sa.Column("user_summary", sa.String), ) def populate_db(session): # we need to populate the user_summary field with the description - session.execute(sa.update(incident_table).values(user_summary=incident_table.c.description)) + session.execute( + sa.update(incident_table).values(user_summary=incident_table.c.description) + ) session.commit() def depopulate_db(session): # we need to populate the description field with the user_summary - session.execute(sa.update(incident_table).values(description=incident_table.c.user_summary)) + session.execute( + sa.update(incident_table).values(description=incident_table.c.user_summary) + ) session.commit() def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - + session = Session(op.get_bind()) populate_db(session) - - op.drop_column("incident", "description") + + try: + op.drop_column("incident", "description") + except Exception as e: + print(f"Error dropping column description: {e}") # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.add_column("incident", sa.Column("description", sa.VARCHAR(), nullable=False, default="", server_default="")) - + op.add_column( + "incident", + sa.Column( + "description", sa.VARCHAR(), nullable=False, default="", server_default="" + ), + ) + session = Session(op.get_bind()) depopulate_db(session) - + # ### end Alembic commands ###