Merge repeated if
statements into single if
This commit is contained in:
parent
fac00d45cc
commit
40c7ef7fd6
@ -100,11 +100,8 @@ class Command:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def history(self):
|
async def history(self):
|
||||||
ret = []
|
|
||||||
versions = Migrate.get_all_version_files()
|
versions = Migrate.get_all_version_files()
|
||||||
for version in versions:
|
return [version for version in versions]
|
||||||
ret.append(version)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
async def inspectdb(self, tables: List[str]):
|
async def inspectdb(self, tables: List[str]):
|
||||||
connection = get_app_connection(self.tortoise_config, self.app)
|
connection = get_app_connection(self.tortoise_config, self.app)
|
||||||
|
@ -184,7 +184,7 @@ class BaseDDL:
|
|||||||
"idx" if not unique else "uid", model, field_names
|
"idx" if not unique else "uid", model, field_names
|
||||||
),
|
),
|
||||||
table_name=model._meta.db_table,
|
table_name=model._meta.db_table,
|
||||||
column_names=", ".join([self.schema_generator.quote(f) for f in field_names]),
|
column_names=", ".join(self.schema_generator.quote(f) for f in field_names),
|
||||||
)
|
)
|
||||||
|
|
||||||
def drop_index(self, model: "Type[Model]", field_names: List[str], unique=False):
|
def drop_index(self, model: "Type[Model]", field_names: List[str], unique=False):
|
||||||
|
@ -96,11 +96,10 @@ def get_version_content_from_file(version_file: Union[str, Path]) -> Dict:
|
|||||||
second = len(content) - 1
|
second = len(content) - 1
|
||||||
upgrade_content = content[first + len(_UPGRADE) : second].strip() # noqa:E203
|
upgrade_content = content[first + len(_UPGRADE) : second].strip() # noqa:E203
|
||||||
downgrade_content = content[second + len(_DOWNGRADE) :].strip() # noqa:E203
|
downgrade_content = content[second + len(_DOWNGRADE) :].strip() # noqa:E203
|
||||||
ret = {
|
return {
|
||||||
"upgrade": list(filter(lambda x: x or False, upgrade_content.split(";\n"))),
|
"upgrade": list(filter(lambda x: x or False, upgrade_content.split(";\n"))),
|
||||||
"downgrade": list(filter(lambda x: x or False, downgrade_content.split(";\n"))),
|
"downgrade": list(filter(lambda x: x or False, downgrade_content.split(";\n"))),
|
||||||
}
|
}
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def write_version_file(version_file: Path, content: Dict):
|
def write_version_file(version_file: Path, content: Dict):
|
||||||
|
@ -72,18 +72,16 @@ def test_modify_column():
|
|||||||
ret1 = Migrate.ddl.modify_column(User, User._meta.fields_map.get("is_active").describe(False))
|
ret1 = Migrate.ddl.modify_column(User, User._meta.fields_map.get("is_active").describe(False))
|
||||||
if isinstance(Migrate.ddl, MysqlDDL):
|
if isinstance(Migrate.ddl, MysqlDDL):
|
||||||
assert ret0 == "ALTER TABLE `category` MODIFY COLUMN `name` VARCHAR(200)"
|
assert ret0 == "ALTER TABLE `category` MODIFY COLUMN `name` VARCHAR(200)"
|
||||||
|
assert (
|
||||||
|
ret1
|
||||||
|
== "ALTER TABLE `user` MODIFY COLUMN `is_active` BOOL NOT NULL COMMENT 'Is Active' DEFAULT 1"
|
||||||
|
)
|
||||||
elif isinstance(Migrate.ddl, PostgresDDL):
|
elif isinstance(Migrate.ddl, PostgresDDL):
|
||||||
assert (
|
assert (
|
||||||
ret0
|
ret0
|
||||||
== 'ALTER TABLE "category" ALTER COLUMN "name" TYPE VARCHAR(200) USING "name"::VARCHAR(200)'
|
== 'ALTER TABLE "category" ALTER COLUMN "name" TYPE VARCHAR(200) USING "name"::VARCHAR(200)'
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(Migrate.ddl, MysqlDDL):
|
|
||||||
assert (
|
|
||||||
ret1
|
|
||||||
== "ALTER TABLE `user` MODIFY COLUMN `is_active` BOOL NOT NULL COMMENT 'Is Active' DEFAULT 1"
|
|
||||||
)
|
|
||||||
elif isinstance(Migrate.ddl, PostgresDDL):
|
|
||||||
assert (
|
assert (
|
||||||
ret1 == 'ALTER TABLE "user" ALTER COLUMN "is_active" TYPE BOOL USING "is_active"::BOOL'
|
ret1 == 'ALTER TABLE "user" ALTER COLUMN "is_active" TYPE BOOL USING "is_active"::BOOL'
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user