2021-08-26 21:14:20 +00:00
|
|
|
from datetime import datetime
|
2022-09-17 18:12:14 +00:00
|
|
|
|
2023-10-26 17:56:42 +00:00
|
|
|
from sqlalchemy import Column, DateTime, ForeignKey, String
|
|
|
|
|
2022-08-11 05:53:14 +00:00
|
|
|
from base.orm import Base, local_session
|
2021-08-26 21:14:20 +00:00
|
|
|
|
2022-09-03 10:50:14 +00:00
|
|
|
|
2022-07-21 11:58:50 +00:00
|
|
|
class CommunityFollower(Base):
|
2022-09-03 10:50:14 +00:00
|
|
|
__tablename__ = "community_followers"
|
2022-06-12 07:51:22 +00:00
|
|
|
|
2022-09-03 10:50:14 +00:00
|
|
|
id = None # type: ignore
|
2022-11-30 17:21:15 +00:00
|
|
|
follower = Column(ForeignKey("user.id"), primary_key=True)
|
|
|
|
community = Column(ForeignKey("community.id"), primary_key=True)
|
2023-10-26 17:56:42 +00:00
|
|
|
joinedAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
2022-11-24 08:27:01 +00:00
|
|
|
# role = Column(ForeignKey(Role.id), nullable=False, comment="Role for member")
|
2022-06-12 07:51:22 +00:00
|
|
|
|
2021-08-26 21:14:20 +00:00
|
|
|
|
|
|
|
class Community(Base):
|
2022-09-03 10:50:14 +00:00
|
|
|
__tablename__ = "community"
|
|
|
|
|
|
|
|
name = Column(String, nullable=False, comment="Name")
|
|
|
|
slug = Column(String, nullable=False, unique=True, comment="Slug")
|
|
|
|
desc = Column(String, nullable=False, default="")
|
|
|
|
pic = Column(String, nullable=False, default="")
|
2023-10-26 17:56:42 +00:00
|
|
|
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
2022-09-03 10:50:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def init_table():
|
|
|
|
with local_session() as session:
|
2023-10-26 17:56:42 +00:00
|
|
|
d = session.query(Community).filter(Community.slug == "discours").first()
|
2022-11-19 11:35:34 +00:00
|
|
|
if not d:
|
2022-11-24 08:27:01 +00:00
|
|
|
d = Community.create(name="Дискурс", slug="discours")
|
2022-11-19 11:35:34 +00:00
|
|
|
session.add(d)
|
|
|
|
session.commit()
|
|
|
|
Community.default_community = d
|
2022-11-20 07:48:40 +00:00
|
|
|
print('[orm] default community id: %s' % d.id)
|