From bd8eb94a6e568bbd5b5b269ac1396c5d620e65de Mon Sep 17 00:00:00 2001 From: Patrick Schneeweis Date: Thu, 23 Jul 2020 21:21:58 -0400 Subject: [PATCH 1/3] Increase max length of version column --- aerich/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aerich/models.py b/aerich/models.py index 27e9474..8589d6d 100644 --- a/aerich/models.py +++ b/aerich/models.py @@ -1,8 +1,10 @@ from tortoise import Model, fields +MAX_VERSION_LENGTH = 255 + class Aerich(Model): - version = fields.CharField(max_length=50) + version = fields.CharField(max_length=MAX_VERSION_LENGTH) app = fields.CharField(max_length=20) class Meta: From f93ab6bbffe0ac7324dddd3c733c6ada54710e7a Mon Sep 17 00:00:00 2001 From: Patrick Schneeweis Date: Thu, 23 Jul 2020 21:22:30 -0400 Subject: [PATCH 2/3] Raise name length error when creating migration. Currently this error gets raised when trying to apply the migration, but it seems better to learn about it when trying to create the migration. --- aerich/migrate.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aerich/migrate.py b/aerich/migrate.py index 3f7f119..c5267f8 100644 --- a/aerich/migrate.py +++ b/aerich/migrate.py @@ -17,7 +17,7 @@ from tortoise import ( from tortoise.fields import Field from aerich.ddl import BaseDDL -from aerich.models import Aerich +from aerich.models import Aerich, MAX_VERSION_LENGTH from aerich.utils import get_app_connection @@ -89,7 +89,10 @@ class Migrate: last_version_num = await cls._get_last_version_num() if last_version_num is None: return f"0_{now}_init.json" - return f"{last_version_num + 1}_{now}_{name}.json" + version = f"{last_version_num + 1}_{now}_{name}.json" + if len(version) > MAX_VERSION_LENGTH: + raise ValueError(f"Version name exceeds maximum length ({MAX_VERSION_LENGTH})") + return version @classmethod async def _generate_diff_sql(cls, name): From 119b15d59713d7e80dc9d779215776df5dd8d417 Mon Sep 17 00:00:00 2001 From: Patrick Schneeweis Date: Thu, 23 Jul 2020 21:29:26 -0400 Subject: [PATCH 3/3] style fixes --- aerich/migrate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aerich/migrate.py b/aerich/migrate.py index c5267f8..c11921d 100644 --- a/aerich/migrate.py +++ b/aerich/migrate.py @@ -17,7 +17,7 @@ from tortoise import ( from tortoise.fields import Field from aerich.ddl import BaseDDL -from aerich.models import Aerich, MAX_VERSION_LENGTH +from aerich.models import MAX_VERSION_LENGTH, Aerich from aerich.utils import get_app_connection