Skip to content

Commit

Permalink
Add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
stefannica committed Dec 22, 2023
1 parent 6d2fb98 commit 9d64a4a
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""track secrets in db [7b651bf6822e].
Revision ID: 7b651bf6822e
Revises: 0.53.1
Create Date: 2023-12-22 20:56:18.131906
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.


revision = "7b651bf6822e"
down_revision = "0.53.1"
branch_labels = None
depends_on = None


def upgrade() -> None:
"""Upgrade database schema and/or data, creating a new revision."""
from zenml.config.global_config import GlobalConfiguration
from zenml.enums import SecretsStoreType

zen_store = GlobalConfiguration().zen_store

if zen_store.secrets_store.type == SecretsStoreType.SQL:
return

# Transfer secrets from the external secrets store to the db
secrets_store = zen_store.secrets_store

external_secrets = secrets_store.list_secrets()

conn = op.get_bind()
meta = sa.MetaData(bind=op.get_bind())
meta.reflect(only=("secret",))
secrets = sa.Table("artifact", meta)
for secret in external_secrets:
conn.execute(
secrets.insert().values(
id=secret.id,
created=secret.created,
updated=secret.updated,
name=secret.name,
scope=secret.scope,
values=None,
workspace_id=secret.workspace.id,
user_id=secret.user.id if secret.user else None,
)
)


def downgrade() -> None:
"""Downgrade database schema and/or data back to the previous revision."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###

0 comments on commit 9d64a4a

Please sign in to comment.