imports-format+id-fix+remigrate

This commit is contained in:
tonyrewin 2022-11-10 08:40:32 +03:00
parent b62211e05f
commit 503d6daa93
11 changed files with 36 additions and 37 deletions

View File

@ -10,7 +10,8 @@ import bs4
from migration.tables.comments import migrate as migrateComment from migration.tables.comments import migrate as migrateComment
from migration.tables.comments import migrate_2stage as migrateComment_2stage from migration.tables.comments import migrate_2stage as migrateComment_2stage
from migration.tables.content_items import get_shout_slug, migrate as migrateShout from migration.tables.content_items import get_shout_slug
from migration.tables.content_items import migrate as migrateShout
from migration.tables.topics import migrate as migrateTopic from migration.tables.topics import migrate as migrateTopic
from migration.tables.users import migrate as migrateUser from migration.tables.users import migrate as migrateUser
from migration.tables.users import migrate_2stage as migrateUser_2stage from migration.tables.users import migrate_2stage as migrateUser_2stage

View File

@ -2,6 +2,7 @@ import base64
import os import os
import re import re
import uuid import uuid
from .html2text import html2text from .html2text import html2text
TOOLTIP_REGEX = r"(\/\/\/(.+)\/\/\/)" TOOLTIP_REGEX = r"(\/\/\/(.+)\/\/\/)"

View File

@ -47,6 +47,7 @@
"antifashizm": "anti-faschism", "antifashizm": "anti-faschism",
"antiquity": "antiquity", "antiquity": "antiquity",
"antiutopiya": "dystopia", "antiutopiya": "dystopia",
"anton-dolin": "anton-dolin",
"antropology": "antropology", "antropology": "antropology",
"antropotsen": "antropocenus", "antropotsen": "antropocenus",
"architecture": "architecture", "architecture": "architecture",
@ -159,6 +160,7 @@
"design": "design", "design": "design",
"detskie-doma": "orphanages", "detskie-doma": "orphanages",
"detstvo": "childhood", "detstvo": "childhood",
"devid-linch": "david-linch",
"devyanostye": "90s", "devyanostye": "90s",
"dialog": "dialogue", "dialog": "dialogue",
"digital": "digital", "digital": "digital",
@ -359,6 +361,7 @@
"kazan": "kazan", "kazan": "kazan",
"kiberbezopasnost": "cybersecurity", "kiberbezopasnost": "cybersecurity",
"kinoklub": "cinema-club", "kinoklub": "cinema-club",
"kinokritika": "film-criticism",
"kirill-serebrennikov": "kirill-serebrennikov", "kirill-serebrennikov": "kirill-serebrennikov",
"kladbische": "cemetery", "kladbische": "cemetery",
"klassika": "classic", "klassika": "classic",
@ -503,6 +506,7 @@
"odinochestvo": "loneliness", "odinochestvo": "loneliness",
"odna-kniga-odna-istoriya": "one-book-one-story", "odna-kniga-odna-istoriya": "one-book-one-story",
"okrainy": "outskirts", "okrainy": "outskirts",
"omon": "swat",
"opinions": "opinions", "opinions": "opinions",
"oppozitsiya": "opposition", "oppozitsiya": "opposition",
"orhan-pamuk": "orhan-pamuk", "orhan-pamuk": "orhan-pamuk",
@ -779,6 +783,7 @@
"vladimir-putin": "vladimir-putin", "vladimir-putin": "vladimir-putin",
"vladimir-sorokin": "vladimir-sorokin", "vladimir-sorokin": "vladimir-sorokin",
"vladimir-voynovich": "vladimir-voynovich", "vladimir-voynovich": "vladimir-voynovich",
"vnutrenniy-opyt": "inner-expirience",
"volga": "volga", "volga": "volga",
"volontery": "volonteurs", "volontery": "volonteurs",
"vong-karvay": "wong-karwai", "vong-karvay": "wong-karwai",

View File

@ -1,6 +1,6 @@
from datetime import datetime from datetime import datetime
from sqlalchemy import Column, String, ForeignKey, DateTime from sqlalchemy import Column, DateTime, ForeignKey, String
from base.orm import Base from base.orm import Base
@ -16,8 +16,7 @@ class ShoutCollection(Base):
class Collection(Base): class Collection(Base):
__tablename__ = "collection" __tablename__ = "collection"
id = None # type: ignore slug = Column(String, unique=True)
slug = Column(String, primary_key=True)
title = Column(String, nullable=False, comment="Title") title = Column(String, nullable=False, comment="Title")
body = Column(String, nullable=True, comment="Body") body = Column(String, nullable=True, comment="Body")
pic = Column(String, nullable=True, comment="Picture") pic = Column(String, nullable=True, comment="Picture")

