nochecks
This commit is contained in:
@@ -6,6 +6,9 @@ from orm.reaction import Reaction
|
||||
from orm.shout import Shout
|
||||
from orm.topic import Topic, TopicFollower
|
||||
from orm.user import User, UserRating
|
||||
from orm.viewed import ViewedEntry
|
||||
|
||||
# NOTE: keep orm module isolated
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
@@ -19,13 +22,18 @@ __all__ = [
|
||||
"Notification",
|
||||
"Reaction",
|
||||
"UserRating"
|
||||
"ViewedEntry"
|
||||
]
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
Operation.init_table()
|
||||
Resource.init_table()
|
||||
User.init_table()
|
||||
Community.init_table()
|
||||
Role.init_table()
|
||||
|
||||
# NOTE: keep orm module isolated
|
||||
def init_tables():
|
||||
Base.metadata.create_all(engine)
|
||||
Operation.init_table()
|
||||
Resource.init_table()
|
||||
User.init_table()
|
||||
Community.init_table()
|
||||
UserRating.init_table()
|
||||
Shout.init_table()
|
||||
Role.init_table()
|
||||
ViewedEntry.init_table()
|
||||
print("[orm] tables initialized")
|
||||
|
@@ -32,12 +32,14 @@ class Community(Base):
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
default = (
|
||||
d = (
|
||||
session.query(Community).filter(Community.slug == "discours").first()
|
||||
)
|
||||
if not default:
|
||||
default = Community.create(
|
||||
name="Дискурс", slug="discours", createdBy="discours"
|
||||
)
|
||||
|
||||
Community.default_community = default
|
||||
if not d:
|
||||
d = Community.create(
|
||||
name="Дискурс", slug="discours", createdBy="anonymous"
|
||||
)
|
||||
session.add(d)
|
||||
session.commit()
|
||||
Community.default_community = d
|
||||
print('[migration] default community: %s' % d.id)
|
||||
|
@@ -50,7 +50,7 @@ class Role(Base):
|
||||
default = Role.create(
|
||||
name="author",
|
||||
desc="Role for author",
|
||||
community=Community.default_community.id,
|
||||
community=1,
|
||||
)
|
||||
|
||||
Role.default_role = default
|
||||
|
20
orm/shout.py
20
orm/shout.py
@@ -1,9 +1,9 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, JSON
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from base.orm import Base
|
||||
from base.orm import Base, local_session
|
||||
from orm.reaction import Reaction
|
||||
from orm.topic import Topic
|
||||
from orm.user import User
|
||||
@@ -43,7 +43,7 @@ class Shout(Base):
|
||||
__tablename__ = "shout"
|
||||
|
||||
slug = Column(String, unique=True)
|
||||
community = Column(Integer, ForeignKey("community.id"), nullable=False, comment="Community")
|
||||
community = Column(ForeignKey("community.id"), default=1)
|
||||
lang = Column(String, nullable=False, default='ru', comment="Language")
|
||||
body = Column(String, nullable=False, comment="Body")
|
||||
title = Column(String, nullable=True)
|
||||
@@ -56,7 +56,6 @@ class Shout(Base):
|
||||
reactions = relationship(lambda: Reaction)
|
||||
visibility = Column(String, nullable=True) # owner authors community public
|
||||
versionOf = Column(ForeignKey("shout.slug"), nullable=True)
|
||||
lang = Column(String, default='ru')
|
||||
oid = Column(String, nullable=True)
|
||||
media = Column(JSON, nullable=True)
|
||||
|
||||
@@ -64,3 +63,16 @@ class Shout(Base):
|
||||
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
|
||||
publishedAt = Column(DateTime, nullable=True)
|
||||
deletedAt = Column(DateTime, nullable=True)
|
||||
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
entry = {
|
||||
"slug": "genesis-block",
|
||||
"body": "",
|
||||
"title": "Ничего",
|
||||
"lang": "ru"
|
||||
}
|
||||
s = Shout.create(**entry)
|
||||
session.add(s)
|
||||
session.commit()
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import JSON as JSONType
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String
|
||||
|
||||
from base.orm import Base
|
||||
@@ -25,10 +24,7 @@ class Topic(Base):
|
||||
title = Column(String, nullable=False, comment="Title")
|
||||
body = Column(String, nullable=True, comment="Body")
|
||||
pic = Column(String, nullable=True, comment="Picture")
|
||||
children = Column(
|
||||
JSONType, nullable=True, default=[], comment="list of children topics"
|
||||
)
|
||||
community = Column(
|
||||
ForeignKey("community.slug"), nullable=False, comment="Community"
|
||||
ForeignKey("community.id"), default=1, comment="Community"
|
||||
)
|
||||
oid = Column(String, nullable=True, comment="Old ID")
|
||||
|
@@ -25,6 +25,10 @@ class UserRating(Base):
|
||||
user = Column(ForeignKey("user.slug"), primary_key=True)
|
||||
value = Column(Integer)
|
||||
|
||||
@staticmethod
|
||||
def init_table():
|
||||
pass
|
||||
|
||||
|
||||
class UserRole(Base):
|
||||
__tablename__ = "user_role"
|
||||
@@ -48,6 +52,7 @@ class AuthorFollower(Base):
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "user"
|
||||
default_user = None
|
||||
|
||||
email = Column(String, unique=True, nullable=False, comment="Email")
|
||||
username = Column(String, nullable=False, comment="Login")
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, DateTime, ForeignKey
|
||||
from base.orm import Base
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer
|
||||
from base.orm import Base, local_session
|
||||
|
||||
|
||||
class ViewedEntry(Base):
|
||||
@@ -8,6 +8,18 @@ class ViewedEntry(Base):
|
||||
|
||||
viewer = Column(ForeignKey("user.slug"), default='anonymous')
|
||||
shout = Column(ForeignKey("shout.slug"))
|
||||
amount = Column(Integer, default=1)
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
entry = {
|
||||
"shout": "genesis-block",
|
||||
"amount": 0
|
||||
}
|
||||
viewed = ViewedEntry.create(**entry)
|
||||
session.add(viewed)
|
||||
session.commit()
|
||||
|
Reference in New Issue
Block a user