-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DB migration script to remove secrets managers
- Loading branch information
1 parent
32b03c5
commit 55b3cae
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/zenml/zen_stores/migrations/versions/1041bc644e0d_remove_secrets_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""remove secrets manager [1041bc644e0d]. | ||
Revision ID: 1041bc644e0d | ||
Revises: 4e1972485075 | ||
Create Date: 2023-12-18 18:40:26.612845 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1041bc644e0d" | ||
down_revision = "4e1972485075" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Upgrade database schema and/or data, creating a new revision.""" | ||
conn = op.get_bind() | ||
meta = sa.MetaData(bind=op.get_bind()) | ||
meta.reflect(only=("stack_component", "stack_composition")) | ||
components = sa.Table("stack_component", meta) | ||
compositions = sa.Table("stack_composition", meta) | ||
|
||
# Find all secrets manager components | ||
secrets_manager_components = conn.execute( | ||
sa.select([components.c.id]).where( | ||
components.c.type == "secrets_manager" | ||
) | ||
).all() | ||
|
||
secrets_manager_ids = [i[0] for i in secrets_manager_components] | ||
|
||
# Remove all secrets manager compositions | ||
conn.execute( | ||
compositions.delete().where( | ||
compositions.c.component_id.in_(secrets_manager_ids) | ||
) | ||
) | ||
|
||
# Remove all secrets manager components | ||
conn.execute( | ||
components.delete().where(components.c.id.in_(secrets_manager_ids)) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
"""Downgrade database schema and/or data back to the previous revision.""" | ||
pass |