importing class instead of copy pasting it

This commit is contained in:
Silversthorn 2024-03-23 12:37:46 +01:00
parent 64a1defb95
commit f0086c70f7
3 changed files with 10 additions and 92 deletions

View File

@ -12,6 +12,7 @@ from app.classes.models.management import (
Backups, Backups,
) )
from app.classes.models.server_permissions import RoleServers from app.classes.models.server_permissions import RoleServers
from app.classes.models.servers import Servers
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -22,37 +23,6 @@ def migrate(migrator: Migrator, database, **kwargs):
""" """
db = database db = database
# **********************************************************************************
# Servers New Model from Old (easier to migrate without dunmping Database)
# **********************************************************************************
class Servers(peewee.Model):
server_id = peewee.CharField(primary_key=True, default=str(uuid.uuid4()))
created = peewee.DateTimeField(default=datetime.datetime.now)
server_uuid = peewee.CharField(default="", index=True)
server_name = peewee.CharField(default="Server", index=True)
path = peewee.CharField(default="")
backup_path = peewee.CharField(default="")
executable = peewee.CharField(default="")
log_path = peewee.CharField(default="")
execution_command = peewee.CharField(default="")
auto_start = peewee.BooleanField(default=0)
auto_start_delay = peewee.IntegerField(default=10)
crash_detection = peewee.BooleanField(default=0)
stop_command = peewee.CharField(default="stop")
executable_update_url = peewee.CharField(default="")
server_ip = peewee.CharField(default="127.0.0.1")
server_port = peewee.IntegerField(default=25565)
logs_delete_after = peewee.IntegerField(default=0)
type = peewee.CharField(default="minecraft-java")
show_status = peewee.BooleanField(default=1)
created_by = peewee.IntegerField(default=-100)
shutdown_timeout = peewee.IntegerField(default=60)
ignored_exits = peewee.CharField(default="0")
class Meta:
table_name = "servers"
database = db
try: try:
# Changes on Server Table # Changes on Server Table
migrator.alter_column_type( migrator.alter_column_type(

View File

@ -12,6 +12,7 @@ from app.classes.models.management import (
Backups, Backups,
) )
from app.classes.models.server_permissions import RoleServers from app.classes.models.server_permissions import RoleServers
from app.classes.models.servers import Servers
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -27,37 +28,6 @@ def migrate(migrator: Migrator, database, **kwargs):
Console.debug("Update database already done, skipping this part") Console.debug("Update database already done, skipping this part")
return return
# **********************************************************************************
# Servers New Model from Old (easier to migrate without dunmping Database)
# **********************************************************************************
class Servers(peewee.Model):
server_id = peewee.CharField(primary_key=True, default=str(uuid.uuid4()))
created = peewee.DateTimeField(default=datetime.datetime.now)
server_uuid = peewee.CharField(default="", index=True)
server_name = peewee.CharField(default="Server", index=True)
path = peewee.CharField(default="")
backup_path = peewee.CharField(default="")
executable = peewee.CharField(default="")
log_path = peewee.CharField(default="")
execution_command = peewee.CharField(default="")
auto_start = peewee.BooleanField(default=0)
auto_start_delay = peewee.IntegerField(default=10)
crash_detection = peewee.BooleanField(default=0)
stop_command = peewee.CharField(default="stop")
executable_update_url = peewee.CharField(default="")
server_ip = peewee.CharField(default="127.0.0.1")
server_port = peewee.IntegerField(default=25565)
logs_delete_after = peewee.IntegerField(default=0)
type = peewee.CharField(default="minecraft-java")
show_status = peewee.BooleanField(default=1)
created_by = peewee.IntegerField(default=-100)
shutdown_timeout = peewee.IntegerField(default=60)
ignored_exits = peewee.CharField(default="0")
class Meta:
table_name = "servers"
database = db
try: try:
logger.info("Migrating Data from Int to UUID (Foreign Keys)") logger.info("Migrating Data from Int to UUID (Foreign Keys)")
Console.info("Migrating Data from Int to UUID (Foreign Keys)") Console.info("Migrating Data from Int to UUID (Foreign Keys)")

View File

@ -7,6 +7,7 @@ from app.classes.shared.console import Console
from app.classes.shared.migration import Migrator, MigrateHistory from app.classes.shared.migration import Migrator, MigrateHistory
from app.classes.models.management import Schedules, Backups from app.classes.models.management import Schedules, Backups
from app.classes.models.server_permissions import RoleServers from app.classes.models.server_permissions import RoleServers
from app.classes.models.servers import Servers
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -17,36 +18,6 @@ def migrate(migrator: Migrator, database, **kwargs):
""" """
db = database db = database
# **********************************************************************************
# Servers New Model from Old (easier to migrate without dunmping Database)
# **********************************************************************************
class Servers(peewee.Model):
server_id = peewee.CharField(primary_key=True, default=str(uuid.uuid4()))
created = peewee.DateTimeField(default=datetime.datetime.now)
server_name = peewee.CharField(default="Server", index=True)
path = peewee.CharField(default="")
backup_path = peewee.CharField(default="")
executable = peewee.CharField(default="")
log_path = peewee.CharField(default="")
execution_command = peewee.CharField(default="")
auto_start = peewee.BooleanField(default=0)
auto_start_delay = peewee.IntegerField(default=10)
crash_detection = peewee.BooleanField(default=0)
stop_command = peewee.CharField(default="stop")
executable_update_url = peewee.CharField(default="")
server_ip = peewee.CharField(default="127.0.0.1")
server_port = peewee.IntegerField(default=25565)
logs_delete_after = peewee.IntegerField(default=0)
type = peewee.CharField(default="minecraft-java")
show_status = peewee.BooleanField(default=1)
created_by = peewee.IntegerField(default=-100)
shutdown_timeout = peewee.IntegerField(default=60)
ignored_exits = peewee.CharField(default="0")
class Meta:
table_name = "servers"
database = db
try: try:
# Changes on Servers Roles Table # Changes on Servers Roles Table
migrator.alter_column_type( migrator.alter_column_type(
@ -84,6 +55,9 @@ def migrate(migrator: Migrator, database, **kwargs):
), ),
) )
# Drop Column after migration
migrator.drop_columns("servers", ["server_uuid"])
except Exception as ex: except Exception as ex:
logger.error("Error while migrating Data from Int to UUID (Fixing Issue)") logger.error("Error while migrating Data from Int to UUID (Fixing Issue)")
logger.error(ex) logger.error(ex)
@ -122,3 +96,7 @@ def rollback(migrator: Migrator, database, **kwargs):
"server_id", "server_id",
peewee.IntegerField(null=True), peewee.IntegerField(null=True),
) )
migrator.add_columns(
"servers", server_uuid=peewee.CharField(default="", index=True)
) # Recreating the column for roll back