示例#1
0
class IsochroneCalculation(SQLModel, table=True):
    __tablename__ = "isochrone_calculation"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(
        sa_column=Column(Integer, primary_key=True, autoincrement=True))
    calculation_type: str = Field(sa_column=Column(Text, nullable=False))
    starting_point: str = Field(sa_column=Column(Text, nullable=False))
    routing_profile: str = Field(sa_column=Column(Text, nullable=False))
    speed: float = Field(sa_column=Column(Float(53), nullable=False))
    modus: str = Field(sa_column=Column(Text, nullable=False))
    creation_date: Optional[datetime] = Field(
        sa_column=Column(DateTime, server_default=text("CURRENT_TIMESTAMP")))
    parent_id: Optional[int] = Field(sa_column=Column(
        Integer,
        ForeignKey("customer.isochrone_calculation.id", ondelete="CASCADE")))
    scenario_id: Optional[int] = Field(sa_column=Column(
        Integer, ForeignKey("customer.scenario.id", ondelete="CASCADE")))
    user_id: int = Field(
        sa_column=Column(Integer,
                         ForeignKey("customer.user.id", ondelete="CASCADE"),
                         nullable=False))

    scenario: Optional["Scenario"] = Relationship(
        back_populates="isochrone_calculations")
    user: "******" = Relationship(back_populates="isochrone_calculations")
    isochrone_features: "IsochroneFeature" = Relationship(
        back_populates="isochrone_calculation")
示例#2
0
class Server(SQLModel, table=True):
    id: Optional[int] = Field(
        sa_column=Column(Integer, primary_key=True, unique=True),
        description="ID of server",
        gt=0,
        le=INTEGER_SIZE,
    )
    name: str = Field(
        sa_column=Column(String(255), nullable=False),
        description="Name of server from Discord",
    )
    icon: Optional[str] = Field(
        sa_column=Column(String(64)), description="Icon of server from Discord"
    )
    discord_id: str = Field(
        sa_column=Column(String(64), nullable=False, unique=True),
        alias="discordId",
        description="Discord ID of server",
    )
    channels: List["Channel"] = Relationship(
        sa_relationship=relationship(
            "Channel", back_populates="server", cascade="all, delete-orphan"
        )
    )
    players: List["Player"] = Relationship(
        sa_relationship=relationship(
            "Player", secondary=player_server_association, back_populates="servers"
        )
    )

    class Config:
        orm_mode = True
        allow_population_by_field_name = True
示例#3
0
class Video(VideoBase, table=True):
    user_id: uuid.UUID = Field(foreign_key='user.id', nullable=False, description='User primary key')
    user: User = Relationship(back_populates='videos')
    thumbnail_uri: Optional[str] = Field(default=None, nullable=True)

    tags: List[Tag] = Relationship(back_populates='videos', link_model=VideoTagLink)
    likes: List[User] = Relationship(back_populates='liked_videos', link_model=VideoLikeLink)
示例#4
0
class UserCustomization(SQLModel, table=True):
    __tablename__ = "user_customization"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(sa_column=Column(Integer, primary_key=True, autoincrement=True))
    setting: dict = Field(sa_column=Column(JSONB, nullable=False))
    creation_date: Optional[datetime] = Field(
        sa_column=Column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
    )
    user_id: int = Field(
        sa_column=Column(
            Integer, ForeignKey("customer.user.id", ondelete="CASCADE"), nullable=False
        )
    )
    customization_id: int = Field(
        sa_column=Column(
            Integer, ForeignKey("customer.customization.id", ondelete="CASCADE"), nullable=False
        )
    )
    study_area_id: int = Field(
        sa_column=Column(
            Integer, ForeignKey("basic.study_area.id"), nullable=False
        )
    )
    customizations: "Customization" = Relationship(back_populates="user_customizations")
    users: "User" = Relationship(back_populates="user_customizations")
    study_areas: "StudyArea" = Relationship(back_populates="user_customizations")
