From 815df2144e998eefe6971213b26b0c2c8c31306d Mon Sep 17 00:00:00 2001 From: Rajesh Jonnalagadda Date: Sun, 13 Oct 2024 14:10:13 +0530 Subject: [PATCH] refactor: merged the runbook patches into signle one and remov the previous patches related to runbooks --- .../versions/2024-10-09-08-55_de84655df741.py | 69 ------------------- ...63.py => 2024-10-13-08-33_8af72e1df141.py} | 47 +++++++++++-- 2 files changed, 43 insertions(+), 73 deletions(-) delete mode 100644 keep/api/models/db/migrations/versions/2024-10-09-08-55_de84655df741.py rename keep/api/models/db/migrations/versions/{2024-10-08-22-23_0796be640663.py => 2024-10-13-08-33_8af72e1df141.py} (54%) diff --git a/keep/api/models/db/migrations/versions/2024-10-09-08-55_de84655df741.py b/keep/api/models/db/migrations/versions/2024-10-09-08-55_de84655df741.py deleted file mode 100644 index 63a13b8c9..000000000 --- a/keep/api/models/db/migrations/versions/2024-10-09-08-55_de84655df741.py +++ /dev/null @@ -1,69 +0,0 @@ -"""Add incidents link to runbook and timestamp - -Revision ID: de84655df741 -Revises: 0796be640663 -Create Date: 2024-10-09 08:55:40.216359 - -""" - -import sqlalchemy as sa -import sqlalchemy_utils -import sqlmodel -from alembic import op - -# revision identifiers, used by Alembic. -revision = "de84655df741" -down_revision = "0796be640663" -branch_labels = None -depends_on = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "runbooktoincident", - sa.Column( - "incident_id", - sqlalchemy_utils.types.uuid.UUIDType(binary=False), - nullable=False, - ), - sa.Column("tenant_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), - sa.Column("runbook_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), - sa.Column("timestamp", sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(["incident_id"], ["incident.id"], ondelete="CASCADE"), - sa.ForeignKeyConstraint( - ["runbook_id"], - ["runbook.id"], - ), - sa.ForeignKeyConstraint( - ["tenant_id"], - ["tenant.id"], - ), - sa.PrimaryKeyConstraint("incident_id", "runbook_id"), - ) - - with op.batch_alter_table("incident", schema=None) as batch_op: - batch_op.add_column(sa.Column("runbooks_count", sa.Integer(), nullable=False)) - - - with op.batch_alter_table("runbook", schema=None) as batch_op: - batch_op.add_column(sa.Column("timestamp", sa.DateTime(), nullable=True)) - batch_op.create_index( - batch_op.f("ix_runbook_timestamp"), ["timestamp"], unique=False - ) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("runbook", schema=None) as batch_op: - batch_op.drop_index(batch_op.f("ix_runbook_timestamp")) - batch_op.drop_column("timestamp") - - - with op.batch_alter_table("incident", schema=None) as batch_op: - batch_op.drop_column("runbooks_count") - - op.drop_table("runbooktoincident") - # ### end Alembic commands ### diff --git a/keep/api/models/db/migrations/versions/2024-10-08-22-23_0796be640663.py b/keep/api/models/db/migrations/versions/2024-10-13-08-33_8af72e1df141.py similarity index 54% rename from keep/api/models/db/migrations/versions/2024-10-08-22-23_0796be640663.py rename to keep/api/models/db/migrations/versions/2024-10-13-08-33_8af72e1df141.py index 0d7e4b442..30addf841 100644 --- a/keep/api/models/db/migrations/versions/2024-10-08-22-23_0796be640663.py +++ b/keep/api/models/db/migrations/versions/2024-10-13-08-33_8af72e1df141.py @@ -1,17 +1,18 @@ -"""Add runbook tables +"""add runbook schema -Revision ID: 0796be640663 +Revision ID: 8af72e1df141 Revises: bf756df80e9d -Create Date: 2024-10-08 22:23:47.905179 +Create Date: 2024-10-13 08:33:24.727292 """ import sqlalchemy as sa +import sqlalchemy_utils import sqlmodel from alembic import op # revision identifiers, used by Alembic. -revision = "0796be640663" +revision = "8af72e1df141" down_revision = "bf756df80e9d" branch_labels = None depends_on = None @@ -24,6 +25,7 @@ def upgrade() -> None: sa.Column("tenant_id", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("relative_path", sa.Text(), nullable=True), sa.Column("title", sa.Text(), nullable=True), + sa.Column("timestamp", sa.DateTime(), nullable=True), sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("repo_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("provider_type", sqlmodel.sql.sqltypes.AutoString(), nullable=False), @@ -32,6 +34,11 @@ def upgrade() -> None: sa.ForeignKeyConstraint(["tenant_id"], ["tenant.id"], ondelete="CASCADE"), sa.PrimaryKeyConstraint("id"), ) + with op.batch_alter_table("runbook", schema=None) as batch_op: + batch_op.create_index( + batch_op.f("ix_runbook_timestamp"), ["timestamp"], unique=False + ) + op.create_table( "runbookcontent", sa.Column("runbook_id", sqlmodel.sql.sqltypes.GUID(), nullable=True), @@ -44,11 +51,43 @@ def upgrade() -> None: sa.ForeignKeyConstraint(["runbook_id"], ["runbook.id"], ondelete="CASCADE"), sa.PrimaryKeyConstraint("id"), ) + op.create_table( + "runbooktoincident", + sa.Column( + "incident_id", + sqlalchemy_utils.types.uuid.UUIDType(binary=False), + nullable=False, + ), + sa.Column("tenant_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column("runbook_id", sqlmodel.sql.sqltypes.GUID(), nullable=False), + sa.Column("timestamp", sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(["incident_id"], ["incident.id"], ondelete="CASCADE"), + sa.ForeignKeyConstraint( + ["runbook_id"], + ["runbook.id"], + ), + sa.ForeignKeyConstraint( + ["tenant_id"], + ["tenant.id"], + ), + sa.PrimaryKeyConstraint("incident_id", "runbook_id"), + ) + + with op.batch_alter_table("incident", schema=None) as batch_op: + batch_op.add_column(sa.Column("runbooks_count", sa.Integer(), nullable=False)) + # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("incident", schema=None) as batch_op: + batch_op.drop_column("runbooks_count") + + op.drop_table("runbooktoincident") op.drop_table("runbookcontent") + with op.batch_alter_table("runbook", schema=None) as batch_op: + batch_op.drop_index(batch_op.f("ix_runbook_timestamp")) + op.drop_table("runbook") # ### end Alembic commands ###