-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Hello,
I'm replacing all the database access implementations I used previously with Fatsapi-sqla, and now I need to integrate it with alembic.
What would be the best way to use Fastapi-sqla in alembic?
Do you have any examples of a standard implementation?
I'm defining my models as follows:
from datetime import datetime
from fastapi_sqla import Base
from sqlalchemy.dialects.postgresql.json import JSONB
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.sql import expression
from sqlalchemy import (
Column,
Integer,
String,
Boolean,
UniqueConstraint,
PrimaryKeyConstraint,
DateTime,
text,
)
import cuid
class EntityModel(Base):
__tablename__ = "entities"
__table_args__ = (
PrimaryKeyConstraint("id", name="entities_pkey"),
UniqueConstraint("business_id", name="entities_business_id_ukey"),
)
id = Column(String(25), default=cuid.cuid, nullable=False, primary_key=True)
owner = Column(String(25), nullable=False)
name = Column(String(128), nullable=False)
email = Column(String(255), nullable=False)
active = Column(
Boolean, nullable=False, default=False, server_default=expression.false()
)
status = Column(Integer, nullable=False, default=0, server_default=text("0"))
country = Column(String(3), default="BRA", nullable=False)
business_id = Column(String(25), nullable=False)
external_id = Column(String(128), nullable=True)
partner_id = Column(String(25), nullable=True)
profile = Column(MutableDict.as_mutable(JSONB))
created_at = Column(
DateTime(timezone=False), default=datetime.utcnow, nullable=False
)
updated_at = Column(
DateTime(timezone=False),
default=datetime.utcnow,
onupdate=datetime.utcnow,
nullable=False,
)
def __init__(self, *args, **kwargs):
if "id" not in kwargs:
kwargs["id"] = cuid.cuid()
super(EntityModel, self).__init__(*args, **kwargs)
Is this the best way to do it ?
Thanks
Metadata
Metadata
Assignees
Labels
No labels