View File

@ -1,6 +1,6 @@
from datetime import datetime from datetime import datetime
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from base.orm import Base from base.orm import Base
@ -50,8 +50,7 @@ class ShoutAllowed(Base):
class Shout(Base): class Shout(Base):
__tablename__ = "shout" __tablename__ = "shout"
id = None # type: ignore slug = Column(String, unique=True)
slug = Column(String, primary_key=True)
community = Column(Integer, ForeignKey("community.id"), nullable=False, comment="Community") community = Column(Integer, ForeignKey("community.id"), nullable=False, comment="Community")
lang = Column(String, nullable=False, default='ru', comment="Language") lang = Column(String, nullable=False, default='ru', comment="Language")
body = Column(String, nullable=False, comment="Body") body = Column(String, nullable=False, comment="Body")

View File

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from sqlalchemy import Column, Boolean, String, ForeignKey, DateTime, JSON as JSONType from sqlalchemy import JSON as JSONType
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String
from base.orm import Base from base.orm import Base
@ -20,8 +21,7 @@ class TopicFollower(Base):
class Topic(Base): class Topic(Base):
__tablename__ = "topic" __tablename__ = "topic"
id = None # type: ignore slug = Column(String, unique=True)
slug = Column(String, primary_key=True)
title = Column(String, nullable=False, comment="Title") title = Column(String, nullable=False, comment="Title")
body = Column(String, nullable=True, comment="Body") body = Column(String, nullable=True, comment="Body")
pic = Column(String, nullable=True, comment="Picture") pic = Column(String, nullable=True, comment="Picture")

View File

@ -1,14 +1,7 @@
from datetime import datetime from datetime import datetime
from sqlalchemy import ( from sqlalchemy import JSON as JSONType
Column, from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
Integer,
String,
ForeignKey,
Boolean,
DateTime,
JSON as JSONType,
)
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from base.orm import Base, local_session from base.orm import Base, local_session

View File

@ -1,27 +1,22 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from urllib.parse import quote_plus
from datetime import datetime from datetime import datetime
from urllib.parse import quote_plus
from graphql.type import GraphQLResolveInfo from graphql.type import GraphQLResolveInfo
from transliterate import translit
from starlette.responses import RedirectResponse from starlette.responses import RedirectResponse
from transliterate import translit
from auth.jwtcodec import JWTCodec
from auth.tokenstorage import TokenStorage
from auth.authenticate import login_required from auth.authenticate import login_required
from auth.email import send_auth_email from auth.email import send_auth_email
from auth.identity import Identity, Password from auth.identity import Identity, Password
from base.exceptions import ( from auth.jwtcodec import JWTCodec
BaseHttpException, from auth.tokenstorage import TokenStorage
InvalidPassword, from base.exceptions import (BaseHttpException, InvalidPassword, InvalidToken,
InvalidToken, ObjectNotExist, OperationNotAllowed)
ObjectNotExist,
OperationNotAllowed,
)
from base.orm import local_session from base.orm import local_session
from base.resolvers import mutation, query from base.resolvers import mutation, query
from orm import User, Role from orm import Role, User
from resolvers.profile import user_subscriptions from resolvers.profile import user_subscriptions

View File

@ -45,6 +45,7 @@ async def user_unpublished_shouts(_, info, offset, limit) -> List[Shout]:
.join(ShoutAuthor) .join(ShoutAuthor)
.where(and_(Shout.publishedAt.is_(None), ShoutAuthor.user == user.slug)) .where(and_(Shout.publishedAt.is_(None), ShoutAuthor.user == user.slug))
.order_by(desc(Shout.createdAt)) .order_by(desc(Shout.createdAt))
.group_by(Shout.id)
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.all() .all()

View File

