From 15f0bc39988079ead4a89b8561ad4921efc717c8 Mon Sep 17 00:00:00 2001 From: Jason Syrotuck Date: Fri, 24 Jun 2022 08:48:34 -0700 Subject: [PATCH] Feature/alembic model detection (#205) * time to test showcase Signed-off-by: Jason Sy * revert file changes.. still throwing error? Signed-off-by: Jason Sy * reverting the right file Signed-off-by: Jason Sy * new alembic revision Signed-off-by: Jason Sy * linter didn't like this Signed-off-by: Jason Sy * existing db column type is varchar Signed-off-by: Jason Sy --- .../autogenerate_sync_e7fdfee68c43.py | 61 +++++++++++++++++++ services/traction/api/db/models/__init__.py | 7 +++ .../api/db/models/present_credential.py | 1 + .../api/db/models/tenant_webhook_msg.py | 4 +- 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 services/traction/api/db/migrations/versions/autogenerate_sync_e7fdfee68c43.py diff --git a/services/traction/api/db/migrations/versions/autogenerate_sync_e7fdfee68c43.py b/services/traction/api/db/migrations/versions/autogenerate_sync_e7fdfee68c43.py new file mode 100644 index 000000000..9fdca191f --- /dev/null +++ b/services/traction/api/db/migrations/versions/autogenerate_sync_e7fdfee68c43.py @@ -0,0 +1,61 @@ +"""autogenerate_sync + +Revision ID: e7fdfee68c43 +Revises: 2ab74e9499c0 +Create Date: 2022-06-23 22:39:44.842386 + +""" +from alembic import op +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "e7fdfee68c43" +down_revision = "2ab74e9499c0" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + # We don't want these to be nullable, but it's going to be re-written soon + op.alter_column( + "tenantwebhook", "tenant_id", existing_type=postgresql.UUID(), nullable=True + ) + op.alter_column( + "tenantwebhookmsg", "tenant_id", existing_type=postgresql.UUID(), nullable=True + ) + + op.create_index( + op.f("ix_verifier_presentation_contact_id"), + "verifier_presentation", + ["contact_id"], + unique=False, + ) + op.create_index( + op.f("ix_verifier_presentation_tenant_id"), + "verifier_presentation", + ["tenant_id"], + unique=False, + ) + op.create_foreign_key( + None, "verifier_presentation", "tenant", ["tenant_id"], ["id"] + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, "verifier_presentation", type_="foreignkey") + op.drop_index( + op.f("ix_verifier_presentation_tenant_id"), table_name="verifier_presentation" + ) + op.drop_index( + op.f("ix_verifier_presentation_contact_id"), table_name="verifier_presentation" + ) + op.alter_column( + "tenantwebhookmsg", "tenant_id", existing_type=postgresql.UUID(), nullable=False + ) + op.alter_column( + "tenantwebhook", "tenant_id", existing_type=postgresql.UUID(), nullable=False + ) + # ### end Alembic commands ### diff --git a/services/traction/api/db/models/__init__.py b/services/traction/api/db/models/__init__.py index d7e4a59eb..53e6aec5e 100644 --- a/services/traction/api/db/models/__init__.py +++ b/services/traction/api/db/models/__init__.py @@ -4,12 +4,19 @@ from api.db.models.tenant import Tenant # noqa: F401 from api.db.models.tenant_webhook import TenantWebhook # noqa: F401 from api.db.models.tenant_webhook_msg import TenantWebhookMsg # noqa: F401 +from api.db.models.tenant_schema import TenantSchema # noqa: F401 +from api.db.models.issue_credential import IssueCredential # noqa: F401 +from api.db.models.present_credential import PresentCredential # noqa: F401 +from api.db.models.tenant_issuer import TenantIssuer # noqa: F401 +from api.db.models.tenant_connection import TenantConnection # noqa: F401 +from api.db.models.tenant_workflow import TenantWorkflow # noqa: F401 from api.db.models.v1.contact import Contact # noqa: F401 from api.db.models.v1.connection_invitation import ConnectionInvitation # noqa: F401 from api.db.models.v1.governance import SchemaTemplate, CredentialTemplate # noqa: F401 from api.db.models.v1.issuer import IssuerCredential # noqa: F401 from api.db.models.v1.message import Message # noqa: F401 +from api.db.models.v1.verifier_presentation import VerifierPresentation # noqa: F401 from api.db.models.v1.tenant_permissions import TenantPermissions # noqa: F401 from api.db.models.v1.tenant_configuration import ( TenantConfiguration, diff --git a/services/traction/api/db/models/present_credential.py b/services/traction/api/db/models/present_credential.py index 65ecd2e6f..d2fd6617f 100644 --- a/services/traction/api/db/models/present_credential.py +++ b/services/traction/api/db/models/present_credential.py @@ -18,6 +18,7 @@ class PresentCredentialBase(BaseModel): workflow_id: uuid.UUID = Field(nullable=True, default=None) pres_exch_id: uuid.UUID = Field(nullable=True, default=None) presentation: str = Field(nullable=True, default=None) + cred_def_id: str = Field(nullable=True, default=None) class PresentCredential(PresentCredentialBase, BaseTable, table=True): diff --git a/services/traction/api/db/models/tenant_webhook_msg.py b/services/traction/api/db/models/tenant_webhook_msg.py index 2ce9be53d..deaa2cdeb 100644 --- a/services/traction/api/db/models/tenant_webhook_msg.py +++ b/services/traction/api/db/models/tenant_webhook_msg.py @@ -2,9 +2,8 @@ from datetime import datetime from typing import Optional -from sqlmodel import Field - from api.db.models.base import BaseModel, BaseTable +from sqlmodel import Field class TenantWebhookMsgBase(BaseModel): @@ -23,6 +22,7 @@ class TenantWebhookMsgBase(BaseModel): class TenantWebhookMsg(TenantWebhookMsgBase, BaseTable, table=True): # This is the class that represents the table + # may be optional in some modelsomes, but not in the db table pass