From 637fc7516ba61810f13a2495e6378e0ba0382ca6 Mon Sep 17 00:00:00 2001 From: itqop Date: Thu, 16 Oct 2025 00:29:55 +0300 Subject: [PATCH] fix: small fixes --- src/hubgw/models/cooldown.py | 5 ++++- src/hubgw/models/home.py | 13 ++++++++----- src/hubgw/models/luckperms.py | 4 ++++ src/hubgw/models/punishment.py | 13 +++++++++++-- src/hubgw/models/warp.py | 14 +++++++++----- src/hubgw/models/whitelist.py | 6 +++++- 6 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/hubgw/models/cooldown.py b/src/hubgw/models/cooldown.py index b3d4202..371fb16 100644 --- a/src/hubgw/models/cooldown.py +++ b/src/hubgw/models/cooldown.py @@ -1,6 +1,6 @@ """Cooldown model.""" -from sqlalchemy import Column, String, DateTime, Integer, ForeignKey +from sqlalchemy import Column, String, DateTime, Integer, ForeignKey, UniqueConstraint from sqlalchemy.dialects.postgresql import UUID, JSONB from hubgw.models.base import Base @@ -9,6 +9,9 @@ class Cooldown(Base): """Cooldown model.""" __tablename__ = "hub_cooldowns" + __table_args__ = ( + UniqueConstraint('player_uuid', 'cooldown_type', name='idx_hub_cooldowns_player_type'), + ) id = Column(UUID(as_uuid=True), primary_key=True, server_default="gen_random_uuid()") player_uuid = Column(String(36), 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 27b4532..4740718 100644 --- a/src/hubgw/models/home.py +++ b/src/hubgw/models/home.py @@ -1,6 +1,6 @@ """Home model.""" -from sqlalchemy import Column, Float, String, Boolean, ForeignKey, REAL, Text +from sqlalchemy import Column, Float, String, Boolean, ForeignKey, REAL, Text, UniqueConstraint from sqlalchemy.dialects.postgresql import UUID from hubgw.models.base import Base @@ -9,14 +9,17 @@ class Home(Base): """Home model.""" __tablename__ = "hub_homes" + __table_args__ = ( + UniqueConstraint('player_uuid', 'name', name='idx_hub_homes_player_name'), + ) id = Column(UUID(as_uuid=True), primary_key=True, server_default="gen_random_uuid()") player_uuid = Column(String(36), ForeignKey("luckperms_players.uuid", ondelete="CASCADE"), nullable=False, index=True) name = Column(String(255), nullable=False) - world = Column(Text, nullable=False) # TEXT type - x = Column(Float, nullable=False) # DOUBLE PRECISION - y = Column(Float, nullable=False) # DOUBLE PRECISION - z = Column(Float, nullable=False) # DOUBLE PRECISION + world = Column(Text, nullable=False) + x = Column(Float, nullable=False) + y = Column(Float, nullable=False) + z = Column(Float, nullable=False) yaw = Column(REAL, default=0.0) pitch = Column(REAL, default=0.0) is_public = Column(Boolean, default=False) diff --git a/src/hubgw/models/luckperms.py b/src/hubgw/models/luckperms.py index d8c6745..13e11be 100644 --- a/src/hubgw/models/luckperms.py +++ b/src/hubgw/models/luckperms.py @@ -7,6 +7,7 @@ from sqlalchemy import ( BigInteger, ForeignKey, Integer, + Index, ) from sqlalchemy.orm import relationship @@ -37,6 +38,9 @@ class LuckPermsUserPermission(Base): """LuckPerms User Permission model.""" __tablename__ = "luckperms_user_permissions" + __table_args__ = ( + Index('idx_luckperms_user_permissions_lookup', 'uuid', 'permission', 'server', 'world'), + ) id = Column(Integer, primary_key=True, autoincrement=True) uuid = Column(String(36), 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 145f8f8..1030526 100644 --- a/src/hubgw/models/punishment.py +++ b/src/hubgw/models/punishment.py @@ -1,6 +1,6 @@ """Punishment model.""" -from sqlalchemy import Column, String, DateTime, Boolean, Text, ForeignKey +from sqlalchemy import Column, String, DateTime, Boolean, Text, ForeignKey, CheckConstraint, Index from sqlalchemy.dialects.postgresql import UUID, INET from hubgw.models.base import Base @@ -9,12 +9,21 @@ class Punishment(Base): """Punishment model.""" __tablename__ = "hub_punishments" + __table_args__ = ( + CheckConstraint( + "punishment_type IN ('BAN', 'MUTE', 'KICK', 'WARN', 'TEMPBAN', 'TEMPMUTE')", + name='check_punishment_type' + ), + Index('idx_hub_punishments_player_active', 'player_uuid', 'is_active', postgresql_where=Column('is_active')), + Index('idx_hub_punishments_type_active', 'punishment_type', 'is_active', postgresql_where=Column('is_active')), + Index('idx_hub_punishments_player_ip', 'player_ip', postgresql_where=Column('player_ip') != None), + ) id = Column(UUID(as_uuid=True), primary_key=True, server_default="gen_random_uuid()") player_uuid = Column(String(36), ForeignKey("luckperms_players.uuid", ondelete="CASCADE"), nullable=False, index=True) player_name = Column(String(255), nullable=False) player_ip = Column(INET) - punishment_type = Column(String(50), nullable=False) # BAN, MUTE, KICK, WARN, TEMPBAN, TEMPMUTE + punishment_type = Column(String(50), nullable=False) reason = Column(Text, nullable=False) staff_uuid = Column(String(36), ForeignKey("luckperms_players.uuid", ondelete="SET NULL"), nullable=False) staff_name = Column(String(255), nullable=False) diff --git a/src/hubgw/models/warp.py b/src/hubgw/models/warp.py index ebae409..5b0b73d 100644 --- a/src/hubgw/models/warp.py +++ b/src/hubgw/models/warp.py @@ -1,6 +1,6 @@ """Warp model.""" -from sqlalchemy import Column, String, Float, Boolean, REAL, Text +from sqlalchemy import Column, String, Float, Boolean, REAL, Text, Index from sqlalchemy.dialects.postgresql import UUID from hubgw.models.base import Base @@ -9,13 +9,17 @@ class Warp(Base): """Warp model.""" __tablename__ = "hub_warps" + __table_args__ = ( + Index('idx_hub_warps_world', 'world'), + Index('idx_hub_warps_public', 'is_public', postgresql_where=Column('is_public')), + ) id = Column(UUID(as_uuid=True), primary_key=True, server_default="gen_random_uuid()") name = Column(String(255), nullable=False, unique=True, index=True) - world = Column(Text, nullable=False) # TEXT type - x = Column(Float, nullable=False) # DOUBLE PRECISION - y = Column(Float, nullable=False) # DOUBLE PRECISION - z = Column(Float, nullable=False) # DOUBLE PRECISION + world = Column(Text, nullable=False) + x = Column(Float, nullable=False) + y = Column(Float, nullable=False) + z = Column(Float, nullable=False) yaw = Column(REAL, default=0.0) pitch = Column(REAL, default=0.0) is_public = Column(Boolean, default=True) diff --git a/src/hubgw/models/whitelist.py b/src/hubgw/models/whitelist.py index 4c28809..4ab5483 100644 --- a/src/hubgw/models/whitelist.py +++ b/src/hubgw/models/whitelist.py @@ -1,6 +1,6 @@ """Whitelist model.""" -from sqlalchemy import Column, String, DateTime, Boolean, ForeignKey +from sqlalchemy import Column, String, DateTime, Boolean, ForeignKey, Index from sqlalchemy.dialects.postgresql import UUID from hubgw.models.base import Base @@ -9,6 +9,10 @@ class WhitelistEntry(Base): """Whitelist entry model.""" __tablename__ = "hub_whitelist" + __table_args__ = ( + Index('idx_hub_whitelist_active', 'is_active', postgresql_where=Column('is_active')), + Index('idx_hub_whitelist_expires', 'expires_at', postgresql_where=Column('expires_at') != None), + ) id = Column(UUID(as_uuid=True), primary_key=True, server_default="gen_random_uuid()") player_name = Column(String(255), nullable=False, unique=True, index=True)