finish for init core
This commit is contained in:
@ -1 +1 @@
|
||||
from .user import *
|
||||
from .users import *
|
||||
|
20
fuware/db/models/_model_base.py
Normal file
20
fuware/db/models/_model_base.py
Normal file
@ -0,0 +1,20 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Integer
|
||||
from sqlalchemy.orm import declarative_base, Mapped, mapped_column
|
||||
from text_unidecode import unidecode
|
||||
|
||||
from fuware.db.db_setup import SessionLocal
|
||||
|
||||
Model = declarative_base()
|
||||
Model.query = SessionLocal.query_property()
|
||||
|
||||
class SqlAlchemyBase(Model):
|
||||
__abstract__ = True
|
||||
|
||||
created_at: Mapped[datetime | None] = mapped_column(DateTime, default=datetime.utcnow(), index=True)
|
||||
update_at: Mapped[datetime | None] = mapped_column(DateTime, default=datetime.utcnow(), onupdate=datetime.utcnow())
|
||||
|
||||
@classmethod
|
||||
def normalize(cls, val: str) -> str:
|
||||
return unidecode(val).lower().strip()
|
@ -1,8 +0,0 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, DateTime
|
||||
from sqlalchemy.orm import declarative_mixin
|
||||
|
||||
@declarative_mixin
|
||||
class Timestamp:
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
@ -1,15 +0,0 @@
|
||||
from db import Base
|
||||
from sqlalchemy import Boolean, Column, String
|
||||
from .mixins import Timestamp
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
|
||||
class User(Base, Timestamp):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True)
|
||||
username = Column(String(100), unique=True, index=True, nullable=False)
|
||||
password = Column(String, index=True, nullable=False)
|
||||
name = Column(String, index=True, nullable=True)
|
||||
is_admin = Column(Boolean, default=False)
|
||||
is_lock = Column(Boolean, default=False)
|
1
fuware/db/models/users/__init__.py
Normal file
1
fuware/db/models/users/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .users import *
|
20
fuware/db/models/users/users.py
Normal file
20
fuware/db/models/users/users.py
Normal file
@ -0,0 +1,20 @@
|
||||
import uuid
|
||||
from sqlalchemy import Boolean, Column, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from .._model_base import SqlAlchemyBase
|
||||
|
||||
class User(SqlAlchemyBase):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id: Mapped[UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4, index=True)
|
||||
username: Mapped[str | None] = mapped_column(String, unique=True, index=True, nullable=False)
|
||||
password: Mapped[str | None] = mapped_column(String, index=True, nullable=False)
|
||||
name: Mapped[str | None] = mapped_column(String, index=True, nullable=True)
|
||||
is_admin: Mapped[bool | None] = mapped_column(Boolean, default=False)
|
||||
is_lock: Mapped[bool | None] = mapped_column(Boolean, default=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}, name: {self.name}, username: {self.username}"
|
Reference in New Issue
Block a user