Migration fix, notification schema update

This commit is contained in:
Igor Lobanov 2023-10-09 12:52:13 +02:00
parent a9b26254ce
commit 6e149432c1
4 changed files with 328 additions and 304 deletions

View File

@ -70,7 +70,6 @@ def create_author_from_app(app):
"username": app["email"], "username": app["email"],
"email": app["email"], "email": app["email"],
"name": app.get("name", ""), "name": app.get("name", ""),
"bio": app.get("bio", ""),
"emailConfirmed": False, "emailConfirmed": False,
"slug": slug, "slug": slug,
"createdAt": ts, "createdAt": ts,
@ -149,6 +148,7 @@ async def migrate(entry, storage):
"deletedAt": date_parse(entry.get("deletedAt")) if entry.get("deletedAt") else None, "deletedAt": date_parse(entry.get("deletedAt")) if entry.get("deletedAt") else None,
"createdAt": date_parse(entry.get("createdAt", OLD_DATE)), "createdAt": date_parse(entry.get("createdAt", OLD_DATE)),
"updatedAt": date_parse(entry["updatedAt"]) if "updatedAt" in entry else ts, "updatedAt": date_parse(entry["updatedAt"]) if "updatedAt" in entry else ts,
"createdBy": author.id,
"topics": await add_topics_follower(entry, storage, author), "topics": await add_topics_follower(entry, storage, author),
"body": extract_html(entry, cleanup=True) "body": extract_html(entry, cleanup=True)
} }

View File

@ -21,7 +21,6 @@ def migrate(entry):
"createdAt": parse(entry["createdAt"]), "createdAt": parse(entry["createdAt"]),
"emailConfirmed": ("@discours.io" in email) or bool(entry["emails"][0]["verified"]), "emailConfirmed": ("@discours.io" in email) or bool(entry["emails"][0]["verified"]),
"muted": False, # amnesty "muted": False, # amnesty
"bio": entry["profile"].get("bio", ""),
"links": [], "links": [],
"name": "anonymous", "name": "anonymous",
"password": entry["services"]["password"].get("bcrypt") "password": entry["services"]["password"].get("bcrypt")
@ -29,7 +28,7 @@ def migrate(entry):
if "updatedAt" in entry: if "updatedAt" in entry:
user_dict["updatedAt"] = parse(entry["updatedAt"]) user_dict["updatedAt"] = parse(entry["updatedAt"])
if "wasOnineAt" in entry: if "wasOnlineAt" in entry:
user_dict["lastSeen"] = parse(entry["wasOnlineAt"]) user_dict["lastSeen"] = parse(entry["wasOnlineAt"])
if entry.get("profile"): if entry.get("profile"):
# slug # slug

View File

@ -1,13 +1,22 @@
from datetime import datetime from datetime import datetime
from sqlalchemy import Column, String, JSON, ForeignKey, DateTime, Boolean from sqlalchemy import Column, Enum, JSON, ForeignKey, DateTime, Boolean, Integer
from base.orm import Base from base.orm import Base
from enum import Enum as Enumeration
class NotificationType(Enumeration):
NEW_COMMENT = 1
NEW_REPLY = 2
class Notification(Base): class Notification(Base):
__tablename__ = "notification" __tablename__ = "notification"
shout = Column(ForeignKey("shout.id"), index=True)
reaction = Column(ForeignKey("reaction.id"), index=True)
user = Column(ForeignKey("user.id"), index=True) user = Column(ForeignKey("user.id"), index=True)
createdAt = Column(DateTime, nullable=False, default=datetime.now, index=True) createdAt = Column(DateTime, nullable=False, default=datetime.now, index=True)
seen = Column(Boolean, nullable=False, default=False, index=True) seen = Column(Boolean, nullable=False, default=False, index=True)
type = Column(String, nullable=False) type = Column(Enum(NotificationType), nullable=False)
data = Column(JSON, nullable=True) data = Column(JSON, nullable=True)
occurrences = Column(Integer, default=1)

View File

@ -500,3 +500,19 @@ type Chat {
unread: Int unread: Int
private: Boolean private: Boolean
} }
enum NotificationType {
NEW_COMMENT,
NEW_REPLY
}
type Notification {
id: Int!
shout: Int
reaction: Int
type: NotificationType
createdAt: DateTime!
seen: Boolean!
data: String # JSON
occurrences: Int!
}