Skip to content

cattle_grid.database

account

Account

Bases: Base

Represents an account

Source code in cattle_grid/database/account.py
class Account(Base):
    """Represents an account"""

    __tablename__ = "account"
    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(256))
    password_hash: Mapped[str] = mapped_column(String(256))
    meta_information: Mapped[dict] = mapped_column(JSON(), default={})

    actors: Mapped[list["ActorForAccount"]] = relationship(viewonly=True)
    permissions: Mapped[list["Permission"]] = relationship(viewonly=True)

ActorForAccount

Bases: Base

Represents the actor associated with an account

Source code in cattle_grid/database/account.py
class ActorForAccount(Base):
    """Represents the actor associated with an account"""

    __tablename__ = "actorforaccount"
    id: Mapped[int] = mapped_column(primary_key=True)
    account_id: Mapped[int] = mapped_column(
        ForeignKey("account.id", ondelete="CASCADE")
    )
    account: Mapped[Account] = relationship(lazy="joined")

    actor: Mapped[str] = mapped_column(String(256))
    name: Mapped[str] = mapped_column(
        String(256),
        default="NO NAME",
    )
    status: Mapped[ActorStatus] = mapped_column(String(10), default=ActorStatus.active)

    groups: Mapped[list["ActorGroup"]] = relationship(viewonly=True)

ActorStatus

Bases: StrEnum

Status actors can have for an account

Source code in cattle_grid/database/account.py
class ActorStatus(StrEnum):
    """Status actors can have for an account"""

    active = auto()
    deleted = auto()

activity_pub

Credential

Bases: Base

Stored credential. This corresponds to storing a private key

Source code in cattle_grid/database/activity_pub.py
class Credential(Base):
    """Stored credential. This corresponds to storing a private key"""

    __tablename__ = "credential"

    id: Mapped[int] = mapped_column(primary_key=True)
    actor_id: Mapped[str] = mapped_column(String(256))
    identifier: Mapped[str] = mapped_column(String(256), unique=True)
    secret: Mapped[str] = mapped_column(Text())

InboxLocation

Bases: Base

Describes the location of an inbox. Used to send ActivityPub Activities addressed to the actor to the corresponding inbox.

This information is also collected for remote actors.

Source code in cattle_grid/database/activity_pub.py
class InboxLocation(Base):
    """Describes the location of an inbox. Used to send
    ActivityPub Activities addressed to the actor to the
    corresponding inbox.

    This information is also collected for remote actors.
    """

    __tablename__ = "inboxlocation"

    id: Mapped[int] = mapped_column(primary_key=True)
    actor: Mapped[str] = mapped_column(String(256), unique=True)
    inbox: Mapped[str] = mapped_column(String(256))

activity_pub_actor

Actor

Bases: Base

Represents the stored information about an actor in the database

Source code in cattle_grid/database/activity_pub_actor.py
class Actor(Base):
    """Represents the stored information about an actor in the database"""

    __tablename__ = "actor"

    id: Mapped[int] = mapped_column(primary_key=True)
    actor_id: Mapped[str] = mapped_column(String(256), unique=True)
    inbox_uri: Mapped[str] = mapped_column(String(256), unique=True)
    outbox_uri: Mapped[str] = mapped_column(String(256), unique=True)
    following_uri: Mapped[str] = mapped_column(String(256), unique=True)
    followers_uri: Mapped[str] = mapped_column(String(256), unique=True)

    preferred_username: Mapped[str] = mapped_column(String(256), nullable=True)

    public_key_name: Mapped[str] = mapped_column(String(256))
    public_key: Mapped[str] = mapped_column(Text())

    automatically_accept_followers: Mapped[bool] = mapped_column(Boolean())
    profile: Mapped[dict] = mapped_column(JSON())

    status: Mapped[ActorStatus] = mapped_column(String(7))

    created_at: Mapped[datetime] = mapped_column(server_default=func.now())

    identifiers: Mapped[list["PublicIdentifier"]] = relationship(viewonly=True)
    followers: Mapped[list["Follower"]] = relationship(viewonly=True)
    following: Mapped[list["Following"]] = relationship(viewonly=True)
    blocking: Mapped[list["Blocking"]] = relationship(viewonly=True)

ActorStatus

Bases: StrEnum

Represents the status of the actor

