niming_backend/utils/pgclass.py

69 lines
1.7 KiB
Python
Raw Normal View History

2024-12-17 01:08:35 +08:00
from sqlalchemy import Column, String, TIMESTAMP, func, BIGINT, ARRAY
2024-11-13 03:23:11 +08:00
from sqlalchemy.ext.declarative import declarative_base
2024-12-09 03:24:22 +08:00
from sqlalchemy_utils.types.pg_composite import CompositeType
from sqlalchemy.ext.mutable import MutableList
2024-11-13 03:23:11 +08:00
Base = declarative_base()
2024-12-09 03:24:22 +08:00
CompositeType.cache_ok = False
comment_type = CompositeType(
'comment',
[
Column('content', String),
Column('ip', String),
Column('hash', String),
Column('created_at', TIMESTAMP),
Column("sha1", String)
]
)
2024-12-17 01:08:35 +08:00
# post
2024-11-13 03:23:11 +08:00
class SQLarticle(Base):
__tablename__ = 'posts'
2024-11-14 13:03:00 +08:00
id = Column(BIGINT, primary_key=True)
2024-11-25 21:51:50 +08:00
content = Column(String)
2024-12-09 03:24:22 +08:00
file_list = Column(ARRAY(String))
hash = Column(String)
comment_list = Column(MutableList.as_mutable(ARRAY(comment_type)))
# post metadata
class SQLmeta(Base):
__tablename__ = 'article_meta'
hash = Column(String, primary_key=True)
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
2024-11-13 03:23:11 +08:00
igid = Column(String)
2024-11-14 13:03:00 +08:00
ip = Column(String)
2024-11-13 03:23:11 +08:00
2024-11-13 21:20:21 +08:00
2024-12-09 03:24:22 +08:00
# post mark
class SQLmark(Base):
__tablename__ = 'mark'
hash = Column(String, primary_key=True)
mark = Column(String)
# logs
2024-11-13 21:20:21 +08:00
class SQLlog(Base):
__tablename__ = 'logs'
id = Column(BIGINT, primary_key=True)
2024-11-13 21:20:21 +08:00
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
message = Column(String)
source = Column(String)
2024-11-18 02:47:25 +08:00
2024-12-17 01:08:35 +08:00
# user
2024-11-18 02:47:25 +08:00
class SQLuser(Base):
__tablename__ = 'users'
id = Column(BIGINT, primary_key=True)
user = Column(String)
password = Column(String) # hash , sha512
permission = Column(ARRAY(String))