refactor(models): unify table names to singular form for consistency across models

This commit is contained in:
JSC
2025-07-05 18:11:19 +02:00
parent 21541c8184
commit 024c58f013
7 changed files with 12 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ from app.database import db
class Plan(db.Model): class Plan(db.Model):
"""Plan model for user subscription plans.""" """Plan model for user subscription plans."""
__tablename__ = "plans" __tablename__ = "plan"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
code = Column(String(50), unique=True, nullable=False, index=True) code = Column(String(50), unique=True, nullable=False, index=True)

View File

@@ -17,14 +17,14 @@ if TYPE_CHECKING:
class Playlist(db.Model): class Playlist(db.Model):
"""Model for playlists containing sounds.""" """Model for playlists containing sounds."""
__tablename__ = "playlists" __tablename__ = "playlist"
id: Mapped[int] = mapped_column(Integer, primary_key=True) id: Mapped[int] = mapped_column(Integer, primary_key=True)
name: Mapped[str] = mapped_column(String(255), nullable=False) name: Mapped[str] = mapped_column(String(255), nullable=False)
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True) description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
genre: Mapped[Optional[str]] = mapped_column(String(100), nullable=True) genre: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
user_id: Mapped[Optional[int]] = mapped_column( user_id: Mapped[Optional[int]] = mapped_column(
Integer, ForeignKey("users.id"), nullable=True Integer, ForeignKey("user.id"), nullable=True
) )
is_main: Mapped[bool] = mapped_column( is_main: Mapped[bool] = mapped_column(
Boolean, default=False, nullable=False Boolean, default=False, nullable=False

View File

@@ -17,14 +17,14 @@ if TYPE_CHECKING:
class PlaylistSound(db.Model): class PlaylistSound(db.Model):
"""Model for playlist-sound relationships with ordering.""" """Model for playlist-sound relationships with ordering."""
__tablename__ = "playlist_sounds" __tablename__ = "playlist_sound"
id: Mapped[int] = mapped_column(Integer, primary_key=True) id: Mapped[int] = mapped_column(Integer, primary_key=True)
playlist_id: Mapped[int] = mapped_column( playlist_id: Mapped[int] = mapped_column(
Integer, ForeignKey("playlists.id"), nullable=False Integer, ForeignKey("playlist.id"), nullable=False
) )
sound_id: Mapped[int] = mapped_column( sound_id: Mapped[int] = mapped_column(
Integer, ForeignKey("sounds.id"), nullable=False Integer, ForeignKey("sound.id"), nullable=False
) )
order: Mapped[int] = mapped_column(Integer, nullable=False) order: Mapped[int] = mapped_column(Integer, nullable=False)
added_at: Mapped[datetime] = mapped_column( added_at: Mapped[datetime] = mapped_column(

View File

@@ -25,7 +25,7 @@ class SoundType(Enum):
class Sound(db.Model): class Sound(db.Model):
"""Sound model for storing sound file information.""" """Sound model for storing sound file information."""
__tablename__ = "sounds" __tablename__ = "sound"
id: Mapped[int] = mapped_column(primary_key=True) id: Mapped[int] = mapped_column(primary_key=True)

View File

@@ -19,12 +19,12 @@ class SoundPlayed(db.Model):
# Foreign keys # Foreign keys
user_id: Mapped[int] = mapped_column( user_id: Mapped[int] = mapped_column(
Integer, Integer,
ForeignKey("users.id"), ForeignKey("user.id"),
nullable=False, nullable=False,
) )
sound_id: Mapped[int] = mapped_column( sound_id: Mapped[int] = mapped_column(
Integer, Integer,
ForeignKey("sounds.id"), ForeignKey("sound.id"),
nullable=False, nullable=False,
) )

View File

@@ -20,7 +20,7 @@ if TYPE_CHECKING:
class User(db.Model): class User(db.Model):
"""User model for storing user information.""" """User model for storing user information."""
__tablename__ = "users" __tablename__ = "user"
id: Mapped[int] = mapped_column(primary_key=True) id: Mapped[int] = mapped_column(primary_key=True)
@@ -48,7 +48,7 @@ class User(db.Model):
# Plan relationship # Plan relationship
plan_id: Mapped[int] = mapped_column( plan_id: Mapped[int] = mapped_column(
Integer, Integer,
ForeignKey("plans.id"), ForeignKey("plan.id"),
nullable=False, nullable=False,
) )

View File

@@ -21,7 +21,7 @@ class UserOAuth(db.Model):
id: Mapped[int] = mapped_column(primary_key=True) id: Mapped[int] = mapped_column(primary_key=True)
# User relationship # User relationship
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False) user_id: Mapped[int] = mapped_column(ForeignKey("user.id"), nullable=False)
# OAuth provider information # OAuth provider information
provider: Mapped[str] = mapped_column(String(50), nullable=False) provider: Mapped[str] = mapped_column(String(50), nullable=False)