diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b54fe585a..7b135cde3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,6 @@ repos: - Pillow - prometheus_client - tortoise-orm - - aerich==0.6.3 - redis - django - dj_database_url diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 79e65751b..77c246c93 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,10 +87,16 @@ Their configurations are already written in `pyproject.toml`, so it should work ## Migrations -> [!CAUTION] -> The migration engine we've been using in the past is severely broken, and will be removed soon -> in favor of Django's migration engine. In the meantime, all PRs that require database migrations -> are put on hold. +If you are modifying models definition, you need migrations to update the database schema. + +First, synchronize your changes between `ballsdex/core/models.py` and +`admin_panel/bd_models/models.py`, they must be identical! + +Then you can run `python3 manage.py makemigrations` to generate a migration file. Re-read its +contents to ensure there is only what you modified, and commit it. + +You can read more about migrations +[here](https://docs.djangoproject.com/en/5.1/topics/migrations/), the engine is very extensive! ## Coding style diff --git a/admin_panel/admin_panel/settings/base.py b/admin_panel/admin_panel/settings/base.py index edd9b0237..262f31b46 100644 --- a/admin_panel/admin_panel/settings/base.py +++ b/admin_panel/admin_panel/settings/base.py @@ -9,7 +9,15 @@ from ballsdex.settings import read_settings, settings -read_settings(Path("../config.yml")) +try: + read_settings(Path("../config.yml")) +except FileNotFoundError: + from rich import print + + print( + "[yellow][bold]Could not find ../config.yml file.[/bold] " + "Please run the bot once to generate this file.[/yellow]" + ) BASE_DIR = Path(__file__).resolve().parent.parent diff --git a/admin_panel/bd_models/migrations/0002_move_upload_files.py b/admin_panel/bd_models/migrations/0002_move_upload_files.py index de6b72152..d5a0b0106 100644 --- a/admin_panel/bd_models/migrations/0002_move_upload_files.py +++ b/admin_panel/bd_models/migrations/0002_move_upload_files.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING from bd_models.models import Ball, Economy, Regime, Special -from django.db import migrations +from django.db import connection, migrations from django.db.models import Case, ImageField, When from django.db.models.expressions import F, Value from django.db.models.functions import Concat, Replace @@ -60,6 +60,10 @@ def _check_reserved_names(): def move_forwards(apps: "Apps", schema_editor: "BaseDatabaseSchemaEditor"): + # only run this migration if there are existing tables (migrating from aerich) + if "ball" not in connection.introspection.table_names(): + return + # Run this first, as outdated objects are created by aerich's initial migrations Regime.objects.update(**_replace_text("background")) Special.objects.update(**_replace_text("background")) @@ -80,6 +84,10 @@ def move_forwards(apps: "Apps", schema_editor: "BaseDatabaseSchemaEditor"): def move_backwards(apps: "Apps", schema_editor: "BaseDatabaseSchemaEditor"): + # only run this migration if the tables weren't deleted + if "ball" not in connection.introspection.table_names(): + return + Ball.objects.update( **_replace_text("wild_card", reverse=True), **_replace_text("collection_card", reverse=True), diff --git a/admin_panel/bd_models/migrations/0003_delete_ball_delete_ballinstance_and_more.py b/admin_panel/bd_models/migrations/0003_delete_ball_delete_ballinstance_and_more.py new file mode 100644 index 000000000..3da69f9b1 --- /dev/null +++ b/admin_panel/bd_models/migrations/0003_delete_ball_delete_ballinstance_and_more.py @@ -0,0 +1,55 @@ +# Generated by Django 5.1.4 on 2025-01-28 14:44 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bd_models", "0002_move_upload_files"), + ] + + operations = [ + migrations.DeleteModel( + name="Ball", + ), + migrations.DeleteModel( + name="BallInstance", + ), + migrations.DeleteModel( + name="BlacklistedGuild", + ), + migrations.DeleteModel( + name="BlacklistedID", + ), + migrations.DeleteModel( + name="BlacklistHistory", + ), + migrations.DeleteModel( + name="Block", + ), + migrations.DeleteModel( + name="Economy", + ), + migrations.DeleteModel( + name="Friendship", + ), + migrations.DeleteModel( + name="Guildconfig", + ), + migrations.DeleteModel( + name="Player", + ), + migrations.DeleteModel( + name="Regime", + ), + migrations.DeleteModel( + name="Special", + ), + migrations.DeleteModel( + name="Trade", + ), + migrations.DeleteModel( + name="Tradeobject", + ), + ] diff --git a/admin_panel/bd_models/migrations/0004_check_aerich_migrations_initial.py b/admin_panel/bd_models/migrations/0004_check_aerich_migrations_initial.py new file mode 100644 index 000000000..ec462657a --- /dev/null +++ b/admin_panel/bd_models/migrations/0004_check_aerich_migrations_initial.py @@ -0,0 +1,682 @@ +# Generated by Django 5.1.4 on 2025-02-12 11:31 + +import sys +from typing import TYPE_CHECKING + +import django.db.models.deletion +from bd_models.models import Economy, Regime, Special +from django.db import connection, migrations, models + +if TYPE_CHECKING: + from django.apps.registry import Apps + from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def execute_aerich_migration_check(apps: "Apps", schema_editor: "BaseDatabaseSchemaEditor"): + with connection.cursor() as cursor: + cursor.execute( + "SELECT EXISTS(SELECT * FROM information_schema.tables " + "WHERE table_schema = 'public' AND table_name = 'aerich')" + ) + has_aerich = cursor.fetchone() + assert has_aerich + if not has_aerich[0]: + # aerich presence not detected, new instance, keep going + return + + cursor.execute("SELECT version FROM aerich ORDER BY id DESC") + version = cursor.fetchone() + assert version + if version[0] != "38_20250120182312_update.sql": + raise RuntimeError( + "Aerich migrations exists and are not up to date, cannot safely proceed!!\n\n" + "The old migration engine is being removed in favor of Django's own, you must " + "either have an empty table or have a perfectly up-to-date database to migrate.\n" + "The resolution is to roll back to version 2.24.2, run the bot once to complete " + "all migrations, then upgrade to the latest version.\n\n" + "Commands to run:\n" + " git checkout release/2.24.2\n" + " docker compose up --build bot\n" + ' [Press Ctrl+C after seeing the line "Ran X migrations: ...."]\n' + " git switch -\n" + " docker compose up --build admin-panel\n" + " [Ensure all migrations complete successfully]" + ) + elif "--fake-initial" not in sys.argv: + raise RuntimeError( + "Detected up-to-date Aerich table but --fake-initial flag missing\n\n" + "You are about to migrate from the Aerich migration engine to Django's own. " + "Your database is up-to-date, but you must run this command with the " + "--fake-initial flag to instruct Django to not override existing tables.\n\n" + 'Please run "python3 manage.py migrate --fake-initial" to pass this migration.' + ) + + +def aerich_move_backwards(apps: "Apps", schema_editor: "BaseDatabaseSchemaEditor"): + # allows reversing the migration + pass + + +def default_models_forward(apps: "Apps", schema_editor: "BaseDatabaseSchemaEditor"): + default_economies = { + "Capitalist": "capitalist.png", + "Communist": "communist.png", + } + default_regimes = { + "Democracy": "democracy.png", + "Dictatorship": "dictatorship.png", + "Union": "union.png", + } + + for name, icon in default_economies.items(): + object, created = Economy.objects.get_or_create(name=name, defaults={"icon": icon}) + if created: + print(f"Created default economy {object}") + for name, background in default_regimes.items(): + object, created = Regime.objects.get_or_create( + name=name, defaults={"background": background} + ) + if created: + print(f"Created default regime {object}") + object, created = Special.objects.get_or_create( + name="Shiny", + defaults={ + "rarity": 0.00048828125, + "catch_phrase": "**✨ It's a shiny countryball! ✨**", + "emoji": "✨", + "background": "shiny.png", + }, + ) + if created: + print(f"Created default shiny special {object}") + + +def default_models_backward(apps: "Apps", schema_editor: "BaseDatabaseSchemaEditor"): + pass + + +class Migration(migrations.Migration): + initial = True + + dependencies = [ + ("bd_models", "0003_delete_ball_delete_ballinstance_and_more"), + ] + + operations = [ + migrations.RunPython( + code=execute_aerich_migration_check, + reverse_code=aerich_move_backwards, + ), + migrations.CreateModel( + name="BlacklistedGuild", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("discord_id", models.BigIntegerField(help_text="Discord Guild ID", unique=True)), + ("reason", models.TextField(blank=True, null=True)), + ("date", models.DateTimeField(auto_now_add=True, null=True)), + ("moderator_id", models.BigIntegerField(blank=True, null=True)), + ], + options={ + "db_table": "blacklistedguild", + "managed": True, + }, + ), + migrations.CreateModel( + name="BlacklistedID", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("discord_id", models.BigIntegerField(help_text="Discord user ID", unique=True)), + ("reason", models.TextField(blank=True, null=True)), + ("date", models.DateTimeField(auto_now_add=True, null=True)), + ("moderator_id", models.BigIntegerField(blank=True, null=True)), + ], + options={ + "db_table": "blacklistedid", + "managed": True, + }, + ), + migrations.CreateModel( + name="BlacklistHistory", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("discord_id", models.BigIntegerField(help_text="Discord ID")), + ("moderator_id", models.BigIntegerField(help_text="Discord Moderator ID")), + ("reason", models.TextField(blank=True, null=True)), + ("date", models.DateTimeField(auto_now_add=True)), + ("id_type", models.CharField(default="user", max_length=64)), + ("action_type", models.CharField(default="blacklist", max_length=64)), + ], + options={ + "verbose_name_plural": "blacklisthistories", + "db_table": "blacklisthistory", + "managed": True, + }, + ), + migrations.CreateModel( + name="Economy", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("name", models.CharField(max_length=64)), + ( + "icon", + models.ImageField(help_text="512x512 PNG image", max_length=200, upload_to=""), + ), + ], + options={ + "verbose_name_plural": "economies", + "db_table": "economy", + "managed": True, + }, + ), + migrations.CreateModel( + name="GuildConfig", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("guild_id", models.BigIntegerField(help_text="Discord guild ID", unique=True)), + ( + "spawn_channel", + models.BigIntegerField( + blank=True, + help_text="Discord channel ID where balls will spawn", + null=True, + ), + ), + ( + "enabled", + models.BooleanField( + help_text="Whether the bot will spawn countryballs in this guild" + ), + ), + ("silent", models.BooleanField()), + ], + options={ + "db_table": "guildconfig", + "managed": True, + }, + ), + migrations.CreateModel( + name="Player", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("discord_id", models.BigIntegerField(help_text="Discord user ID", unique=True)), + ( + "donation_policy", + models.SmallIntegerField( + choices=[ + (1, "Always Accept"), + (2, "Request Approval"), + (3, "Always Deny"), + (4, "Friends Only"), + ], + help_text="How you want to handle donations", + ), + ), + ( + "privacy_policy", + models.SmallIntegerField( + choices=[(1, "Allow"), (2, "Deny"), (3, "Same Server"), (4, "Friends")], + help_text="How you want to handle inventory privacy", + ), + ), + ( + "mention_policy", + models.SmallIntegerField( + choices=[(1, "Allow"), (2, "Deny")], help_text="Control the bot's mentions" + ), + ), + ( + "friend_policy", + models.SmallIntegerField( + choices=[(1, "Allow"), (2, "Deny")], + help_text="Open or close your friend requests", + ), + ), + ], + options={ + "db_table": "player", + "managed": True, + }, + ), + migrations.CreateModel( + name="Regime", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("name", models.CharField(max_length=64)), + ( + "background", + models.ImageField( + help_text="1428x2000 PNG image", max_length=200, upload_to="" + ), + ), + ], + options={ + "db_table": "regime", + "managed": True, + }, + ), + migrations.CreateModel( + name="Special", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("name", models.CharField(max_length=64)), + ( + "catch_phrase", + models.CharField( + blank=True, + help_text="Sentence sent in bonus when someone catches a special card", + max_length=128, + null=True, + ), + ), + ( + "start_date", + models.DateTimeField( + blank=True, + help_text="Start time of the event. If blank, starts immediately", + null=True, + ), + ), + ( + "end_date", + models.DateTimeField( + blank=True, + help_text="End time of the event. If blank, the event is permanent", + null=True, + ), + ), + ( + "rarity", + models.FloatField( + help_text="Value between 0 and 1, chances of using this " + "special background." + ), + ), + ( + "emoji", + models.CharField( + blank=True, + help_text="Either a unicode character or a discord emoji ID", + max_length=20, + null=True, + ), + ), + ( + "background", + models.ImageField( + blank=True, + help_text="1428x2000 PNG image", + max_length=200, + null=True, + upload_to="", + ), + ), + ( + "tradeable", + models.BooleanField( + default=True, help_text="Whether balls of this event can be traded" + ), + ), + ( + "hidden", + models.BooleanField( + default=False, help_text="Hides the event from user commands" + ), + ), + ( + "credits", + models.CharField( + null=True, + help_text="Author of the special event artwork", + max_length=64, + ), + ), + ], + options={ + "db_table": "special", + "managed": True, + }, + ), + migrations.CreateModel( + name="Ball", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("country", models.CharField(max_length=48, unique=True)), + ("health", models.IntegerField(help_text="Ball health stat")), + ("attack", models.IntegerField(help_text="Ball attack stat")), + ("rarity", models.FloatField(help_text="Rarity of this ball")), + ("emoji_id", models.BigIntegerField(help_text="Emoji ID for this ball")), + ( + "wild_card", + models.ImageField( + help_text="Image used when a new ball spawns in the wild", + max_length=200, + upload_to="", + ), + ), + ( + "collection_card", + models.ImageField( + help_text="Image used when displaying balls", max_length=200, upload_to="" + ), + ), + ( + "credits", + models.CharField(help_text="Author of the collection artwork", max_length=64), + ), + ( + "capacity_name", + models.CharField( + help_text="Name of the countryball's capacity", max_length=64 + ), + ), + ( + "capacity_description", + models.CharField( + help_text="Description of the countryball's capacity", max_length=256 + ), + ), + ( + "capacity_logic", + models.JSONField( + blank=True, default=dict, help_text="Effect of this capacity" + ), + ), + ( + "enabled", + models.BooleanField( + default=True, help_text="Enables spawning and show in completion" + ), + ), + ( + "short_name", + models.CharField( + blank=True, + help_text="An alternative shorter name used only when generating the " + "card, if the base name is too long.", + max_length=12, + null=True, + ), + ), + ( + "catch_names", + models.TextField( + blank=True, + help_text="Additional possible names for catching this ball, " + "separated by semicolons", + null=True, + ), + ), + ( + "tradeable", + models.BooleanField( + default=True, help_text="Whether this ball can be traded with others" + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True, null=True)), + ("translations", models.TextField(blank=True, null=True)), + ( + "economy", + models.ForeignKey( + blank=True, + help_text="Economical regime of this country", + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="bd_models.economy", + ), + ), + ( + "regime", + models.ForeignKey( + help_text="Political regime of this country", + on_delete=django.db.models.deletion.CASCADE, + to="bd_models.regime", + ), + ), + ], + options={ + "db_table": "ball", + "managed": True, + }, + ), + migrations.CreateModel( + name="Friendship", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("since", models.DateTimeField(auto_now_add=True)), + ( + "player1", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.player" + ), + ), + ( + "player2", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="friendship_player2_set", + to="bd_models.player", + ), + ), + ], + options={ + "db_table": "friendship", + "managed": True, + }, + ), + migrations.CreateModel( + name="Block", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("date", models.DateTimeField(auto_now_add=True)), + ( + "player1", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.player" + ), + ), + ( + "player2", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="block_player2_set", + to="bd_models.player", + ), + ), + ], + options={ + "db_table": "block", + "managed": True, + }, + ), + migrations.CreateModel( + name="BallInstance", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("catch_date", models.DateTimeField()), + ("health_bonus", models.IntegerField()), + ("attack_bonus", models.IntegerField()), + ("favorite", models.BooleanField()), + ( + "server_id", + models.BigIntegerField( + blank=True, + help_text="Discord server ID where this ball was caught", + null=True, + ), + ), + ("tradeable", models.BooleanField()), + ("extra_data", models.JSONField(blank=True, default=dict)), + ( + "locked", + models.DateTimeField( + blank=True, + help_text="If the instance was locked for a trade and when", + null=True, + ), + ), + ("spawned_time", models.DateTimeField(blank=True, null=True)), + ( + "ball", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.ball" + ), + ), + ( + "player", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.player" + ), + ), + ( + "trade_player", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="ballinstance_trade_player_set", + to="bd_models.player", + ), + ), + ( + "special", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="bd_models.special", + ), + ), + ], + options={ + "db_table": "ballinstance", + "managed": True, + "unique_together": {("player", "id")}, + }, + ), + migrations.CreateModel( + name="Trade", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("date", models.DateTimeField(auto_now_add=True)), + ( + "player1", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.player" + ), + ), + ( + "player2", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="trade_player2_set", + to="bd_models.player", + ), + ), + ], + options={ + "db_table": "trade", + "managed": True, + }, + ), + migrations.CreateModel( + name="TradeObject", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ( + "ballinstance", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.ballinstance" + ), + ), + ( + "player", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.player" + ), + ), + ( + "trade", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="bd_models.trade" + ), + ), + ], + options={ + "db_table": "tradeobject", + "managed": True, + }, + ), + migrations.RunPython( + code=default_models_forward, reverse_code=default_models_backward, atomic=True + ), + ] diff --git a/admin_panel/bd_models/migrations/0005_alter_ball_short_name.py b/admin_panel/bd_models/migrations/0005_alter_ball_short_name.py new file mode 100644 index 000000000..18d8a0d67 --- /dev/null +++ b/admin_panel/bd_models/migrations/0005_alter_ball_short_name.py @@ -0,0 +1,24 @@ +# Generated by Django 5.1.4 on 2025-02-12 17:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bd_models", "0004_check_aerich_migrations_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="ball", + name="short_name", + field=models.CharField( + blank=True, + help_text="An alternative shorter name used only when generating the card, " + "if the base name is too long.", + max_length=24, + null=True, + ), + ), + ] diff --git a/admin_panel/bd_models/models.py b/admin_panel/bd_models/models.py index 6d72f897f..81cb3324a 100644 --- a/admin_panel/bd_models/models.py +++ b/admin_panel/bd_models/models.py @@ -36,7 +36,7 @@ def __str__(self) -> str: return str(self.guild_id) class Meta: - managed = False + managed = True db_table = "guildconfig" @@ -97,7 +97,7 @@ def __str__(self) -> str: ) class Meta: - managed = False + managed = True db_table = "player" @@ -109,7 +109,7 @@ def __str__(self) -> str: return self.name class Meta: - managed = False + managed = True db_table = "economy" verbose_name_plural = "economies" @@ -122,7 +122,7 @@ def __str__(self) -> str: return self.name class Meta: - managed = False + managed = True db_table = "regime" @@ -156,12 +156,15 @@ class Special(models.Model): help_text="Whether balls of this event can be traded", default=True ) hidden = models.BooleanField(help_text="Hides the event from user commands", default=False) + credits = models.CharField( + max_length=64, help_text="Author of the special event artwork", null=True + ) def __str__(self) -> str: return self.name class Meta: - managed = False + managed = True db_table = "special" @@ -190,7 +193,7 @@ class Ball(models.Model): help_text="Enables spawning and show in completion", default=True ) short_name = models.CharField( - max_length=12, + max_length=24, blank=True, null=True, help_text="An alternative shorter name used only when generating the card, " @@ -248,7 +251,7 @@ def lower_catch_names(names: str | None) -> str | None: return super().save(force_insert, force_update, using, update_fields) class Meta: - managed = False + managed = True db_table = "ball" @@ -308,7 +311,7 @@ def description(self) -> SafeText: return mark_safe(f"{emoji} {text} ATK:{self.attack_bonus:+d}% HP:{self.health_bonus:+d}%") class Meta: - managed = False + managed = True db_table = "ballinstance" unique_together = (("player", "id"),) @@ -320,7 +323,7 @@ class BlacklistedID(models.Model): moderator_id = models.BigIntegerField(blank=True, null=True) class Meta: - managed = False + managed = True db_table = "blacklistedid" @@ -331,7 +334,7 @@ class BlacklistedGuild(models.Model): moderator_id = models.BigIntegerField(blank=True, null=True) class Meta: - managed = False + managed = True db_table = "blacklistedguild" @@ -344,7 +347,7 @@ class BlacklistHistory(models.Model): action_type = models.CharField(max_length=64, default="blacklist") class Meta: - managed = False + managed = True db_table = "blacklisthistory" verbose_name_plural = "blacklisthistories" @@ -361,7 +364,7 @@ def __str__(self) -> str: return f"Trade #{self.pk:0X}" class Meta: - managed = False + managed = True db_table = "trade" @@ -374,7 +377,7 @@ class TradeObject(models.Model): trade_id: int class Meta: - managed = False + managed = True db_table = "tradeobject" @@ -388,7 +391,7 @@ class Friendship(models.Model): player2_id: int class Meta: - managed = False + managed = True db_table = "friendship" @@ -400,5 +403,5 @@ class Block(models.Model): player2_id: int class Meta: - managed = False + managed = True db_table = "block" diff --git a/ballsdex/__main__.py b/ballsdex/__main__.py index e2c3bbc31..550709b43 100755 --- a/ballsdex/__main__.py +++ b/ballsdex/__main__.py @@ -11,7 +11,6 @@ import discord import yarl -from aerich import Command from discord.ext.commands import when_mentioned_or from rich import print from tortoise import Tortoise @@ -28,7 +27,7 @@ "connections": {"default": os.environ.get("BALLSDEXBOT_DB_URL")}, "apps": { "models": { - "models": ["ballsdex.core.models", "aerich.models"], + "models": ["ballsdex.core.models"], "default_connection": "default", }, }, @@ -241,16 +240,6 @@ async def init_tortoise(db_url: str, *, skip_migrations: bool = False): log.debug(f"Database URL: {db_url}") await Tortoise.init(config=TORTOISE_ORM) - if skip_migrations: - return - - # migrations - command = Command(TORTOISE_ORM, app="models") - await command.init() - migrations = await command.upgrade() - if migrations: - log.info(f"Ran {len(migrations)} migrations: {', '.join(migrations)}") - def main(): bot = None diff --git a/ballsdex/core/models.py b/ballsdex/core/models.py index b706b9d75..a2794c9e4 100755 --- a/ballsdex/core/models.py +++ b/ballsdex/core/models.py @@ -125,7 +125,7 @@ class Ball(models.Model): country = fields.CharField(max_length=48, unique=True, description="Name of this countryball") short_name = fields.CharField( - max_length=12, + max_length=24, null=True, default=None, description="Alternative shorter name to be used in card design, " diff --git a/docker-compose.yml b/docker-compose.yml index d6bdd4238..bd7f753c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,11 @@ services: source: ./ target: /code tty: true - command: poetry run python3 -m ballsdex --dev + command: > + bash -c " + cd admin_panel && + poetry run python3 manage.py migrate --no-input --fake-initial && + cd .. && poetry run python3 -m ballsdex" admin-panel: image: ballsdex @@ -48,7 +52,7 @@ services: working_dir: /code/admin_panel command: > bash -c " - poetry run python3 manage.py migrate --no-input && + poetry run python3 manage.py migrate --no-input --fake-initial && poetry run python3 manage.py collectstatic --no-input && poetry run uvicorn admin_panel.asgi:application --host 0.0.0.0" diff --git a/migrations/models/0_20220909204856_init.sql b/migrations/models/0_20220909204856_init.sql deleted file mode 100644 index f64341852..000000000 --- a/migrations/models/0_20220909204856_init.sql +++ /dev/null @@ -1,72 +0,0 @@ --- upgrade -- -CREATE TABLE IF NOT EXISTS "ball" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "country" VARCHAR(48) NOT NULL UNIQUE, - "regime" SMALLINT NOT NULL, - "economy" SMALLINT NOT NULL, - "health" INT NOT NULL, - "attack" INT NOT NULL, - "rarity" DOUBLE PRECISION NOT NULL, - "emoji_id" INT NOT NULL, - "wild_card" VARCHAR(200) NOT NULL, - "collection_card" VARCHAR(200) NOT NULL, - "credits" VARCHAR(64) NOT NULL, - "capacity_name" VARCHAR(64) NOT NULL, - "capacity_description" VARCHAR(256) NOT NULL, - "capacity_logic" JSONB NOT NULL -); -COMMENT ON COLUMN "ball"."regime" IS 'Political regime of this country'; -COMMENT ON COLUMN "ball"."economy" IS 'Economical regime of this country'; -COMMENT ON COLUMN "ball"."health" IS 'Ball health stat'; -COMMENT ON COLUMN "ball"."attack" IS 'Ball attack stat'; -COMMENT ON COLUMN "ball"."rarity" IS 'Rarity of this ball'; -COMMENT ON COLUMN "ball"."emoji_id" IS 'Emoji ID for this ball'; -COMMENT ON COLUMN "ball"."wild_card" IS 'Image used when a new ball spawns in the wild'; -COMMENT ON COLUMN "ball"."collection_card" IS 'Image used when displaying balls'; -COMMENT ON COLUMN "ball"."credits" IS 'Author of the collection artwork'; -COMMENT ON COLUMN "ball"."capacity_name" IS 'Name of the countryball''s capacity'; -COMMENT ON COLUMN "ball"."capacity_description" IS 'Description of the countryball''s capacity'; -COMMENT ON COLUMN "ball"."capacity_logic" IS 'Effect of this capacity'; -CREATE TABLE IF NOT EXISTS "guildconfig" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "guild_id" INT NOT NULL UNIQUE, - "spawn_channel" INT, - "enabled" BOOL NOT NULL DEFAULT True -); -COMMENT ON COLUMN "guildconfig"."guild_id" IS 'Discord guild ID'; -COMMENT ON COLUMN "guildconfig"."spawn_channel" IS 'Discord channel ID where balls will spawn'; -COMMENT ON COLUMN "guildconfig"."enabled" IS 'Whether the bot will spawn countryballs in this guild'; -CREATE TABLE IF NOT EXISTS "player" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "discord_id" INT NOT NULL UNIQUE -); -COMMENT ON COLUMN "player"."discord_id" IS 'Discord user ID'; -CREATE TABLE IF NOT EXISTS "ballinstance" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "count" INT NOT NULL, - "catch_date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, - "special" INT NOT NULL DEFAULT 0, - "health_bonus" INT NOT NULL DEFAULT 0, - "attack_bonus" INT NOT NULL DEFAULT 0, - "ball_id" INT NOT NULL REFERENCES "ball" ("id") ON DELETE CASCADE, - "player_id" INT NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE, - "trade_player_id" INT NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE, - CONSTRAINT "uid_ballinstanc_player__f154f9" UNIQUE ("player_id", "id") -); -COMMENT ON COLUMN "ballinstance"."special" IS 'Defines rare instances, like a shiny'; -CREATE TABLE IF NOT EXISTS "user" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "username" VARCHAR(50) NOT NULL UNIQUE, - "password" VARCHAR(200) NOT NULL, - "last_login" TIMESTAMPTZ NOT NULL, - "avatar" VARCHAR(200) NOT NULL DEFAULT '', - "intro" TEXT NOT NULL, - "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP -); -COMMENT ON COLUMN "user"."last_login" IS 'Last Login'; -CREATE TABLE IF NOT EXISTS "aerich" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "version" VARCHAR(255) NOT NULL, - "app" VARCHAR(100) NOT NULL, - "content" JSONB NOT NULL -); diff --git a/migrations/models/10_20221022184330_update.sql b/migrations/models/10_20221022184330_update.sql deleted file mode 100644 index efcd206bb..000000000 --- a/migrations/models/10_20221022184330_update.sql +++ /dev/null @@ -1,6 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" DROP CONSTRAINT "ballinstance_trade_player_id_fkey"; -ALTER TABLE "ballinstance" ADD CONSTRAINT "fk_ballinst_player_6b1aca0e" FOREIGN KEY ("trade_player_id") REFERENCES "player" ("id") ON DELETE SET NULL; --- downgrade -- -ALTER TABLE "ballinstance" DROP CONSTRAINT "fk_ballinst_player_6b1aca0e"; -ALTER TABLE "ballinstance" ADD CONSTRAINT "ballinstance_trade_player_id_fkey" FOREIGN KEY ("trade_player_id") REFERENCES "player" ("id") ON DELETE CASCADE; diff --git a/migrations/models/11_20230127140747_update.sql b/migrations/models/11_20230127140747_update.sql deleted file mode 100644 index c17446354..000000000 --- a/migrations/models/11_20230127140747_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "blacklistedid" ADD "reason" TEXT; --- downgrade -- -ALTER TABLE "blacklistedid" DROP COLUMN "reason"; diff --git a/migrations/models/12_20230224112031_update.sql b/migrations/models/12_20230224112031_update.sql deleted file mode 100644 index 6f2df25c6..000000000 --- a/migrations/models/12_20230224112031_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ADD "catch_names" TEXT; --- downgrade -- -ALTER TABLE "ball" DROP COLUMN "catch_names"; diff --git a/migrations/models/13_20230301173448_update.sql b/migrations/models/13_20230301173448_update.sql deleted file mode 100644 index 2e44cd75d..000000000 --- a/migrations/models/13_20230301173448_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" DROP COLUMN "count"; --- downgrade -- -ALTER TABLE "ballinstance" ADD "count" INT NOT NULL; diff --git a/migrations/models/14_20230326131235_update.sql b/migrations/models/14_20230326131235_update.sql deleted file mode 100644 index 4a558c982..000000000 --- a/migrations/models/14_20230326131235_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "player" ADD "donation_policy" SMALLINT NOT NULL DEFAULT 1; --- downgrade -- -ALTER TABLE "player" DROP COLUMN "donation_policy"; diff --git a/migrations/models/15_20230404133020_update.sql b/migrations/models/15_20230404133020_update.sql deleted file mode 100644 index 57682da0d..000000000 --- a/migrations/models/15_20230404133020_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "blacklistedid" ADD "date" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP; --- downgrade -- -ALTER TABLE "blacklistedid" DROP COLUMN "date"; diff --git a/migrations/models/16_20230410144614_update.sql b/migrations/models/16_20230410144614_update.sql deleted file mode 100644 index 99dd7a26a..000000000 --- a/migrations/models/16_20230410144614_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ADD "tradeable" BOOL NOT NULL DEFAULT True; --- downgrade -- -ALTER TABLE "ball" DROP COLUMN "tradeable"; diff --git a/migrations/models/17_20230420000356_update.sql b/migrations/models/17_20230420000356_update.sql deleted file mode 100644 index daf619832..000000000 --- a/migrations/models/17_20230420000356_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "special" ADD "emoji" VARCHAR(20); --- downgrade -- -ALTER TABLE "special" DROP COLUMN "emoji"; diff --git a/migrations/models/19_20230522100203_update.sql b/migrations/models/19_20230522100203_update.sql deleted file mode 100644 index 2c736e44c..000000000 --- a/migrations/models/19_20230522100203_update.sql +++ /dev/null @@ -1,10 +0,0 @@ --- upgrade -- -CREATE TABLE IF NOT EXISTS "blacklistedguild" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "discord_id" BIGINT NOT NULL UNIQUE, - "reason" TEXT, - "date" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP -); -COMMENT ON COLUMN "blacklistedguild"."discord_id" IS 'Discord Guild ID'; --- downgrade -- -DROP TABLE IF EXISTS "blacklistedguild"; diff --git a/migrations/models/1_20220909223048_update.sql b/migrations/models/1_20220909223048_update.sql deleted file mode 100644 index bc21ee5d0..000000000 --- a/migrations/models/1_20220909223048_update.sql +++ /dev/null @@ -1,10 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ALTER COLUMN "emoji_id" TYPE BIGINT USING "emoji_id"::BIGINT; -ALTER TABLE "guildconfig" ALTER COLUMN "spawn_channel" TYPE BIGINT USING "spawn_channel"::BIGINT; -ALTER TABLE "guildconfig" ALTER COLUMN "guild_id" TYPE BIGINT USING "guild_id"::BIGINT; -ALTER TABLE "player" ALTER COLUMN "discord_id" TYPE BIGINT USING "discord_id"::BIGINT; --- downgrade -- -ALTER TABLE "ball" ALTER COLUMN "emoji_id" TYPE INT USING "emoji_id"::INT; -ALTER TABLE "player" ALTER COLUMN "discord_id" TYPE INT USING "discord_id"::INT; -ALTER TABLE "guildconfig" ALTER COLUMN "spawn_channel" TYPE INT USING "spawn_channel"::INT; -ALTER TABLE "guildconfig" ALTER COLUMN "guild_id" TYPE INT USING "guild_id"::INT; diff --git a/migrations/models/20_20230725165036_update.sql b/migrations/models/20_20230725165036_update.sql deleted file mode 100644 index 720a834c0..000000000 --- a/migrations/models/20_20230725165036_update.sql +++ /dev/null @@ -1,54 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ADD "economy_id" INT; -ALTER TABLE "ball" ADD "regime_id" INT; -- Add NOT NULL after we filled the table -- -CREATE TABLE IF NOT EXISTS "economy" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "name" VARCHAR(64) NOT NULL, - "icon" VARCHAR(200) NOT NULL -); -COMMENT ON COLUMN "ball"."economy_id" IS 'Economical regime of this country'; -COMMENT ON COLUMN "ball"."regime_id" IS 'Political regime of this country'; -COMMENT ON COLUMN "economy"."icon" IS '512x512 PNG image';; -CREATE TABLE IF NOT EXISTS "regime" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "name" VARCHAR(64) NOT NULL, - "background" VARCHAR(200) NOT NULL -); -COMMENT ON COLUMN "regime"."background" IS '1428x2000 PNG image';; -ALTER TABLE "special" ADD "background" VARCHAR(200); -UPDATE "special" SET "background" = "democracy_card"; -ALTER TABLE "special" DROP COLUMN "democracy_card"; -ALTER TABLE "special" DROP COLUMN "union_card"; -ALTER TABLE "special" DROP COLUMN "dictatorship_card"; -ALTER TABLE "ball" ADD CONSTRAINT "fk_ball_regime_d7fd92a9" FOREIGN KEY ("regime_id") REFERENCES "regime" ("id") ON DELETE CASCADE; -ALTER TABLE "ball" ADD CONSTRAINT "fk_ball_economy_cfe9c5c3" FOREIGN KEY ("economy_id") REFERENCES "economy" ("id") ON DELETE SET NULL; -INSERT INTO "economy" ("name", "icon") VALUES - ('Capitalist', '/ballsdex/core/image_generator/src/capitalist.png'), - ('Communist', '/ballsdex/core/image_generator/src/communist.png'); -INSERT INTO "regime" ("name", "background") VALUES - ('Democracy', '/ballsdex/core/image_generator/src/democracy.png'), - ('Dictatorship', '/ballsdex/core/image_generator/src/dictatorship.png'), - ('Union', '/ballsdex/core/image_generator/src/union.png'); -UPDATE "ball" SET "economy_id" = "economy" WHERE "economy" != 3; -UPDATE "ball" SET "economy_id" = null WHERE "economy" = 3; -UPDATE "ball" SET "regime_id" = "regime"; -ALTER TABLE "ball" ALTER COLUMN "regime_id" SET NOT NULL; -- Table filled, now we can put non-nullable constraint -- -ALTER TABLE "ball" DROP COLUMN "economy"; -ALTER TABLE "ball" DROP COLUMN "regime"; --- downgrade -- -ALTER TABLE "ball" DROP CONSTRAINT "fk_ball_economy_cfe9c5c3"; -ALTER TABLE "ball" DROP CONSTRAINT "fk_ball_regime_d7fd92a9"; -ALTER TABLE "ball" ADD "regime" SMALLINT; -ALTER TABLE "ball" ADD "economy" SMALLINT; -UPDATE "ball" SET "regime" = "regime_id"; -UPDATE "ball" SET "economy" = "economy_id"; -ALTER TABLE "ball" DROP COLUMN "economy_id"; -ALTER TABLE "ball" DROP COLUMN "regime_id"; -ALTER TABLE "special" ADD "democracy_card" VARCHAR(200); -ALTER TABLE "special" ADD "union_card" VARCHAR(200); -ALTER TABLE "special" ADD "dictatorship_card" VARCHAR(200); -ALTER TABLE "special" DROP COLUMN "background"; -DROP TABLE IF EXISTS "economy"; -DROP TABLE IF EXISTS "regime"; -ALTER TABLE "ball" ALTER COLUMN "regime" SET NOT NULL; -ALTER TABLE "ball" ALTER COLUMN "regime" SET NOT NULL; diff --git a/migrations/models/21_20231113175415_update.sql b/migrations/models/21_20231113175415_update.sql deleted file mode 100644 index ba09e4062..000000000 --- a/migrations/models/21_20231113175415_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "server_id" BIGINT; --- downgrade -- -ALTER TABLE "ballinstance" DROP COLUMN "spawn_time"; diff --git a/migrations/models/22_20231115171322_update.sql b/migrations/models/22_20231115171322_update.sql deleted file mode 100644 index 93e0d32e3..000000000 --- a/migrations/models/22_20231115171322_update.sql +++ /dev/null @@ -1,15 +0,0 @@ --- upgrade -- -CREATE TABLE IF NOT EXISTS "trade" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, - "player1_id" INT NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE, - "player2_id" INT NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE -);; -CREATE TABLE IF NOT EXISTS "tradeobject" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "ballinstance_id" INT NOT NULL REFERENCES "ballinstance" ("id") ON DELETE CASCADE, - "player_id" INT NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE, - "trade_id" INT NOT NULL REFERENCES "trade" ("id") ON DELETE CASCADE -);-- downgrade -- -DROP TABLE IF EXISTS "trade"; -DROP TABLE IF EXISTS "tradeobject"; diff --git a/migrations/models/23_20231205113247_update.sql b/migrations/models/23_20231205113247_update.sql deleted file mode 100644 index 5161f1d71..000000000 --- a/migrations/models/23_20231205113247_update.sql +++ /dev/null @@ -1,6 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "tradeable" BOOL NOT NULL DEFAULT True; -ALTER TABLE "special" ADD "tradeable" BOOL NOT NULL DEFAULT True; --- downgrade -- -ALTER TABLE "special" DROP COLUMN "tradeable"; -ALTER TABLE "ballinstance" DROP COLUMN "tradeable"; diff --git a/migrations/models/24_20231219112238_update.sql b/migrations/models/24_20231219112238_update.sql deleted file mode 100644 index d627d699f..000000000 --- a/migrations/models/24_20231219112238_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "special" ADD "hidden" BOOL NOT NULL DEFAULT False; --- downgrade -- -ALTER TABLE "special" DROP COLUMN "hidden"; diff --git a/migrations/models/25_20240109160009_update.sql b/migrations/models/25_20240109160009_update.sql deleted file mode 100644 index c5369c3de..000000000 --- a/migrations/models/25_20240109160009_update.sql +++ /dev/null @@ -1,12 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ADD "created_at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP; -UPDATE ball b -SET created_at = bi.catch_date -FROM ( - SELECT ball_id, MIN(catch_date) AS catch_date - FROM ballinstance - GROUP BY ball_id -) AS bi -WHERE b.id = bi.ball_id; --- downgrade -- -ALTER TABLE "ball" DROP COLUMN "created_at"; diff --git a/migrations/models/26_20240121004430_update.sql b/migrations/models/26_20240121004430_update.sql deleted file mode 100644 index e419d7ae8..000000000 --- a/migrations/models/26_20240121004430_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "player" ADD "privacy_policy" SMALLINT NOT NULL DEFAULT 2; --- downgrade -- -ALTER TABLE "player" DROP COLUMN "privacy_policy"; diff --git a/migrations/models/27_20240123140205_update.sql b/migrations/models/27_20240123140205_update.sql deleted file mode 100644 index a9aa7e671..000000000 --- a/migrations/models/27_20240123140205_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "extra_data" JSONB NOT NULL DEFAULT '{}'::JSONB; --- downgrade -- -ALTER TABLE "ballinstance" DROP COLUMN "extra_data"; diff --git a/migrations/models/28_20240225164026_update.sql b/migrations/models/28_20240225164026_update.sql deleted file mode 100644 index 300c8a57c..000000000 --- a/migrations/models/28_20240225164026_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "locked" TIMESTAMPTZ; --- downgrade -- -ALTER TABLE "ballinstance" DROP COLUMN "locked"; diff --git a/migrations/models/29_20240320142916_update.sql b/migrations/models/29_20240320142916_update.sql deleted file mode 100644 index a10ef7407..000000000 --- a/migrations/models/29_20240320142916_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "spawned_time" TIMESTAMPTZ; --- downgrade -- -ALTER TABLE "ballinstance" DROP COLUMN "spawned_time"; diff --git a/migrations/models/2_20220910020800_update.sql b/migrations/models/2_20220910020800_update.sql deleted file mode 100644 index 31a51a3a3..000000000 --- a/migrations/models/2_20220910020800_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ALTER COLUMN "trade_player_id" DROP NOT NULL; --- downgrade -- -ALTER TABLE "ballinstance" ALTER COLUMN "trade_player_id" SET NOT NULL; diff --git a/migrations/models/30_20240812140936_update.sql b/migrations/models/30_20240812140936_update.sql deleted file mode 100644 index 5c1e028d9..000000000 --- a/migrations/models/30_20240812140936_update.sql +++ /dev/null @@ -1,18 +0,0 @@ --- upgrade -- -CREATE TABLE IF NOT EXISTS "blacklisthistory" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "discord_id" BIGINT NOT NULL, - "moderator_id" BIGINT NOT NULL, - "reason" TEXT, - "date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, - "id_type" VARCHAR(64) NOT NULL DEFAULT 'user', - "action_type" VARCHAR(64) NOT NULL DEFAULT 'blacklist' -); -COMMENT ON COLUMN "blacklisthistory"."discord_id" IS 'Discord ID'; -COMMENT ON COLUMN "blacklisthistory"."moderator_id" IS 'Discord Moderator ID';; -ALTER TABLE "blacklistedguild" ADD "moderator_id" BIGINT; -ALTER TABLE "blacklistedid" ADD "moderator_id" BIGINT; --- downgrade -- -ALTER TABLE "blacklistedid" DROP COLUMN "moderator_id"; -ALTER TABLE "blacklistedguild" DROP COLUMN "moderator_id"; -DROP TABLE IF EXISTS "blacklisthistory"; diff --git a/migrations/models/32_20240830012954_update.sql b/migrations/models/32_20240830012954_update.sql deleted file mode 100644 index ffe716a39..000000000 --- a/migrations/models/32_20240830012954_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "guildconfig" ADD "silent" BOOL NOT NULL DEFAULT False; --- downgrade -- -ALTER TABLE "guildconfig" DROP COLUMN "silent"; \ No newline at end of file diff --git a/migrations/models/33_20240902113932_update.sql b/migrations/models/33_20240902113932_update.sql deleted file mode 100644 index fcb21ae9d..000000000 --- a/migrations/models/33_20240902113932_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "player" ADD "mention_policy" SMALLINT NOT NULL DEFAULT 1; --- downgrade -- -ALTER TABLE "player" DROP COLUMN "mention_policy"; diff --git a/migrations/models/33_20240906092911_update.sql b/migrations/models/33_20240906092911_update.sql deleted file mode 100644 index 8057ac15b..000000000 --- a/migrations/models/33_20240906092911_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ADD "translations" TEXT; --- downgrade -- -ALTER TABLE "ball" DROP COLUMN "translations"; diff --git a/migrations/models/34_20240909212154_update.sql b/migrations/models/34_20240909212154_update.sql deleted file mode 100644 index 743f7e147..000000000 --- a/migrations/models/34_20240909212154_update.sql +++ /dev/null @@ -1,16 +0,0 @@ --- upgrade -- -CREATE TABLE IF NOT EXISTS "friendship" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "since" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, - "player1_id" INT NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE, - "player2_id" INT NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE -); -CREATE TABLE IF NOT EXISTS "block" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, - "player1_id" INTEGER NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE, - "player2_id" INTEGER NOT NULL REFERENCES "player" ("id") ON DELETE CASCADE -); --- downgrade -- -DROP TABLE IF EXISTS "friendship"; -DROP TABLE IF EXISTS "block"; diff --git a/migrations/models/35_20240913181322_update.sql b/migrations/models/35_20240913181322_update.sql deleted file mode 100644 index aee4f4be1..000000000 --- a/migrations/models/35_20240913181322_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "player" ADD "friend_policy" SMALLINT NOT NULL DEFAULT 1; --- downgrade -- -ALTER TABLE "player" DROP COLUMN "friend_policy"; diff --git a/migrations/models/36_20241009120300_update.sql b/migrations/models/36_20241009120300_update.sql deleted file mode 100644 index f2e7ac006..000000000 --- a/migrations/models/36_20241009120300_update.sql +++ /dev/null @@ -1,25 +0,0 @@ --- upgrade -- -ALTER TABLE "special" ALTER COLUMN "start_date" DROP NOT NULL; -ALTER TABLE "special" ALTER COLUMN "end_date" DROP NOT NULL; - -WITH shiny_id AS ( - INSERT INTO "special" (name, catch_phrase, rarity, emoji, background) VALUES - ('Shiny', '**It''s a shiny countryball!**', 0.00048828125, - '✨', '/ballsdex/core/image_generator/src/shiny.png') - RETURNING id) -UPDATE "ballinstance" SET "special_id" = (SELECT id FROM shiny_id) WHERE "shiny" = true; - -ALTER TABLE "ballinstance" DROP COLUMN "shiny"; --- downgrade -- -ALTER TABLE "ballinstance" ADD "shiny" BOOL NOT NULL DEFAULT False; - -UPDATE "ballinstance" SET "shiny" = true -FROM "special" s -WHERE s.id = special_id -AND s.background = '/ballsdex/core/image_generator/src/shiny.png'; - -DELETE FROM "special" WHERE -background = '/ballsdex/core/image_generator/src/shiny.png'; - -ALTER TABLE "special" ALTER COLUMN "start_date" SET NOT NULL; -ALTER TABLE "special" ALTER COLUMN "end_date" SET NOT NULL; diff --git a/migrations/models/36_20241124155350_update.sql b/migrations/models/36_20241124155350_update.sql deleted file mode 100644 index 0cb3d0fb4..000000000 --- a/migrations/models/36_20241124155350_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "special" ADD "credits" VARCHAR(64); --- downgrade -- -ALTER TABLE "special" DROP COLUMN "credits"; diff --git a/migrations/models/37_20250110192500_update.sql b/migrations/models/37_20250110192500_update.sql deleted file mode 100644 index 056d74cd5..000000000 --- a/migrations/models/37_20250110192500_update.sql +++ /dev/null @@ -1,18 +0,0 @@ --- upgrade -- -CREATE INDEX "idx_ballinstanc_ball_id_0752b7" ON "ballinstance" ("ball_id"); -CREATE INDEX "idx_ballinstanc_player__4a2d71" ON "ballinstance" ("player_id"); -CREATE INDEX "idx_ballinstanc_special_f3f7e1" ON "ballinstance" ("special_id"); -CREATE INDEX "idx_trade_player1_35694c" ON "trade" ("player1_id"); -CREATE INDEX "idx_trade_player2_5abb89" ON "trade" ("player2_id"); -CREATE INDEX "idx_tradeobject_player__04bc1c" ON "tradeobject" ("player_id"); -CREATE INDEX "idx_tradeobject_trade_i_255bae" ON "tradeobject" ("trade_id"); -CREATE INDEX "idx_tradeobject_ballins_49034b" ON "tradeobject" ("ballinstance_id"); --- downgrade -- -DROP INDEX "idx_ballinstanc_special_f3f7e1"; -DROP INDEX "idx_ballinstanc_player__4a2d71"; -DROP INDEX "idx_ballinstanc_ball_id_0752b7"; -DROP INDEX "idx_tradeobject_ballins_49034b"; -DROP INDEX "idx_tradeobject_trade_i_255bae"; -DROP INDEX "idx_tradeobject_player__04bc1c"; -DROP INDEX "idx_trade_player2_5abb89"; -DROP INDEX "idx_trade_player1_35694c"; diff --git a/migrations/models/38_20250120182312_update.sql b/migrations/models/38_20250120182312_update.sql deleted file mode 100644 index 2d584342a..000000000 --- a/migrations/models/38_20250120182312_update.sql +++ /dev/null @@ -1,13 +0,0 @@ --- upgrade -- -DROP TABLE IF EXISTS "user"; --- downgrade -- -CREATE TABLE IF NOT EXISTS "user" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "username" VARCHAR(50) NOT NULL UNIQUE, - "password" VARCHAR(200) NOT NULL, - "last_login" TIMESTAMPTZ NOT NULL, - "avatar" VARCHAR(200) NOT NULL DEFAULT '', - "intro" TEXT NOT NULL, - "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP -); -COMMENT ON COLUMN "user"."last_login" IS 'Last Login'; diff --git a/migrations/models/3_20220913220923_update.sql b/migrations/models/3_20220913220923_update.sql deleted file mode 100644 index 751acb951..000000000 --- a/migrations/models/3_20220913220923_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ADD "enabled" BOOL NOT NULL DEFAULT True; --- downgrade -- -ALTER TABLE "ball" DROP COLUMN "enabled"; diff --git a/migrations/models/4_20220915164836_update.sql b/migrations/models/4_20220915164836_update.sql deleted file mode 100644 index 80bb0971b..000000000 --- a/migrations/models/4_20220915164836_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "favorite" BOOL NOT NULL DEFAULT False; --- downgrade -- -ALTER TABLE "ballinstance" DROP COLUMN "favorite"; diff --git a/migrations/models/5_20220924005726_update.sql b/migrations/models/5_20220924005726_update.sql deleted file mode 100644 index 979ced1aa..000000000 --- a/migrations/models/5_20220924005726_update.sql +++ /dev/null @@ -1,6 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "shiny" BOOL NOT NULL DEFAULT False; -ALTER TABLE "ballinstance" DROP COLUMN "special"; --- downgrade -- -ALTER TABLE "ballinstance" ADD "special" INT NOT NULL DEFAULT 0; -ALTER TABLE "ballinstance" DROP COLUMN "shiny"; diff --git a/migrations/models/6_20220924014717_update.sql b/migrations/models/6_20220924014717_update.sql deleted file mode 100644 index 3048b23a2..000000000 --- a/migrations/models/6_20220924014717_update.sql +++ /dev/null @@ -1,4 +0,0 @@ --- upgrade -- -ALTER TABLE "ball" ADD "short_name" VARCHAR(12); --- downgrade -- -ALTER TABLE "ball" DROP COLUMN "short_name"; diff --git a/migrations/models/7_20220926000044_update.sql b/migrations/models/7_20220926000044_update.sql deleted file mode 100644 index e439e92cc..000000000 --- a/migrations/models/7_20220926000044_update.sql +++ /dev/null @@ -1,7 +0,0 @@ --- upgrade -- -CREATE TABLE IF NOT EXISTS "blacklistedid" ( - "discord_id" BIGSERIAL NOT NULL PRIMARY KEY -); -COMMENT ON COLUMN "blacklistedid"."discord_id" IS 'Discord user ID'; --- downgrade -- -DROP TABLE IF EXISTS "blacklistedid"; diff --git a/migrations/models/8_20220926000601_update.sql b/migrations/models/8_20220926000601_update.sql deleted file mode 100644 index bc7abaaae..000000000 --- a/migrations/models/8_20220926000601_update.sql +++ /dev/null @@ -1,6 +0,0 @@ --- upgrade -- -ALTER TABLE "blacklistedid" RENAME COLUMN "discord_id" TO "id"; -ALTER TABLE "blacklistedid" ADD "discord_id" BIGINT NOT NULL UNIQUE; --- downgrade -- -ALTER TABLE "blacklistedid" RENAME COLUMN "id" TO "discord_id"; -ALTER TABLE "blacklistedid" DROP COLUMN "discord_id"; diff --git a/migrations/models/9_20221007231725_update.sql b/migrations/models/9_20221007231725_update.sql deleted file mode 100644 index 749916c22..000000000 --- a/migrations/models/9_20221007231725_update.sql +++ /dev/null @@ -1,20 +0,0 @@ --- upgrade -- -ALTER TABLE "ballinstance" ADD "special_id" INT; -CREATE TABLE IF NOT EXISTS "special" ( - "id" SERIAL NOT NULL PRIMARY KEY, - "name" VARCHAR(64) NOT NULL, - "catch_phrase" VARCHAR(128), - "start_date" TIMESTAMPTZ NOT NULL, - "end_date" TIMESTAMPTZ NOT NULL, - "rarity" DOUBLE PRECISION NOT NULL, - "democracy_card" VARCHAR(200) NOT NULL, - "dictatorship_card" VARCHAR(200) NOT NULL, - "union_card" VARCHAR(200) NOT NULL -); -COMMENT ON COLUMN "special"."catch_phrase" IS 'Sentence sent in bonus when someone catches a special card'; -COMMENT ON COLUMN "special"."rarity" IS 'Value between 0 and 1, chances of using this special background.';; -ALTER TABLE "ballinstance" ADD CONSTRAINT "fk_ballinst_special_25656e1a" FOREIGN KEY ("special_id") REFERENCES "special" ("id") ON DELETE SET NULL; --- downgrade -- -ALTER TABLE "ballinstance" DROP CONSTRAINT "fk_ballinst_special_25656e1a"; -ALTER TABLE "ballinstance" DROP COLUMN "special_id"; -DROP TABLE IF EXISTS "special"; diff --git a/poetry.lock b/poetry.lock index 0882b8712..3c405ab54 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,28 +1,5 @@ # This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand. -[[package]] -name = "aerich" -version = "0.6.3" -description = "A database migrations tool for Tortoise ORM." -optional = false -python-versions = ">=3.7,<4.0" -groups = ["main"] -files = [ - {file = "aerich-0.6.3-py3-none-any.whl", hash = "sha256:d45f98214ed54b8ec9be949df264c5b0b9e8b79d8f8ba9e68714675bc81a5574"}, - {file = "aerich-0.6.3.tar.gz", hash = "sha256:96ac087922048470687264125cb9dfeaade982219c78e6a9b91a0fb67eaa1cd1"}, -] - -[package.dependencies] -click = "*" -dictdiffer = "*" -pydantic = "*" -tomlkit = "*" -tortoise-orm = "*" - -[package.extras] -asyncmy = ["asyncmy"] -asyncpg = ["asyncpg"] - [[package]] name = "aiodns" version = "3.2.0" @@ -860,24 +837,6 @@ files = [ {file = "defusedxml-0.7.1.tar.gz", hash = "sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69"}, ] -[[package]] -name = "dictdiffer" -version = "0.9.0" -description = "Dictdiffer is a library that helps you to diff and patch dictionaries." -optional = false -python-versions = "*" -groups = ["main"] -files = [ - {file = "dictdiffer-0.9.0-py2.py3-none-any.whl", hash = "sha256:442bfc693cfcadaf46674575d2eba1c53b42f5e404218ca2c2ff549f2df56595"}, - {file = "dictdiffer-0.9.0.tar.gz", hash = "sha256:17bacf5fbfe613ccf1b6d512bd766e6b21fb798822a133aa86098b8ac9997578"}, -] - -[package.extras] -all = ["Sphinx (>=3)", "check-manifest (>=0.42)", "mock (>=1.3.0)", "numpy (>=1.13.0)", "numpy (>=1.15.0)", "numpy (>=1.18.0)", "numpy (>=1.20.0)", "pytest (==5.4.3)", "pytest (>=6)", "pytest-cov (>=2.10.1)", "pytest-isort (>=1.2.0)", "pytest-pycodestyle (>=2)", "pytest-pycodestyle (>=2.2.0)", "pytest-pydocstyle (>=2)", "pytest-pydocstyle (>=2.2.0)", "sphinx (>=3)", "sphinx-rtd-theme (>=0.2)", "tox (>=3.7.0)"] -docs = ["Sphinx (>=3)", "sphinx-rtd-theme (>=0.2)"] -numpy = ["numpy (>=1.13.0)", "numpy (>=1.15.0)", "numpy (>=1.18.0)", "numpy (>=1.20.0)"] -tests = ["check-manifest (>=0.42)", "mock (>=1.3.0)", "pytest (==5.4.3)", "pytest (>=6)", "pytest-cov (>=2.10.1)", "pytest-isort (>=1.2.0)", "pytest-pycodestyle (>=2)", "pytest-pycodestyle (>=2.2.0)", "pytest-pydocstyle (>=2)", "pytest-pydocstyle (>=2.2.0)", "sphinx (>=3)", "tox (>=3.7.0)"] - [[package]] name = "discord-py" version = "2.5.0" @@ -3323,4 +3282,4 @@ dev = ["black", "django-debug-toolbar", "flake8-pyproject", "isort", "pre-commit [metadata] lock-version = "2.1" python-versions = ">=3.13, <3.14" -content-hash = "f0f771be52a72fc631c2a3ebabe7378859f49f049f804a636d5928d502d435ea" +content-hash = "8fd50868b495b7927a76a3be59e994363d9d32f59b3bf7d203c7c66285227502" diff --git a/pyproject.toml b/pyproject.toml index f78df9dec..3093d0e09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,6 @@ dependencies = [ "rich==13.8.0", "python-dateutil==2.9.0", "Pillow==10.4.0", - "aerich==0.6.3", "pyyaml==6.0.2", "cachetools==5.5.0", ] @@ -75,11 +74,6 @@ pattern = '__version__ = "(?P\d+\.\d+\.\d+)"' requires = ["poetry-core>=2.0"] build-backend = "poetry.core.masonry.api" -[tool.aerich] -tortoise_orm = "ballsdex.__main__.TORTOISE_ORM" -location = "./migrations" -src_folder = "./ballsdex" - [tool.black] line-length = 99