Compare commits
No commits in common. "855c36c38cd3b09e09c580f38d23852b70e0d1d8" and "e82c1ab94e6cf6d81acb694542bfd5e02b6481b2" have entirely different histories.
855c36c38c
...
e82c1ab94e
4 changed files with 69 additions and 71 deletions
|
@ -6,7 +6,7 @@ from sqlalchemy import MetaData
|
|||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from sqlalchemy.orm import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from app.config import DB_PATH
|
||||
|
@ -25,9 +25,7 @@ async_engine = create_async_engine(
|
|||
)
|
||||
async_session = sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
Base: Any = declarative_base()
|
||||
metadata_obj = MetaData()
|
||||
|
||||
async def get_db_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
|
|
130
app/models.py
130
app/models.py
|
@ -10,7 +10,7 @@ from app.database import metadata_obj
|
|||
from app.activitypub import BaseActor
|
||||
from app.ap_object import BaseObject
|
||||
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy import Boolean
|
||||
from sqlalchemy import DateTime
|
||||
from sqlalchemy import Enum
|
||||
|
@ -32,46 +32,46 @@ def now() -> dtime:
|
|||
class Actor(Base, BaseActor):
|
||||
__tablename__ = "actor"
|
||||
|
||||
id = mapped_column(Integer, primary_key=True, index=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
|
||||
ap_id = mapped_column(String, unique=True, nullable=False, index=True)
|
||||
ap_actor = mapped_column(JSON, nullable=False)
|
||||
ap_type = mapped_column(String, nullable=False)
|
||||
ap_id = Column(String, unique=True, nullable=False, index=True)
|
||||
ap_actor = Column(JSON, nullable=False)
|
||||
ap_type = Column(String, nullable=False)
|
||||
|
||||
handle = mapped_column(String, nullable=True, index=True)
|
||||
handle = Column(String, nullable=True, index=True)
|
||||
|
||||
is_blocked = mapped_column(Boolean, nullable=False, default=False, server_default="0")
|
||||
is_deleted = mapped_column(Boolean, nullable=False, default=False, server_default="0")
|
||||
is_blocked = Column(Boolean, nullable=False, default=False, server_default="0")
|
||||
is_deleted = Column(Boolean, nullable=False, default=False, server_default="0")
|
||||
|
||||
|
||||
class InboxObject(Base, BaseObject):
|
||||
__tablename__ = "inbox"
|
||||
|
||||
id = mapped_column(Integer, primary_key=True, index=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
|
||||
actor_id = mapped_column(Integer, ForeignKey("actor.id"), nullable=False)
|
||||
actor_id = Column(Integer, ForeignKey("actor.id"), nullable=False)
|
||||
actor: Mapped[Actor] = relationship(Actor, uselist=False)
|
||||
|
||||
server = mapped_column(String, nullable=False)
|
||||
server = Column(String, nullable=False)
|
||||
|
||||
is_hidden_from_stream = mapped_column(Boolean, nullable=False, default=False)
|
||||
is_hidden_from_stream = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
ap_actor_id = mapped_column(String, nullable=False)
|
||||
ap_type = mapped_column(String, nullable=False, index=True)
|
||||
ap_id = mapped_column(String, nullable=False, unique=True, index=True)
|
||||
ap_context = mapped_column(String, nullable=True)
|
||||
ap_published_at = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
ap_object = mapped_column(JSON, nullable=False)
|
||||
activity_object_ap_id = mapped_column(String, nullable=True, index=True)
|
||||
ap_actor_id = Column(String, nullable=False)
|
||||
ap_type = Column(String, nullable=False, index=True)
|
||||
ap_id = Column(String, nullable=False, unique=True, index=True)
|
||||
ap_context = Column(String, nullable=True)
|
||||
ap_published_at = Column(DateTime(timezone=True), nullable=False)
|
||||
ap_object = Column(JSON, nullable=False)
|
||||
activity_object_ap_id = Column(String, nullable=True, index=True)
|
||||
|
||||
visibility = mapped_column(Enum(ap.VisibilityEnum), nullable=False)
|
||||
visibility = Column(Enum(ap.VisibilityEnum), nullable=False)
|
||||
|
||||
is_deleted = mapped_column(Boolean, nullable=False, default=False)
|
||||
relates_to_inbox_object_id = mapped_column(
|
||||
is_deleted = Column(Boolean, nullable=False, default=False)
|
||||
relates_to_inbox_object_id = Column(
|
||||
Integer,
|
||||
ForeignKey("inbox.id"),
|
||||
nullable=True,
|
||||
|
@ -82,7 +82,7 @@ class InboxObject(Base, BaseObject):
|
|||
remote_side=id,
|
||||
uselist=False,
|
||||
)
|
||||
relates_to_outbox_object_id = mapped_column(
|
||||
relates_to_outbox_object_id = Column(
|
||||
Integer,
|
||||
ForeignKey("outbox.id", use_alter=True),
|
||||
nullable=True,
|
||||
|
@ -97,28 +97,28 @@ class InboxObject(Base, BaseObject):
|
|||
class OutboxObject(Base, BaseObject):
|
||||
__tablename__ = "outbox"
|
||||
|
||||
id = mapped_column(Integer, primary_key=True, index=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
|
||||
public_id = mapped_column(String, nullable=False, index=True)
|
||||
slug = mapped_column(String, nullable=True, index=True)
|
||||
public_id = Column(String, nullable=False, index=True)
|
||||
slug = Column(String, nullable=True, index=True)
|
||||
|
||||
ap_type = mapped_column(String, nullable=False, index=True)
|
||||
ap_id = mapped_column(String, nullable=False, unique=True, index=True)
|
||||
ap_context = mapped_column(String, nullable=True)
|
||||
ap_object = mapped_column(JSON, nullable=False)
|
||||
ap_type = Column(String, nullable=False, index=True)
|
||||
ap_id = Column(String, nullable=False, unique=True, index=True)
|
||||
ap_context = Column(String, nullable=True)
|
||||
ap_object = Column(JSON, nullable=False)
|
||||
|
||||
activity_object_ap_id = mapped_column(String, nullable=True, index=True)
|
||||
activity_object_ap_id = Column(String, nullable=True, index=True)
|
||||
|
||||
visibility = mapped_column(Enum(ap.VisibilityEnum), nullable=False)
|
||||
visibility = Column(Enum(ap.VisibilityEnum), nullable=False)
|
||||
|
||||
is_deleted = mapped_column(Boolean, nullable=False, default=False)
|
||||
likes_count = mapped_column(Integer, nullable=False, default=0)
|
||||
announces_count = mapped_column(Integer, nullable=False, default=0)
|
||||
replies_count = mapped_column(Integer, nullable=False, default=0)
|
||||
is_deleted = Column(Boolean, nullable=False, default=False)
|
||||
likes_count = Column(Integer, nullable=False, default=0)
|
||||
announces_count = Column(Integer, nullable=False, default=0)
|
||||
replies_count = Column(Integer, nullable=False, default=0)
|
||||
|
||||
relates_to_inbox_object_id = mapped_column(
|
||||
relates_to_inbox_object_id = Column(
|
||||
Integer,
|
||||
ForeignKey("inbox.id", use_alter=True),
|
||||
nullable=True,
|
||||
|
@ -128,7 +128,7 @@ class OutboxObject(Base, BaseObject):
|
|||
foreign_keys=relates_to_inbox_object_id,
|
||||
uselist=False,
|
||||
)
|
||||
relates_to_outbox_object_id = mapped_column(
|
||||
relates_to_outbox_object_id = Column(
|
||||
Integer,
|
||||
ForeignKey("outbox.id"),
|
||||
nullable=True,
|
||||
|
@ -140,7 +140,7 @@ class OutboxObject(Base, BaseObject):
|
|||
uselist=False,
|
||||
)
|
||||
|
||||
relates_to_actor_id = mapped_column(
|
||||
relates_to_actor_id = Column(
|
||||
Integer,
|
||||
ForeignKey("actor.id"),
|
||||
nullable=True,
|
||||
|
@ -155,50 +155,50 @@ class OutboxObject(Base, BaseObject):
|
|||
class IncomingActivity(Base):
|
||||
__tablename__ = "ingress"
|
||||
|
||||
id = mapped_column(Integer, primary_key=True, index=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
|
||||
ap_id = mapped_column(String, nullable=True, index=True)
|
||||
ap_object = mapped_column(JSON, nullable=True)
|
||||
ap_id = Column(String, nullable=True, index=True)
|
||||
ap_object = Column(JSON, nullable=True)
|
||||
|
||||
|
||||
class OutcomingActivity(Base):
|
||||
__tablename__ = "push"
|
||||
|
||||
id = mapped_column(Integer, primary_key=True, index=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
|
||||
ap_id = mapped_column(String, nullable=True, index=True)
|
||||
ap_object = mapped_column(JSON, nullable=True)
|
||||
ap_id = Column(String, nullable=True, index=True)
|
||||
ap_object = Column(JSON, nullable=True)
|
||||
|
||||
|
||||
class Follower(Base):
|
||||
__tablename__ = "follower"
|
||||
|
||||
id = mapped_column(Integer, primary_key=True, index=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
|
||||
actor_id = mapped_column(Integer, ForeignKey("actor.id"), nullable=False, unique=True)
|
||||
actor_id = Column(Integer, ForeignKey("actor.id"), nullable=False, unique=True)
|
||||
actor: Mapped[Actor] = relationship(Actor, uselist=False)
|
||||
|
||||
inbox_object_id = mapped_column(Integer, ForeignKey("inbox.id"), nullable=False)
|
||||
inbox_object_id = Column(Integer, ForeignKey("inbox.id"), nullable=False)
|
||||
inbox_object = relationship(InboxObject, uselist=False)
|
||||
|
||||
ap_actor_id = mapped_column(String, nullable=False, unique=True)
|
||||
ap_actor_id = Column(String, nullable=False, unique=True)
|
||||
|
||||
|
||||
class Following(Base):
|
||||
__tablename__ = "following"
|
||||
|
||||
id = mapped_column(Integer, primary_key=True, index=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = mapped_column(DateTime(timezone=True), nullable=False, default=now)
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
updated_at = Column(DateTime(timezone=True), nullable=False, default=now)
|
||||
|
||||
actor_id = mapped_column(Integer, ForeignKey("actor.id"), nullable=False, unique=True)
|
||||
actor_id = Column(Integer, ForeignKey("actor.id"), nullable=False, unique=True)
|
||||
actor: Mapped[Actor] = relationship(Actor, uselist=False)
|
||||
|
||||
outbox_object_id = mapped_column(Integer, ForeignKey("outbox.id"), nullable=False)
|
||||
outbox_object_id = Column(Integer, ForeignKey("outbox.id"), nullable=False)
|
||||
outbox_object = relationship(OutboxObject, uselist=False)
|
||||
|
||||
ap_actor_id = mapped_column(String, nullable=False, unique=True)
|
||||
ap_actor_id = Column(String, nullable=False, unique=True)
|
||||
|
|
2
poetry.lock
generated
2
poetry.lock
generated
|
@ -1981,4 +1981,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">3.11, <3.13"
|
||||
content-hash = "a5a79aad191dfc8d9fd0dfa18e8a16cc72d5e4ddf6313aad512eb339a3c8dda9"
|
||||
content-hash = "88180fc69bca605f3f6a80d8e62a8e959731763ad3a13bc74fb1a41ebca40487"
|
||||
|
|
|
@ -11,7 +11,7 @@ fastapi = "^0.111.0"
|
|||
httpx = "^0.27.0"
|
||||
uvicorn = "^0.30.1"
|
||||
loguru = "^0.7.2"
|
||||
sqlalchemy = "^2.0.35"
|
||||
sqlalchemy = "^2.0.27"
|
||||
aiosqlite = "^0.20.0"
|
||||
alembic = "^1.13.1"
|
||||
tomli = "^2.0.1"
|
||||
|
|
Loading…
Reference in a new issue