Fix postgre alter null. (#142)
This commit is contained in:
parent
3f52ac348b
commit
fa85e05d1d
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 0.5
|
## 0.5
|
||||||
|
|
||||||
|
### 0.5.3
|
||||||
|
|
||||||
|
- Fix postgre alter null. (#142)
|
||||||
|
|
||||||
### 0.5.2
|
### 0.5.2
|
||||||
|
|
||||||
- Fix rename field on the field add. (#134)
|
- Fix rename field on the field add. (#134)
|
||||||
|
@ -1 +1 @@
|
|||||||
__version__ = "0.5.2"
|
__version__ = "0.5.3"
|
||||||
|
@ -227,10 +227,10 @@ class BaseDDL:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def alter_column_null(self, model: "Type[Model]", field_describe: dict):
|
def alter_column_null(self, model: "Type[Model]", field_describe: dict):
|
||||||
raise NotImplementedError
|
return self.modify_column(model, field_describe)
|
||||||
|
|
||||||
def set_comment(self, model: "Type[Model]", field_describe: dict):
|
def set_comment(self, model: "Type[Model]", field_describe: dict):
|
||||||
raise NotImplementedError
|
return self.modify_column(model, field_describe)
|
||||||
|
|
||||||
def rename_table(self, model: "Type[Model]", old_table_name: str, new_table_name: str):
|
def rename_table(self, model: "Type[Model]", old_table_name: str, new_table_name: str):
|
||||||
db_table = model._meta.db_table
|
db_table = model._meta.db_table
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
from typing import Type
|
|
||||||
|
|
||||||
from tortoise import Model
|
|
||||||
from tortoise.backends.mysql.schema_generator import MySQLSchemaGenerator
|
from tortoise.backends.mysql.schema_generator import MySQLSchemaGenerator
|
||||||
|
|
||||||
from aerich.ddl import BaseDDL
|
from aerich.ddl import BaseDDL
|
||||||
from aerich.exceptions import NotSupportError
|
|
||||||
|
|
||||||
|
|
||||||
class MysqlDDL(BaseDDL):
|
class MysqlDDL(BaseDDL):
|
||||||
@ -29,9 +25,3 @@ class MysqlDDL(BaseDDL):
|
|||||||
_M2M_TABLE_TEMPLATE = "CREATE TABLE `{table_name}` (`{backward_key}` {backward_type} NOT NULL REFERENCES `{backward_table}` (`{backward_field}`) ON DELETE CASCADE,`{forward_key}` {forward_type} NOT NULL REFERENCES `{forward_table}` (`{forward_field}`) ON DELETE CASCADE){extra}{comment}"
|
_M2M_TABLE_TEMPLATE = "CREATE TABLE `{table_name}` (`{backward_key}` {backward_type} NOT NULL REFERENCES `{backward_table}` (`{backward_field}`) ON DELETE CASCADE,`{forward_key}` {forward_type} NOT NULL REFERENCES `{forward_table}` (`{forward_field}`) ON DELETE CASCADE){extra}{comment}"
|
||||||
_MODIFY_COLUMN_TEMPLATE = "ALTER TABLE `{table_name}` MODIFY COLUMN {column}"
|
_MODIFY_COLUMN_TEMPLATE = "ALTER TABLE `{table_name}` MODIFY COLUMN {column}"
|
||||||
_RENAME_TABLE_TEMPLATE = "ALTER TABLE `{old_table_name}` RENAME TO `{new_table_name}`"
|
_RENAME_TABLE_TEMPLATE = "ALTER TABLE `{old_table_name}` RENAME TO `{new_table_name}`"
|
||||||
|
|
||||||
def alter_column_null(self, model: "Type[Model]", field_describe: dict):
|
|
||||||
raise NotSupportError("Alter column null is unsupported in MySQL.")
|
|
||||||
|
|
||||||
def set_comment(self, model: "Type[Model]", field_describe: dict):
|
|
||||||
raise NotSupportError("Alter column comment is unsupported in MySQL.")
|
|
||||||
|
@ -399,6 +399,9 @@ class Migrate:
|
|||||||
elif option == "unique":
|
elif option == "unique":
|
||||||
# because indexed include it
|
# because indexed include it
|
||||||
pass
|
pass
|
||||||
|
elif option == "nullable":
|
||||||
|
# change nullable
|
||||||
|
cls._add_operator(cls._alter_null(model, new_data_field), upgrade)
|
||||||
else:
|
else:
|
||||||
# modify column
|
# modify column
|
||||||
cls._add_operator(
|
cls._add_operator(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "aerich"
|
name = "aerich"
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
description = "A database migrations tool for Tortoise ORM."
|
description = "A database migrations tool for Tortoise ORM."
|
||||||
authors = ["long2ice <long2ice@gmail.com>"]
|
authors = ["long2ice <long2ice@gmail.com>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
@ -832,7 +832,7 @@ def test_migrate(mocker: MockerFixture):
|
|||||||
elif isinstance(Migrate.ddl, PostgresDDL):
|
elif isinstance(Migrate.ddl, PostgresDDL):
|
||||||
assert sorted(Migrate.upgrade_operators) == sorted(
|
assert sorted(Migrate.upgrade_operators) == sorted(
|
||||||
[
|
[
|
||||||
'ALTER TABLE "category" ALTER COLUMN "name" TYPE VARCHAR(200) USING "name"::VARCHAR(200)',
|
'ALTER TABLE "category" ALTER COLUMN "name" DROP NOT NULL',
|
||||||
'ALTER TABLE "category" ALTER COLUMN "slug" TYPE VARCHAR(100) USING "slug"::VARCHAR(100)',
|
'ALTER TABLE "category" ALTER COLUMN "slug" TYPE VARCHAR(100) USING "slug"::VARCHAR(100)',
|
||||||
'ALTER TABLE "config" ADD "user_id" INT NOT NULL',
|
'ALTER TABLE "config" ADD "user_id" INT NOT NULL',
|
||||||
'ALTER TABLE "config" ADD CONSTRAINT "fk_config_user_17daa970" FOREIGN KEY ("user_id") REFERENCES "user" ("id") ON DELETE CASCADE',
|
'ALTER TABLE "config" ADD CONSTRAINT "fk_config_user_17daa970" FOREIGN KEY ("user_id") REFERENCES "user" ("id") ON DELETE CASCADE',
|
||||||
@ -855,7 +855,7 @@ def test_migrate(mocker: MockerFixture):
|
|||||||
)
|
)
|
||||||
assert sorted(Migrate.downgrade_operators) == sorted(
|
assert sorted(Migrate.downgrade_operators) == sorted(
|
||||||
[
|
[
|
||||||
'ALTER TABLE "category" ALTER COLUMN "name" TYPE VARCHAR(200) USING "name"::VARCHAR(200)',
|
'ALTER TABLE "category" ALTER COLUMN "name" SET NOT NULL',
|
||||||
'ALTER TABLE "category" ALTER COLUMN "slug" TYPE VARCHAR(200) USING "slug"::VARCHAR(200)',
|
'ALTER TABLE "category" ALTER COLUMN "slug" TYPE VARCHAR(200) USING "slug"::VARCHAR(200)',
|
||||||
'ALTER TABLE "user" ALTER COLUMN "password" TYPE VARCHAR(200) USING "password"::VARCHAR(200)',
|
'ALTER TABLE "user" ALTER COLUMN "password" TYPE VARCHAR(200) USING "password"::VARCHAR(200)',
|
||||||
'ALTER TABLE "config" DROP COLUMN "user_id"',
|
'ALTER TABLE "config" DROP COLUMN "user_id"',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user