Added level module and migration #25

This commit is contained in:
2022-11-06 14:25:46 +01:00
parent 3516a164da
commit e1dbab3f4f
7 changed files with 104 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
from bot_core.logging.database_logger import DatabaseLogger
from bot_data.abc.migration_abc import MigrationABC
from bot_data.db_context import DBContext
class LevelMigration(MigrationABC):
name = '0.3_LevelMigration'
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)
self._logger = logger
self._db = db
self._cursor = db.cursor
def upgrade(self):
self._logger.debug(__name__, 'Running upgrade')
self._cursor.execute(
str(f"""
CREATE TABLE IF NOT EXISTS `Levels` (
`Id` BIGINT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`PermissionInt` BIGINT NOT NULL,
`ServerId` BIGINT,
PRIMARY KEY(`Id`),
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
);
""")
)
def downgrade(self):
self._cursor.execute('DROP TABLE `Levels`;')