@@ -1,10 +0,0 @@
|
||||
from services.db import Base, engine
|
||||
from orm.shout import Shout
|
||||
from orm.community import Community
|
||||
|
||||
|
||||
def init_tables():
|
||||
Base.metadata.create_all(engine)
|
||||
Shout.init_table()
|
||||
Community.init_table()
|
||||
print("[orm] tables initialized")
|
@@ -1,7 +1,9 @@
|
||||
import time
|
||||
|
||||
from sqlalchemy import JSON as JSONType
|
||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from services.db import Base
|
||||
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import time
|
||||
from sqlalchemy import Column, Integer, ForeignKey, String
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||
|
||||
from services.db import Base
|
||||
|
||||
|
||||
@@ -20,4 +22,4 @@ class Collection(Base):
|
||||
pic = Column(String, nullable=True, comment="Picture")
|
||||
created_at = Column(Integer, default=lambda: int(time.time()))
|
||||
created_by = Column(ForeignKey("author.id"), comment="Created By")
|
||||
published_at = Column(Integer, default=lambda: int(time.time()))
|
||||
publishedAt = Column(Integer, default=lambda: int(time.time()))
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import time
|
||||
from sqlalchemy import Column, String, ForeignKey, Integer
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from services.db import Base, local_session
|
||||
from orm.author import Author
|
||||
from services.db import Base, local_session
|
||||
|
||||
|
||||
class CommunityAuthor(Base):
|
||||
@@ -29,10 +30,12 @@ class Community(Base):
|
||||
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
with local_session("orm.community") as session:
|
||||
d = session.query(Community).filter(Community.slug == "discours").first()
|
||||
if not d:
|
||||
d = Community.create(name="Дискурс", slug="discours")
|
||||
print("[orm] created community %s" % d.slug)
|
||||
d = Community(name="Дискурс", slug="discours")
|
||||
session.add(d)
|
||||
session.commit()
|
||||
print("[orm.community] created community %s" % d.slug)
|
||||
Community.default_community = d
|
||||
print("[orm] default community is %s" % d.slug)
|
||||
print("[orm.community] default community is %s" % d.slug)
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from enum import Enum as Enumeration
|
||||
from sqlalchemy import Column, Integer, Enum, ForeignKey, String
|
||||
from services.db import Base
|
||||
import time
|
||||
from enum import Enum as Enumeration
|
||||
|
||||
from sqlalchemy import Column, Enum, ForeignKey, Integer, String
|
||||
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class ReactionKind(Enumeration):
|
||||
@@ -33,5 +35,7 @@ class Reaction(Base):
|
||||
deleted_by = Column(ForeignKey("author.id"), nullable=True, index=True)
|
||||
shout = Column(ForeignKey("shout.id"), nullable=False, index=True)
|
||||
reply_to = Column(ForeignKey("reaction.id"), nullable=True)
|
||||
quote = Column(String, nullable=True, comment="a quoted fragment")
|
||||
range = Column(String, nullable=True, comment="<start index>:<end>")
|
||||
kind = Column(Enum(ReactionKind), nullable=False)
|
||||
|
||||
oid = Column(String)
|
||||
|
39
orm/shout.py
39
orm/shout.py
@@ -1,20 +1,14 @@
|
||||
import time
|
||||
from enum import Enum as Enumeration
|
||||
from sqlalchemy import (
|
||||
Enum,
|
||||
Boolean,
|
||||
Column,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
JSON,
|
||||
)
|
||||
from sqlalchemy.orm import column_property, relationship
|
||||
from services.db import Base, local_session
|
||||
|
||||
from sqlalchemy import JSON, Boolean, Column, Enum, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from orm.author import Author
|
||||
from orm.community import Community
|
||||
from orm.reaction import Reaction
|
||||
from orm.topic import Topic
|
||||
from orm.author import Author
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class ShoutTopic(Base):
|
||||
@@ -66,8 +60,7 @@ class Shout(Base):
|
||||
updated_at = Column(Integer, nullable=True)
|
||||
published_at = Column(Integer, nullable=True)
|
||||
deleted_at = Column(Integer, nullable=True)
|
||||
|
||||
created_by = Column(ForeignKey("author.id"), comment="Created By")
|
||||
|
||||
deleted_by = Column(ForeignKey("author.id"), nullable=True)
|
||||
|
||||
body = Column(String, nullable=False, comment="Body")
|
||||
@@ -80,9 +73,9 @@ class Shout(Base):
|
||||
layout = Column(String, nullable=True)
|
||||
media = Column(JSON, nullable=True)
|
||||
|
||||
authors = relationship(lambda: Author, secondary=ShoutAuthor.__tablename__)
|
||||
topics = relationship(lambda: Topic, secondary=ShoutTopic.__tablename__)
|
||||
communities = relationship(lambda: Community, secondary=ShoutCommunity.__tablename__)
|
||||
authors = relationship(lambda: Author, secondary="shout_author")
|
||||
topics = relationship(lambda: Topic, secondary="shout_topic")
|
||||
communities = relationship(lambda: Community, secondary="shout_community")
|
||||
reactions = relationship(lambda: Reaction)
|
||||
|
||||
visibility = Column(Enum(ShoutVisibility), default=ShoutVisibility.AUTHORS)
|
||||
@@ -91,15 +84,3 @@ class Shout(Base):
|
||||
version_of = Column(ForeignKey("shout.id"), nullable=True)
|
||||
oid = Column(String, nullable=True)
|
||||
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
s = session.query(Shout).first()
|
||||
if not s:
|
||||
entry = {
|
||||
"slug": "genesis-block",
|
||||
"body": "",
|
||||
"title": "Ничего",
|
||||
"lang": "ru",
|
||||
}
|
||||
s = Shout.create(**entry)
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import time
|
||||
from sqlalchemy import Boolean, Column, Integer, ForeignKey, String
|
||||
|
||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
||||
|
||||
from services.db import Base
|
||||
|
||||
|
||||
|
30
orm/user.py
Normal file
30
orm/user.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import time
|
||||
|
||||
from sqlalchemy import JSON, Boolean, Column, Integer, String
|
||||
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "authorizer_users"
|
||||
|
||||
id = Column(String, primary_key=True, unique=True, nullable=False, default=None)
|
||||
key = Column(String)
|
||||
email = Column(String, unique=True)
|
||||
email_verified_at = Column(Integer)
|
||||
family_name = Column(String)
|
||||
gender = Column(String)
|
||||
given_name = Column(String)
|
||||
is_multi_factor_auth_enabled = Column(Boolean)
|
||||
middle_name = Column(String)
|
||||
nickname = Column(String)
|
||||
password = Column(String)
|
||||
phone_number = Column(String, unique=True)
|
||||
phone_number_verified_at = Column(Integer)
|
||||
# preferred_username = Column(String, nullable=False)
|
||||
picture = Column(String)
|
||||
revoked_timestamp = Column(Integer)
|
||||
roles = Column(JSON)
|
||||
signup_methods = Column(String, default="magic_link_login")
|
||||
created_at = Column(Integer, default=lambda: int(time.time()))
|
||||
updated_at = Column(Integer, default=lambda: int(time.time()))
|
Reference in New Issue
Block a user