diff --git a/.gitea/workflows/docker-pull.yml b/.gitea/workflows/docker-pull.yml index 861c0f2..5f1e7db 100644 --- a/.gitea/workflows/docker-pull.yml +++ b/.gitea/workflows/docker-pull.yml @@ -17,7 +17,7 @@ jobs: - name: Set release version manually id: version - run: echo "version=0.2.0" >> "$GITHUB_OUTPUT" + run: echo "version=0.3.0" >> "$GITHUB_OUTPUT" - name: Compute short SHA id: gitvars diff --git a/pyproject.toml b/pyproject.toml index c8f09bd..e0938ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "hubgw" -version = "0.2.0" +version = "0.3.0" description = "FastAPI Gateway for HubMC" authors = ["itqop "] packages = [ diff --git a/src/hubgw/context.py b/src/hubgw/context.py index b7f0f80..36c1d01 100644 --- a/src/hubgw/context.py +++ b/src/hubgw/context.py @@ -45,6 +45,8 @@ class AppContext(metaclass=Singleton): pool_recycle=True, echo=self.settings.database.echo, **engine_kwargs, + ).execution_options( + schema_translate_map={None: self.settings.database.schema_} ) Base.metadata.bind = self._engine @@ -80,6 +82,8 @@ class AppContext(metaclass=Singleton): pool_recycle=True, echo=self.settings.database.echo, **engine_kwargs, + ).execution_options( + schema_translate_map={None: self.settings.database.azuriom_schema} ) Base.metadata.bind = self._azuriom_engine diff --git a/src/hubgw/core/config.py b/src/hubgw/core/config.py index c627dd0..14d3c8c 100644 --- a/src/hubgw/core/config.py +++ b/src/hubgw/core/config.py @@ -43,6 +43,16 @@ class DatabaseSettings(BaseSettings): validation_alias="DATABASE__AZURIOM_DATABASE", description="Azuriom database name", ) + schema_: str = Field( + default="public", + validation_alias="DATABASE__SCHEMA", + description="Main database schema name", + ) + azuriom_schema: str = Field( + default="public", + validation_alias="DATABASE__AZURIOM_SCHEMA", + description="Azuriom database schema name", + ) pool_size: int = Field( default=10, validation_alias="DATABASE__POOL_SIZE", diff --git a/src/hubgw/models/base.py b/src/hubgw/models/base.py index 6dc4c16..c3dc2cc 100644 --- a/src/hubgw/models/base.py +++ b/src/hubgw/models/base.py @@ -2,7 +2,7 @@ from sqlalchemy import Column, DateTime, func -from sqlalchemy.orm import DeclarativeBase, declared_attr +from sqlalchemy.orm import DeclarativeBase class Base(DeclarativeBase): @@ -12,8 +12,3 @@ class Base(DeclarativeBase): updated_at = Column( DateTime(timezone=True), server_default=func.now(), onupdate=func.now() ) - - @declared_attr.directive - def __table_args__(cls): - """Set default schema for all tables.""" - return {"schema": "public"} diff --git a/src/hubgw/models/cooldown.py b/src/hubgw/models/cooldown.py index db1825e..e76d153 100644 --- a/src/hubgw/models/cooldown.py +++ b/src/hubgw/models/cooldown.py @@ -15,7 +15,6 @@ class Cooldown(Base): UniqueConstraint( "player_uuid", "cooldown_type", name="idx_hub_cooldowns_player_type" ), - {"schema": "public"}, ) id = Column( @@ -23,7 +22,7 @@ class Cooldown(Base): ) player_uuid = Column( String(36), - ForeignKey("hubmc.luckperms_players.uuid", ondelete="CASCADE"), + ForeignKey("luckperms_players.uuid", ondelete="CASCADE"), nullable=False, index=True, ) diff --git a/src/hubgw/models/home.py b/src/hubgw/models/home.py index 8a8de7c..0c3aaeb 100644 --- a/src/hubgw/models/home.py +++ b/src/hubgw/models/home.py @@ -13,7 +13,6 @@ class Home(Base): __tablename__ = "hub_homes" __table_args__ = ( UniqueConstraint("player_uuid", "name", name="idx_hub_homes_player_name"), - {"schema": "public"}, ) id = Column( @@ -21,7 +20,7 @@ class Home(Base): ) player_uuid = Column( String(36), - ForeignKey("hubmc.luckperms_players.uuid", ondelete="CASCADE"), + ForeignKey("luckperms_players.uuid", ondelete="CASCADE"), nullable=False, index=True, ) diff --git a/src/hubgw/models/luckperms.py b/src/hubgw/models/luckperms.py index aae4a45..3e93541 100644 --- a/src/hubgw/models/luckperms.py +++ b/src/hubgw/models/luckperms.py @@ -41,13 +41,12 @@ class LuckPermsUserPermission(Base): "server", "world", ), - {"schema": "public"}, ) id = Column(Integer, primary_key=True, autoincrement=True) uuid = Column( String(36), - ForeignKey("hubmc.luckperms_players.uuid", ondelete="CASCADE"), + ForeignKey("luckperms_players.uuid", ondelete="CASCADE"), nullable=False, index=True, ) diff --git a/src/hubgw/models/punishment.py b/src/hubgw/models/punishment.py index bae327a..7dfff8b 100644 --- a/src/hubgw/models/punishment.py +++ b/src/hubgw/models/punishment.py @@ -33,7 +33,6 @@ class Punishment(Base): "player_ip", postgresql_where=Column("player_ip").is_not(None), ), - {"schema": "public"}, ) id = Column( @@ -41,7 +40,7 @@ class Punishment(Base): ) player_uuid = Column( String(36), - ForeignKey("hubmc.luckperms_players.uuid", ondelete="CASCADE"), + ForeignKey("luckperms_players.uuid", ondelete="CASCADE"), nullable=False, index=True, ) @@ -51,7 +50,7 @@ class Punishment(Base): reason = Column(Text, nullable=False) staff_uuid = Column( String(36), - ForeignKey("hubmc.luckperms_players.uuid", ondelete="SET NULL"), + ForeignKey("luckperms_players.uuid", ondelete="SET NULL"), nullable=False, ) staff_name = Column(String(255), nullable=False) @@ -59,7 +58,7 @@ class Punishment(Base): is_active = Column(Boolean, default=True) revoked_at = Column(DateTime(timezone=True)) revoked_by = Column( - String(36), ForeignKey("hubmc.luckperms_players.uuid", ondelete="SET NULL") + String(36), ForeignKey("luckperms_players.uuid", ondelete="SET NULL") ) revoked_reason = Column(Text) evidence_url = Column(Text) diff --git a/src/hubgw/models/teleport_history.py b/src/hubgw/models/teleport_history.py index b2bfe8c..f333c54 100644 --- a/src/hubgw/models/teleport_history.py +++ b/src/hubgw/models/teleport_history.py @@ -17,7 +17,7 @@ class TeleportHistory(Base): ) player_uuid = Column( String(36), - ForeignKey("hubmc.luckperms_players.uuid", ondelete="CASCADE"), + ForeignKey("luckperms_players.uuid", ondelete="CASCADE"), nullable=False, index=True, ) diff --git a/src/hubgw/models/users.py b/src/hubgw/models/users.py index c24eb33..36ef55e 100644 --- a/src/hubgw/models/users.py +++ b/src/hubgw/models/users.py @@ -34,5 +34,4 @@ class User(Base): __table_args__ = ( Index("idx_users_email", "email", unique=True), - {"schema": "public"}, ) diff --git a/src/hubgw/models/warp.py b/src/hubgw/models/warp.py index fc4c163..0786027 100644 --- a/src/hubgw/models/warp.py +++ b/src/hubgw/models/warp.py @@ -15,7 +15,6 @@ class Warp(Base): Index( "idx_hub_warps_public", "is_public", postgresql_where=Column("is_public") ), - {"schema": "public"}, ) id = Column( diff --git a/src/hubgw/models/whitelist.py b/src/hubgw/models/whitelist.py index 7a99bb1..e54db35 100644 --- a/src/hubgw/models/whitelist.py +++ b/src/hubgw/models/whitelist.py @@ -21,7 +21,6 @@ class WhitelistEntry(Base): "expires_at", postgresql_where=Column("expires_at").is_not(None), ), - {"schema": "public"}, ) id = Column(