add sqlite not support error
This commit is contained in:
parent
00dd04f97d
commit
d18a6b5be0
@ -1,8 +1,19 @@
|
||||
from typing import Type
|
||||
|
||||
from tortoise import Model
|
||||
from tortoise.backends.sqlite.schema_generator import SqliteSchemaGenerator
|
||||
from tortoise.fields import Field
|
||||
|
||||
from aerich.ddl import BaseDDL
|
||||
from aerich.exceptions import NotSupportError
|
||||
|
||||
|
||||
class SqliteDDL(BaseDDL):
|
||||
schema_generator_cls = SqliteSchemaGenerator
|
||||
DIALECT = SqliteSchemaGenerator.DIALECT
|
||||
|
||||
def drop_column(self, model: "Type[Model]", column_name: str):
|
||||
raise NotSupportError("Drop column is not support in SQLite.")
|
||||
|
||||
def modify_column(self, model: "Type[Model]", field_object: Field):
|
||||
raise NotSupportError("Modify column is not support in SQLite.")
|
||||
|
@ -1,6 +1,4 @@
|
||||
class ConfigurationError(Exception):
|
||||
class NotSupportError(Exception):
|
||||
"""
|
||||
config error
|
||||
raise when features not support
|
||||
"""
|
||||
|
||||
pass
|
||||
|
@ -1,6 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from aerich.ddl.mysql import MysqlDDL
|
||||
from aerich.ddl.postgres import PostgresDDL
|
||||
from aerich.ddl.sqlite import SqliteDDL
|
||||
from aerich.exceptions import NotSupportError
|
||||
from aerich.migrate import Migrate
|
||||
from tests.models import Category, User
|
||||
|
||||
@ -63,27 +66,26 @@ def test_add_column():
|
||||
|
||||
|
||||
def test_modify_column():
|
||||
ret = Migrate.ddl.modify_column(Category, Category._meta.fields_map.get("name"))
|
||||
if isinstance(Migrate.ddl, MysqlDDL):
|
||||
assert ret == "ALTER TABLE `category` MODIFY COLUMN `name` VARCHAR(200) NOT NULL"
|
||||
elif isinstance(Migrate.ddl, PostgresDDL):
|
||||
assert ret == 'ALTER TABLE "category" ALTER COLUMN "name" TYPE VARCHAR(200)'
|
||||
else:
|
||||
assert ret == 'ALTER TABLE "category" MODIFY COLUMN "name" VARCHAR(200) NOT NULL'
|
||||
if isinstance(Migrate.ddl, SqliteDDL):
|
||||
with pytest.raises(NotSupportError):
|
||||
ret0 = Migrate.ddl.modify_column(Category, Category._meta.fields_map.get("name"))
|
||||
ret1 = Migrate.ddl.modify_column(User, User._meta.fields_map.get("is_active"))
|
||||
|
||||
else:
|
||||
ret0 = Migrate.ddl.modify_column(Category, Category._meta.fields_map.get("name"))
|
||||
ret1 = Migrate.ddl.modify_column(User, User._meta.fields_map.get("is_active"))
|
||||
if isinstance(Migrate.ddl, MysqlDDL):
|
||||
assert ret0 == "ALTER TABLE `category` MODIFY COLUMN `name` VARCHAR(200) NOT NULL"
|
||||
elif isinstance(Migrate.ddl, PostgresDDL):
|
||||
assert ret0 == 'ALTER TABLE "category" ALTER COLUMN "name" TYPE VARCHAR(200)'
|
||||
|
||||
ret = Migrate.ddl.modify_column(User, User._meta.fields_map.get("is_active"))
|
||||
if isinstance(Migrate.ddl, MysqlDDL):
|
||||
assert (
|
||||
ret
|
||||
ret1
|
||||
== "ALTER TABLE `user` MODIFY COLUMN `is_active` BOOL NOT NULL COMMENT 'Is Active' DEFAULT 1"
|
||||
)
|
||||
elif isinstance(Migrate.ddl, PostgresDDL):
|
||||
assert ret == 'ALTER TABLE "user" ALTER COLUMN "is_active" TYPE BOOL'
|
||||
else:
|
||||
assert (
|
||||
ret
|
||||
== 'ALTER TABLE "user" MODIFY COLUMN "is_active" INT NOT NULL DEFAULT 1 /* Is Active */'
|
||||
)
|
||||
assert ret1 == 'ALTER TABLE "user" ALTER COLUMN "is_active" TYPE BOOL'
|
||||
|
||||
|
||||
def test_alter_column_default():
|
||||
@ -131,10 +133,12 @@ def test_set_comment():
|
||||
|
||||
|
||||
def test_drop_column():
|
||||
ret = Migrate.ddl.drop_column(Category, "name")
|
||||
if isinstance(Migrate.ddl, SqliteDDL):
|
||||
with pytest.raises(NotSupportError):
|
||||
ret = Migrate.ddl.drop_column(Category, "name")
|
||||
if isinstance(Migrate.ddl, MysqlDDL):
|
||||
assert ret == "ALTER TABLE `category` DROP COLUMN `name`"
|
||||
else:
|
||||
elif isinstance(Migrate.ddl, PostgresDDL):
|
||||
assert ret == 'ALTER TABLE "category" DROP COLUMN "name"'
|
||||
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
import pytest
|
||||
from tortoise import Tortoise
|
||||
|
||||
from aerich.ddl.mysql import MysqlDDL
|
||||
from aerich.ddl.postgres import PostgresDDL
|
||||
from aerich.ddl.sqlite import SqliteDDL
|
||||
from aerich.exceptions import NotSupportError
|
||||
from aerich.migrate import Migrate
|
||||
|
||||
|
||||
@ -10,7 +13,9 @@ def test_migrate():
|
||||
models = apps.get("models")
|
||||
diff_models = apps.get("diff_models")
|
||||
Migrate.diff_models(diff_models, models)
|
||||
Migrate.diff_models(models, diff_models, False)
|
||||
if isinstance(Migrate.ddl, SqliteDDL):
|
||||
with pytest.raises(NotSupportError):
|
||||
Migrate.diff_models(models, diff_models, False)
|
||||
if isinstance(Migrate.ddl, MysqlDDL):
|
||||
assert Migrate.upgrade_operators == [
|
||||
"ALTER TABLE `category` ADD `name` VARCHAR(200) NOT NULL",
|
||||
@ -29,15 +34,12 @@ def test_migrate():
|
||||
'ALTER TABLE "category" DROP COLUMN "name"',
|
||||
'ALTER TABLE "user" DROP CONSTRAINT "uid_user_usernam_9987ab"',
|
||||
]
|
||||
else:
|
||||
elif isinstance(Migrate.ddl, SqliteDDL):
|
||||
assert Migrate.upgrade_operators == [
|
||||
'ALTER TABLE "category" ADD "name" VARCHAR(200) NOT NULL',
|
||||
'ALTER TABLE "user" ADD UNIQUE INDEX "uid_user_usernam_9987ab" ("username")',
|
||||
]
|
||||
assert Migrate.downgrade_operators == [
|
||||
'ALTER TABLE "category" DROP COLUMN "name"',
|
||||
'ALTER TABLE "user" DROP INDEX "uid_user_usernam_9987ab"',
|
||||
]
|
||||
assert Migrate.downgrade_operators == []
|
||||
|
||||
|
||||
def test_sort_all_version_files(mocker):
|
||||
|
Loading…
x
Reference in New Issue
Block a user