@ -317,7 +317,7 @@ type UserNotification {
type User { type User {
id: Int! id: Int!
username: String! # to login, ex. email username: String! # to login, ex. email, phone
createdAt: DateTime! createdAt: DateTime!
lastSeen: DateTime lastSeen: DateTime
slug: String! slug: String!
@ -383,6 +383,7 @@ type Reaction {
} }
type Author { type Author {
id: Int!
slug: String! slug: String!
name: String! name: String!
userpic: String userpic: String
@ -427,6 +428,7 @@ type Stat {
} }
type Community { type Community {
id: Int!
slug: String! slug: String!
name: String! name: String!
desc: String desc: String
@ -436,6 +438,7 @@ type Community {
} }
type Collection { type Collection {
id: Int!
slug: String! slug: String!
title: String! title: String!
desc: String desc: String

View File

@ -58,6 +58,7 @@ class ShoutsCache:
) )
.where(Shout.deletedAt.is_(None)) .where(Shout.deletedAt.is_(None))
.filter(Shout.publishedAt.is_not(None)) .filter(Shout.publishedAt.is_not(None))
.group_by(Shout.id)
.order_by(desc("publishedAt")) .order_by(desc("publishedAt"))
# .limit(ShoutsCache.limit) # .limit(ShoutsCache.limit)
), ),
@ -87,6 +88,7 @@ class ShoutsCache:
selectinload(Shout.topics) selectinload(Shout.topics)
) )
.where(Shout.deletedAt.is_(None)) .where(Shout.deletedAt.is_(None))
.group_by(Shout.id)
.order_by(desc("createdAt")) .order_by(desc("createdAt"))
# .limit(ShoutsCache.limit) # .limit(ShoutsCache.limit)
) )
@ -118,7 +120,7 @@ class ShoutsCache:
.join(Reaction) .join(Reaction)
.where(and_(Shout.deletedAt.is_(None), Shout.slug.in_(reacted_slugs))) .where(and_(Shout.deletedAt.is_(None), Shout.slug.in_(reacted_slugs)))
.filter(Shout.publishedAt.is_not(None)) .filter(Shout.publishedAt.is_not(None))
.group_by(Shout.slug, "reactedAt") .group_by(Shout.id, "reactedAt")
.order_by(desc("reactedAt")) .order_by(desc("reactedAt"))
# .limit(ShoutsCache.limit) # .limit(ShoutsCache.limit)
) )
@ -150,7 +152,7 @@ class ShoutsCache:
) )
.join(Reaction) .join(Reaction)
.where(and_(Shout.deletedAt.is_(None), Shout.slug.in_(commented_slugs))) .where(and_(Shout.deletedAt.is_(None), Shout.slug.in_(commented_slugs)))
.group_by(Shout.slug, "reactedAt") .group_by(Shout.id, "reactedAt")
.order_by(desc("reactedAt")) .order_by(desc("reactedAt"))
# .limit(ShoutsCache.limit) # .limit(ShoutsCache.limit)
) )
@ -177,7 +179,7 @@ class ShoutsCache:
.join(Reaction, Reaction.kind == ReactionKind.LIKE) .join(Reaction, Reaction.kind == ReactionKind.LIKE)
.where(Shout.deletedAt.is_(None)) .where(Shout.deletedAt.is_(None))
.filter(Shout.publishedAt.is_not(None)) .filter(Shout.publishedAt.is_not(None))
.group_by(Shout.slug) .group_by(Shout.id)
.order_by(desc("reacted")) .order_by(desc("reacted"))
# .limit(ShoutsCache.limit) # .limit(ShoutsCache.limit)
), ),
@ -203,7 +205,7 @@ class ShoutsCache:
.join(Reaction) .join(Reaction)
.where(Shout.deletedAt.is_(None)) .where(Shout.deletedAt.is_(None))
.filter(Shout.publishedAt > month_ago) .filter(Shout.publishedAt > month_ago)
.group_by(Shout.slug) .group_by(Shout.id)
# .limit(ShoutsCache.limit) # .limit(ShoutsCache.limit)
), ),
) )
@ -231,7 +233,7 @@ class ShoutsCache:
.join(Reaction, func.length(Reaction.body) > 0) .join(Reaction, func.length(Reaction.body) > 0)
.where(Shout.deletedAt.is_(None)) .where(Shout.deletedAt.is_(None))
.filter(Shout.publishedAt > month_ago) .filter(Shout.publishedAt > month_ago)
.group_by(Shout.slug) .group_by(Shout.id)
.order_by(desc("commented")) .order_by(desc("commented"))
# .limit(ShoutsCache.limit) # .limit(ShoutsCache.limit)
), ),