-
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.
- Loading branch information
1 parent
6d2fb98
commit 9d64a4a
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/zenml/zen_stores/migrations/versions/7b651bf6822e_track_secrets_in_db.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,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 ### |