-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reafactor: migrate from raw sql to orm (#24)
* Migrate from raw sql (aiosqlite) to ORM (sqlalchemy) * Adds autocomplete in extension manager command group * Fix music playlist autocomplete not sorting according to name * Increase Mafic logging to warning
- Loading branch information
1 parent
c90f9aa
commit 0813532
Showing
31 changed files
with
1,601 additions
and
1,305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ Servers.inf | |
lavalink_server/logs | ||
ip.txt | ||
*.db | ||
/logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ repos: | |
hooks: | ||
- id: isort | ||
exclude: '^(env)' | ||
args: ["--profile", "black"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from .base import Base | ||
from .greeter import Greeter | ||
from .guild import Guild | ||
from .music import Playlists, Tracks | ||
from .temprole import TempRole | ||
from .ticketsystem import Ticket, TicketConfig | ||
|
||
__all__ = [ | ||
"Greeter", | ||
"Guild", | ||
"Base", | ||
"TempRole", | ||
"Playlists", | ||
"Tracks", | ||
"TicketConfig", | ||
"Ticket", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from sqlalchemy.orm import DeclarativeBase | ||
|
||
|
||
class Base(DeclarativeBase): | ||
def __repr__(self) -> str: | ||
return f"<{self.__class__.__name__}({', '.join([f"{col}={getattr(self, col, None)}" for col in self.__table__.columns.keys()])})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Optional | ||
|
||
import sqlalchemy | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from .base import Base | ||
from .guild import Guild | ||
|
||
|
||
class Greeter(Base): | ||
__tablename__ = "greeters" | ||
|
||
id: Mapped[int] = mapped_column( | ||
sqlalchemy.Integer, primary_key=True, autoincrement=False, index=True | ||
) | ||
guild_id: Mapped[int] = mapped_column( | ||
sqlalchemy.ForeignKey("guilds.id", ondelete="CASCADE"), index=True | ||
) | ||
wlcm_channel: Mapped[Optional[int]] = mapped_column( | ||
sqlalchemy.BigInteger, nullable=True | ||
) | ||
wlcm_image: Mapped[Optional[str]] = mapped_column(sqlalchemy.String, nullable=True) | ||
wlcm_theme: Mapped[Optional[str]] = mapped_column(sqlalchemy.String, nullable=True) | ||
wlcm_fontstyle: Mapped[Optional[str]] = mapped_column( | ||
sqlalchemy.String, nullable=True | ||
) | ||
wlcm_outline: Mapped[Optional[int]] = mapped_column( | ||
sqlalchemy.Integer, nullable=True | ||
) | ||
wlcm_msg: Mapped[Optional[str]] = mapped_column(sqlalchemy.String, nullable=True) | ||
bye_channel: Mapped[Optional[int]] = mapped_column( | ||
sqlalchemy.BigInteger, nullable=True | ||
) | ||
bye_image: Mapped[Optional[str]] = mapped_column(sqlalchemy.String, nullable=True) | ||
bye_theme: Mapped[Optional[str]] = mapped_column(sqlalchemy.String, nullable=True) | ||
bye_fontstyle: Mapped[Optional[str]] = mapped_column( | ||
sqlalchemy.String, nullable=True | ||
) | ||
bye_outline: Mapped[Optional[int]] = mapped_column( | ||
sqlalchemy.Integer, nullable=True | ||
) | ||
bye_msg: Mapped[Optional[str]] = mapped_column(sqlalchemy.String, nullable=True) | ||
|
||
guild: Mapped[Guild] = relationship("Guild", passive_deletes=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import sqlalchemy | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from .base import Base | ||
|
||
|
||
class Guild(Base): | ||
__tablename__ = "guilds" | ||
|
||
id: Mapped[int] = mapped_column( | ||
sqlalchemy.BigInteger, primary_key=True, autoincrement=False, index=True | ||
) | ||
name: Mapped[str] = mapped_column(sqlalchemy.String(length=50)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List | ||
|
||
import sqlalchemy | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from .base import Base | ||
|
||
|
||
class Playlists(Base): | ||
__tablename__ = "playlists" | ||
|
||
id: Mapped[int] = mapped_column(sqlalchemy.Integer, primary_key=True, index=True) | ||
name: Mapped[str] = mapped_column(sqlalchemy.String(length=50)) | ||
user_id: Mapped[int] = mapped_column(sqlalchemy.BigInteger, index=True) | ||
tracks: Mapped[List[Tracks]] = relationship( | ||
"Tracks", back_populates="playlists", cascade="all, delete", lazy="selectin" | ||
) | ||
|
||
|
||
class Tracks(Base): | ||
__tablename__ = "tracks" | ||
id: Mapped[int] = mapped_column(sqlalchemy.Integer, primary_key=True, index=True) | ||
|
||
playlist_id: Mapped[int] = mapped_column( | ||
sqlalchemy.ForeignKey("playlists.id", ondelete="CASCADE"), index=True | ||
) | ||
track: Mapped[str] = mapped_column(sqlalchemy.Text, index=True) | ||
|
||
playlists: Mapped[Playlists] = relationship( | ||
"Playlists", back_populates="tracks", passive_deletes=True, lazy="selectin" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import sqlalchemy | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from .base import Base | ||
from .guild import Guild | ||
|
||
|
||
class TempRole(Base): | ||
__tablename__ = "temprole" | ||
|
||
id: Mapped[int] = mapped_column(sqlalchemy.Integer, primary_key=True, index=True) | ||
guild_id: Mapped[int] = mapped_column( | ||
sqlalchemy.ForeignKey("guilds.id", ondelete="CASCADE"), index=True | ||
) | ||
user_id: Mapped[int] = mapped_column(sqlalchemy.BigInteger, index=True) | ||
role_id: Mapped[int] = mapped_column(sqlalchemy.BigInteger) | ||
expiration: Mapped[str] = mapped_column(sqlalchemy.Text) | ||
|
||
# Relationship | ||
guild: Mapped[Guild] = relationship("Guild", passive_deletes=True) |
Oops, something went wrong.