示例#5
0
class DataUpload(SQLModel, table=True):

    __tablename__ = "data_upload"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(sa_column=Column(Integer, primary_key=True, autoincrement=True))
    data_type: str = Field(sa_column=Column(Text, nullable=False))
    upload_type: str = Field(sa_column=Column(Text, nullable=False))
    upload_grid_ids: Optional[List[str]] = Field(
        sa_column=Column(ARRAY(Text()), nullable=False, server_default=text("'{}'::text[]"))
    )
    upload_size: int = Field(nullable=False)
    creation_date: Optional[datetime] = Field(
        sa_column=Column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
    )
    user_id: int = Field(
        sa_column=Column(
            Integer, ForeignKey("customer.user.id", ondelete="CASCADE"), nullable=False
        )
    )
    study_area_id: int = Field(
        sa_column=Column(
            Integer, ForeignKey("basic.study_area.id"), nullable=False
        )
    )
    reached_poi_heatmap_computed: Optional[bool]

    user: "******" = Relationship(back_populates="data_uploads")
    study_area: "StudyArea" = Relationship(back_populates="data_uploads")
    pois_user: List["PoiUser"] = Relationship(back_populates="data_upload")
    aois_user: List["AoiUser"] = Relationship(back_populates="data_upload")
示例#6
0
class BuildingModified(BuildingBase, table=True):
    __tablename__ = "building_modified"
    __table_args__ = {"schema": "customer"}

    creation_date: Optional[datetime] = Field(
        sa_column=Column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
    )
    building_id: Optional[int] = Field(
        sa_column=Column(
            Integer, ForeignKey("basic.building.id", ondelete="CASCADE"), default=None
        ),
    )
    scenario_id: int = Field(
        sa_column=Column(
            Integer,
            ForeignKey("customer.scenario.id", ondelete="CASCADE"),
            index=True,
            nullable=False,
        ),
    )
    population: Optional[float] = Field(sa_column=Column(Float(53)))
    building: Optional["Building"] = Relationship(back_populates="buildings_modified")
    scenario: "Scenario" = Relationship(back_populates="buildings_modified")
    populations_modified: Optional[List["PopulationModified"]] = Relationship(
        back_populates="building_modified"
    )
    edit_type: str = Field(sa_column=Column(Text, nullable=False, index=True))
    outdated: Optional[bool] = Field(sa_column=Column(Boolean, default=False))
示例#7
0
class Building(BuildingBase, table=True):
    __tablename__ = "building"
    __table_args__ = {"schema": "basic"}

    osm_id: Optional[int]

    populations: List["Population"] = Relationship(back_populates="building")
    buildings_modified: List["BuildingModified"] = Relationship(back_populates="building")
