From 46e684b28d5165abd59a5f583decf6452fe5a04d Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 25 Oct 2023 19:55:30 +0300 Subject: [PATCH] core-update --- .gitignore | 1 + CHANGELOG.txt | 5 +++++ orm/__init__.py | 3 ++- orm/author.py | 31 +++++-------------------------- orm/community.py | 8 +------- pyproject.toml | 2 +- schemas/core.graphql | 4 +--- services/viewed.py | 2 +- 8 files changed, 17 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 4ce172a4..9de4ff38 100644 --- a/.gitignore +++ b/.gitignore @@ -147,3 +147,4 @@ migration/content/**/*.md *.csv dev-server.pid backups/ +poetry.lock \ No newline at end of file diff --git a/CHANGELOG.txt b/CHANGELOG.txt index fc7ab0ae..c87294c5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +[0.2.12] +- Author.userpic -> Author.pic +- CommunityAuthor.role is string now +- Author.user is string now + [0.2.11] - redis interface updated - viewed interface updated diff --git a/orm/__init__.py b/orm/__init__.py index 81d8b7c2..3c42b5c9 100644 --- a/orm/__init__.py +++ b/orm/__init__.py @@ -1,8 +1,9 @@ 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") diff --git a/orm/author.py b/orm/author.py index 1f83ebbd..323f520b 100644 --- a/orm/author.py +++ b/orm/author.py @@ -2,7 +2,7 @@ from datetime import datetime from sqlalchemy import JSON as JSONType from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String from sqlalchemy.orm import relationship -from services.db import Base, local_session +from services.db import Base class AuthorRating(Base): @@ -31,37 +31,16 @@ class AuthorFollower(Base): class Author(Base): __tablename__ = "author" - user = Column(Integer, nullable=False) # unbounded link with authorizer's User type + user = Column(String, nullable=False) # unbounded link with authorizer's User type bio = Column(String, nullable=True, comment="Bio") # status description about = Column(String, nullable=True, comment="About") # long and formatted - userpic = Column(String, nullable=True, comment="Userpic") + pic = Column(String, nullable=True, comment="Userpic") name = Column(String, nullable=True, comment="Display name") slug = Column(String, unique=True, comment="Author's slug") - muted = Column(Boolean, default=False) + createdAt = Column(DateTime, nullable=False, default=datetime.now) lastSeen = Column(DateTime, nullable=False, default=datetime.now) # Td se 0e deletedAt = Column(DateTime, nullable=True, comment="Deleted at") + links = Column(JSONType, nullable=True, comment="Links") ratings = relationship(AuthorRating, foreign_keys=AuthorRating.author) - - @staticmethod - def init_table(): - with local_session() as session: - default = session.query(Author).filter(Author.slug == "anonymous").first() - if not default: - default_dict = { - "user": 0, - "name": "Аноним", - "slug": "anonymous", - } - default = Author.create(**default_dict) - session.add(default) - discours_dict = { - "user": 1, - "name": "Дискурс", - "slug": "discours", - } - discours = Author.create(**discours_dict) - session.add(discours) - session.commit() - Author.default_author = default diff --git a/orm/community.py b/orm/community.py index 2579a918..ee54979c 100644 --- a/orm/community.py +++ b/orm/community.py @@ -6,12 +6,6 @@ from services.db import Base, local_session from orm.author import Author -class CommunityRole: - __tablename__ = "community_role" - - name = Column(String, nullable=False) - - class CommunityAuthor(Base): __tablename__ = "community_author" @@ -19,7 +13,7 @@ class CommunityAuthor(Base): follower = Column(ForeignKey("author.id"), primary_key=True) community = Column(ForeignKey("community.id"), primary_key=True) joinedAt = Column(DateTime, nullable=False, default=datetime.now) - role = Column(ForeignKey("community_role.id"), nullable=False) + role = Column(String, nullable=False) class Community(Base): diff --git a/pyproject.toml b/pyproject.toml index ef484887..f8440349 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "discoursio-core" -version = "0.2.11" +version = "0.2.12" description = "core module for discours.io" authors = ["discoursio devteam"] license = "MIT" diff --git a/schemas/core.graphql b/schemas/core.graphql index dac32701..df3d9c31 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -168,9 +168,7 @@ type Author { user: Int! slug: String! name: String - communities: [Community] - userpic: String - caption: String + pic: String bio: String about: String links: [String] diff --git a/services/viewed.py b/services/viewed.py index 7ae9b5a0..a29a3ecd 100644 --- a/services/viewed.py +++ b/services/viewed.py @@ -1,7 +1,7 @@ import asyncio import time from datetime import timedelta, timezone, datetime -from os import environ, path +from os import environ from gql import Client, gql from gql.transport.httpx import HTTPXAsyncTransport