Source code in cattle_grid/database/activity_pub_actor.py
class ActorStatus(StrEnum):
    """Represents the status of the actor"""

    active = auto()
    deleted = auto()

Blocking

Bases: Base

The people the actor is blocking

Source code in cattle_grid/database/activity_pub_actor.py
class Blocking(Base):
    """The people the actor is blocking"""

    __tablename__ = "blocking"
    id: Mapped[int] = mapped_column(primary_key=True)
    actor_id: Mapped[int] = mapped_column(ForeignKey("actor.id", ondelete="CASCADE"))
    actor: Mapped[Actor] = relationship(lazy="joined")

    blocking: Mapped[str] = mapped_column(String(256))
    request: Mapped[str] = mapped_column(String(256))
    active: Mapped[bool] = mapped_column(Boolean())

Follower

Bases: Base

The people that follow the actor

Source code in cattle_grid/database/activity_pub_actor.py
class Follower(Base):
    """The people that follow the actor"""

    __tablename__ = "follower"
    id: Mapped[int] = mapped_column(primary_key=True)
    actor_id: Mapped[int] = mapped_column(ForeignKey("actor.id", ondelete="CASCADE"))
    actor: Mapped[Actor] = relationship(lazy="joined")

    follower: Mapped[str] = mapped_column(String(256))
    request: Mapped[str] = mapped_column(String(256))
    accepted: Mapped[bool] = mapped_column(Boolean())

Following

Bases: Base

The people the actor is following

Source code in cattle_grid/database/activity_pub_actor.py
class Following(Base):
    """The people the actor is following"""

    __tablename__ = "following"
    id: Mapped[int] = mapped_column(primary_key=True)
    actor_id: Mapped[int] = mapped_column(ForeignKey("actor.id", ondelete="CASCADE"))
    actor: Mapped[Actor] = relationship(lazy="joined")

    following: Mapped[str] = mapped_column(String(256))
    request: Mapped[str] = mapped_column(String(256))
    accepted: Mapped[bool] = mapped_column(Boolean())

PublicIdentifier

Bases: Base

Public identifier

Source code in cattle_grid/database/activity_pub_actor.py
class PublicIdentifier(Base):
    """Public identifier"""

    __tablename__ = "publicidentifier"
    id: Mapped[int] = mapped_column(primary_key=True)
    actor_id: Mapped[int] = mapped_column(ForeignKey("actor.id", ondelete="CASCADE"))
    actor: Mapped[Actor] = relationship(lazy="joined")

    name: Mapped[str] = mapped_column(String(256))
    identifier: Mapped[str] = mapped_column(String(256), unique=True)
    preference: Mapped[int] = mapped_column(default=0)
    status: Mapped[PublicIdentifierStatus] = mapped_column(
        String(10), default=PublicIdentifierStatus.verified
    )

PublicIdentifierStatus

Bases: StrEnum

Represents the status of the public identifier

Source code in cattle_grid/database/activity_pub_actor.py
class PublicIdentifierStatus(StrEnum):
    """Represents the status of the public identifier"""

    unverified = auto()
    verified = auto()
    owned = auto()

StoredActivity

Bases: Base

cattle_grid generates activities under some circumstances (see FIXME). These will be stored in this table

Source code in cattle_grid/database/activity_pub_actor.py
class StoredActivity(Base):
    """cattle_grid generates activities under some
    circumstances (see FIXME). These will be stored
    in this table"""

    __tablename__ = "storedactivity"
    id: Mapped[str] = mapped_column(String(256), primary_key=True)
    actor_id: Mapped[int] = mapped_column(ForeignKey("actor.id", ondelete="CASCADE"))
    actor: Mapped[Actor] = relationship(lazy="joined")

    data: Mapped[dict] = mapped_column(JSON())
    published: Mapped[datetime] = mapped_column()

auth

RemoteIdentity

Bases: Base

Stored information about a public identifier in the database.

Source code in cattle_grid/database/auth.py
class RemoteIdentity(Base):
    """Stored information about a public identifier in the database."""

    __tablename__ = "cattle_grid_auth_remote_identity"

    id: Mapped[int] = mapped_column(primary_key=True)

    key_id: Mapped[str] = mapped_column(String(512), unique=True)
    controller: Mapped[str] = mapped_column(String(512))
    public_key: Mapped[str] = mapped_column(String(1024))