示例#8
0
class User(UserBase, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    is_active: bool = True
    is_superuser: bool = False
    password_hash: str
    stripe_customer_id: Optional[str]

    resources: List["Resource"] = Relationship(back_populates="user")
    courses: List["Course"] = Relationship(back_populates="user")
示例#9
0
class Role(SQLModel, table=True):
    __tablename__ = "role"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(sa_column=Column(Integer, primary_key=True, autoincrement=True))
    name: str = Field(sa_column=Column(Text, nullable=False))

    customizations: List["Customization"] = Relationship(back_populates="role")
    users: List["User"] = Relationship(back_populates="roles", link_model=UserRole)
示例#10
0
class Resource(ResourceBase, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    votes: Optional[int] = Field(default=0)
    broken: Optional[int] = Field(default=0)

    user: User = Relationship(back_populates="resources")
    topics: List[Topic] = Relationship(
        back_populates="resources", link_model=ResourceTopicLink
    )
示例#11
0
class User(UserBase, table=True):
    """
    We store usernames just to be able to add likes, comments etc.
    All authentication is done through Cognito in AWS.
    I've decided to not have username as the primary key, since a username could change.
    """

    id: Optional[uuid.UUID] = Field(default_factory=uuid.uuid4, primary_key=True, index=True, nullable=False)
    videos: List['Video'] = Relationship(back_populates='user')
    liked_videos: List['Video'] = Relationship(back_populates='likes', link_model=VideoLikeLink)
示例#12
0
class Scenario(SQLModel, table=True):
    __tablename__ = "scenario"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(sa_column=Column(Integer, primary_key=True, autoincrement=True))
    scenario_name: str = Field(sa_column=Column(Text, nullable=False))
    routing_heatmap_computed: Optional[bool]
    creation_date: Optional[datetime] = Field(
        sa_column=Column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
    )
    user_id: int = Field(
        sa_column=Column(
            Integer, ForeignKey("customer.user.id", ondelete="CASCADE"), nullable=False
        ),
    )
    data_upload_ids: Optional[List[int]] = Field(
        sa_column=Column(ARRAY(Integer()), server_default=text("'{}'::int[]"))
    ) 
    study_area_id: int = Field(
        sa_column=Column(Integer, ForeignKey("basic.study_area.id"), nullable=False)
    )

    user: "******" = Relationship(back_populates="scenarios")
    isochrone_calculations: List["IsochroneCalculation"] = Relationship(back_populates="scenario")
    pois_modified: List["PoiModified"] = Relationship(back_populates="scenario")
    aois_modified: List["AoiModified"] = Relationship(back_populates="scenario")
    populations_modified: List["PopulationModified"] = Relationship(back_populates="scenario")
    buildings_modified: List["BuildingModified"] = Relationship(back_populates="scenario")
    edges: List["Edge"] = Relationship(back_populates="scenario")
    ways_modified: List["WayModified"] = Relationship(back_populates="scenario")
    nodes: List["Node"] = Relationship(back_populates="scenario")
示例#13
0
class OpportunityStudyAreaConfig(OpportunityConfigBase, table=True):
    __tablename__ = "opportunity_study_area_config"
    __table_args__ = {"schema": "basic"}

    opportunity_group_id: Optional[int] = Field(sa_column=Column(
        Integer, ForeignKey("basic.opportunity_group.id"), nullable=False))
    study_area_id: int = Field(sa_column=Column(
        Integer, ForeignKey("basic.study_area.id"), nullable=False))
    is_active: bool = Field(sa_column=Column(Boolean, nullable=False))
    study_area: "StudyArea" = Relationship(
        back_populates="opportunity_study_area_configs")

    opportunity_group: "OpportunityGroup" = Relationship(
        back_populates="opportunity_study_area_configs")
示例#14
0
class User(UserBase, table=True):
    __tablename__ = "user"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(
        sa_column=Column(Integer, primary_key=True, autoincrement=True))
    hashed_password: Optional[str] = Field(
        sa_column=Column(Text, nullable=False))
    is_active: Optional[bool] = Field(default=False)
    newsletter: Optional[bool] = Field(default=False)
    occupation: Optional[str] = Field(sa_column=Column(Text, nullable=True))
    domain: Optional[str] = Field(sa_column=Column(Text, nullable=True))
    creation_date: Optional[datetime] = Field(
        sa_column=Column(DateTime, server_default=text("CURRENT_TIMESTAMP")))
    organization_id: int = Field(sa_column=Column(
        Integer,
        ForeignKey("customer.organization.id", ondelete="CASCADE"),
        nullable=False))
    active_study_area_id: int = Field(sa_column=Column(
        Integer, ForeignKey("basic.study_area.id"), nullable=False))
    language_preference: str = Field(sa_column=Column(Text, nullable=False))

    organization: "Organization" = Relationship(back_populates="users")
    roles: List["Role"] = Relationship(back_populates="users",
                                       link_model=UserRole)
    scenarios: List["Scenario"] = Relationship(back_populates="user")
    study_areas: List["StudyArea"] = Relationship(back_populates="users",
                                                  link_model=UserStudyArea)
    data_uploads: List["DataUpload"] = Relationship(back_populates="user")
    isochrone_calculations: List["IsochroneCalculation"] = Relationship(
        back_populates="user")
    user_customizations: List["UserCustomization"] = Relationship(
        back_populates="users")
    opportunity_user_configs: List["OpportunityUserConfig"] = Relationship(
        back_populates="user")
示例#15
0
class Customization(SQLModel, table=True):
    __tablename__ = "customization"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(sa_column=Column(Integer, primary_key=True, autoincrement=True))
    type: str = Field(sa_column=Column(Text, nullable=False))
    setting: dict = Field(sa_column=Column(JSONB, nullable=False))
    role_id: int = Field(
        sa_column=Column(
            Integer, ForeignKey("customer.role.id", ondelete="CASCADE"), nullable=False
        )
    )

    role: "Role" = Relationship(back_populates="customizations")
    user_customizations: Optional[List["UserCustomization"]] = Relationship(back_populates="customizations")
示例#16
0
class ProblemProblemSetLink(ORMUtils, table=True):  # type: ignore[call-arg]
    __tablename__ = "problem_problem_set_links"

    problem_id: UUID = Field(sa_column=Column(GUID,
                                              ForeignKey("problems.id",
                                                         ondelete="CASCADE"),
                                              primary_key=True), )
    problem_set_id: UUID = Field(sa_column=Column(GUID,
                                                  ForeignKey(
                                                      "problem_sets.id",
                                                      ondelete="CASCADE"),
                                                  primary_key=True), )
    position: int = Field(index=True,
                          nullable=False,
                          sa_column_kwargs={"server_default": "0"})

    problem: "Problem" = Relationship(
        back_populates="problem_problem_set_links")
    problem_set: "ProblemSet" = Relationship(
        back_populates="problem_problem_set_links")

    @classmethod
    async def find_by_problem_set_and_problem(
            cls, problem_set: str,
            problem: str) -> Optional["ProblemProblemSetLink"]:
        # this is buggy, do not use!
        # not sure how much it's better than three queries (maybe even worse)

        from joj.horse import models

        statement = cls.sql_select().options(
            joinedload(cls.problem_set, innerjoin=True),
            joinedload(cls.problem, innerjoin=True),
        )
        if is_uuid(problem_set):
            statement = statement.where(cls.problem_set_id == problem_set)
        else:
            statement = statement.where(models.ProblemSet.url == problem_set)
        if is_uuid(problem):
            statement = statement.where(cls.problem_id == problem)
        else:
            statement = statement.where(models.Problem.url == problem)
        from loguru import logger

        logger.info(statement)
        result = await cls.session_exec(statement)
        logger.info(result.all())
        return result.one_or_none()
示例#17
0
class Role(SQLModel, table=True):
    id: Optional[int] = Field(
        sa_column=Column(Integer, primary_key=True, unique=True),
        description="ID of role",
        gt=0,
        le=INTEGER_SIZE,
    )
    party_id: Optional[int] = Field(
        sa_column=Column(Integer, ForeignKey("party.id")),
        gt=0,
        le=INTEGER_SIZE,
        alias="partyId",
        description="ID of party",
    )
    name: Optional[str] = Field(sa_column=Column(String(64)),
                                description="Name of role")
    max_players: Optional[int] = Field(
        sa_column=Column(Integer),
        gt=0,
        le=INTEGER_SIZE,
        alias="maxPlayers",
        description="Maximum number of players of role",
    )

    party: Optional["Party"] = Relationship(
        sa_relationship=relationship("Party", back_populates="roles"))

    class Config:
        orm_mode = True
        allow_population_by_field_name = True
示例#18
0
class Channel(SQLModel, table=True):
    id: Optional[int] = Field(
        sa_column=Column(Integer, primary_key=True, unique=True),
        description="ID of channel",
        gt=0,
        le=INTEGER_SIZE,
    )
    name: str = Field(
        sa_column=Column(String(255), nullable=False),
        description="Name of channel from Discord",
    )
    discord_id: str = Field(
        sa_column=Column(String(64), nullable=False, unique=True),
        alias="discordId",
        description="Discord ID of channel",
    )
    server_id: int = Field(
        sa_column=Column(Integer, ForeignKey("server.id"), nullable=False),
        alias="serverId",
        description="ID of server associated with",
        gt=0,
        le=INTEGER_SIZE,
    )
    server: "Server" = Relationship()

    class Config:
        orm_mode = True
        allow_population_by_field_name = True
示例#19
0
class Member(SQLModel, table=True):
    id: Optional[int] = Field(
        sa_column=Column(Integer, primary_key=True, unique=True),
        description="ID of member",
        gt=0,
        le=INTEGER_SIZE,
    )
    player_req: Optional[int] = Field(
        None,
        sa_column=Column(Integer),
        gt=0,
        le=INTEGER_SIZE,
        alias="playerReq",
        description="Required number of players for member to play",
    )
    party_id: int = Field(
        sa_column=Column(Integer, ForeignKey("party.id"), nullable=False),
        gt=0,
        le=INTEGER_SIZE,
        alias="partyId",
        description="ID of party",
    )
    player_id: int = Field(
        sa_column=Column(Integer, ForeignKey("player.id"), nullable=False),
        gt=0,
        le=INTEGER_SIZE,
        alias="playerId",
        description="ID of player",
    )
    role_id: Optional[int] = Field(
        None,
        sa_column=Column(Integer, ForeignKey("role.id"), nullable=True),
        gt=0,
        le=INTEGER_SIZE,
        alias="roleId",
        description="ID of role",
    )

    party: "Party" = Relationship(sa_relationship_kwargs={"lazy": "joined"},
                                  back_populates="members")
    player: "Player" = Relationship(sa_relationship_kwargs={"lazy": "joined"})
    role: Optional["Role"] = Relationship(
        sa_relationship_kwargs={"lazy": "joined"})

    class Config:
        orm_mode = True
        allow_population_by_field_name = True
示例#20
0
class Block(SQLModel, table=True):
    id: int = Field(primary_key=True)
    chain_id: int
    height: int
    timestamp: datetime = Field(sa_column=Column(DateTime(timezone=True)))
    snapshot: Optional[datetime] = Field(sa_column=Column(DateTime(timezone=True)))

    snapshots: List["Snapshot"] = Relationship(back_populates="block")
示例#21
0
class Snapshot(SQLModel, table=True):
    id: int = Field(primary_key=True)
    product: str
    name: str
    assets: float

    block_id: int = Field(foreign_key="block.id")
    block: Block = Relationship(back_populates="snapshots")
示例#22
0
class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    secret_name: str
    age: Optional[int] = None

    team_id: Optional[int] = Field(default=None, foreign_key="team.id")
    team: Optional[Team] = Relationship(back_populates="heroes")
示例#23
0
class OpportunityDefaultConfig(OpportunityConfigBase, table=True):
    __tablename__ = "opportunity_default_config"
    __table_args__ = {"schema": "basic"}

    opportunity_group_id: Optional[int] = Field(sa_column=Column(
        Integer, ForeignKey("basic.opportunity_group.id"), nullable=False))
    opportunity_group: "OpportunityGroup" = Relationship(
        back_populates="opportunity_default_configs")
示例#24
0
class StyleLibrary(SQLModel, table=True):
    __tablename__ = "style_library"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(sa_column=Column(Integer, primary_key=True, autoincrement=True))
    name: str = Field(sa_column=Column(Text(), nullable=False, index=True))
    style: dict = Field(sa_column=Column(JSONB))
    translation: dict = Field(sa_column=Column(JSONB))
    layer_libraries: "LayerLibrary" = Relationship(back_populates="style_library")
示例#25
0
class OpportunityUserConfig(OpportunityConfigBase, table=True):
    __tablename__ = "opportunity_user_config"
    __table_args__ = {"schema": "customer"}

    opportunity_group_id: Optional[int] = Field(sa_column=Column(
        Integer, ForeignKey("basic.opportunity_group.id"), nullable=False))
    study_area_id: int = Field(
        sa_column=Column(Integer, ForeignKey("basic.study_area.id")))
    user_id: int = Field(sa_column=Column(
        Integer, ForeignKey("customer.user.id", ondelete="CASCADE")))
    data_upload_id: Optional[int] = Field(sa_column=Column(
        Integer, ForeignKey("customer.data_upload.id", ondelete="CASCADE")))

    study_area: "StudyArea" = Relationship(
        back_populates="opportunity_user_configs")
    user: "******" = Relationship(back_populates="opportunity_user_configs")

    opportunity_group: "OpportunityGroup" = Relationship(
        back_populates="opportunity_user_configs")
示例#26
0
class Population(PopulationBase, table=True):
    __tablename__ = "population"
    __table_args__ = {"schema": "basic"}

    demography: Optional[dict] = Field(sa_column=Column(JSONB))
    building_id: Optional[int] = Field(sa_column=Column(
        Integer,
        ForeignKey("basic.building.id", ondelete="CASCADE"),
        index=True), )
    building: Optional["Building"] = Relationship(back_populates="populations")
示例#27
0
class OpportunityGroup(SQLModel, table=True):
    __tablename__ = "opportunity_group"
    __table_args__ = {"schema": "basic"}

    id: Optional[int] = Field(
        sa_column=Column(Integer, primary_key=True, autoincrement=True))
    type: str = Field(sa_column=Column(Text, nullable=False))
    group: str = Field(sa_column=Column(Text, nullable=False))
    icon: str = Field(sa_column=Column(Text, nullable=False))
    color: List[str] = Field(sa_column=Column(ARRAY(Text()), nullable=False))

    opportunity_default_configs: Optional[
        List["OpportunityDefaultConfig"]] = Relationship(
            back_populates="opportunity_group")
    opportunity_study_area_configs: Optional[
        List["OpportunityStudyAreaConfig"]] = Relationship(
            back_populates="opportunity_group")
    opportunity_user_configs: Optional[
        List["OpportunityUserConfig"]] = Relationship(
            back_populates="opportunity_group")
示例#28
0
class DomainInvitation(DomainURLORMModel, DomainInvitationDetail,
                       table=True):  # type: ignore[call-arg]
    __tablename__ = "domain_invitations"
    __table_args__ = (
        UniqueConstraint("domain_id", "url"),
        UniqueConstraint("domain_id", "code"),
    )

    domain_id: UUID = Field(sa_column=Column(
        GUID, ForeignKey("domains.id", ondelete="CASCADE"), nullable=False))
    domain: "Domain" = Relationship(back_populates="invitations")
示例#29
0
class OAuth2Token(SQLModel, table=True):
    token_id: int = Field(
        sa_column=Column(Integer, primary_key=True, nullable=False),
        alias="tokenId",
        description="ID of token",
        gt=0,
        le=INTEGER_SIZE,
    )
    player_id: int = Field(
        sa_column=Column(Integer, ForeignKey("player.id"), nullable=False),
        gt=0,
        le=INTEGER_SIZE,
        alias="playerId",
        description="ID of player",
    )
    name: str = Field(
        sa_column=Column(String(20), nullable=False),
        description="Name of token OAuth provider",
    )

    player: "Player" = Relationship()

    token_type: Optional[str] = Field(sa_column=Column(String(20)),
                                      alias="tokenType",
                                      description="Type of token")
    access_token: str = Field(
        sa_column=Column(String(48), nullable=False),
        alias="accessToken",
        description="Access token from OAuth provider",
    )
    refresh_token: Optional[str] = Field(
        sa_column=Column(String(48)),
        alias="refreshToken",
        description="Refresh token from OAuth provider",
    )
    expires_at: Optional[int] = Field(
        sa_column=Column(Integer, default=0),
        ge=0,
        le=INTEGER_SIZE,
        alias="expiresAt",
        description="Token expiration",
    )

    def to_token(self):
        return dict(
            access_token=self.access_token,
            token_type=self.token_type,
            refresh_token=self.refresh_token,
            expires_at=self.expires_at,
        )

    class Config:
        orm_mode = True
        allow_population_by_field_name = True
示例#30
0
class Organization(SQLModel, table=True):
    __tablename__ = "organization"
    __table_args__ = {"schema": "customer"}

    id: Optional[int] = Field(sa_column=Column(Integer, primary_key=True, autoincrement=True))
    name: Optional[str] = Field(sa_column=Column(Text, nullable=False))
    creation_date: Optional[datetime] = Field(
        sa_column=Column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
    )

    users: List["User"] = Relationship(back_populates="organization")