fix: error when there is __init__.py in the migration folder (#272)
* fix: error when there is __init__.py in the migration folder * fix: check __init__.py in the migration folder * refactor * refactor & add test * refactor * Update changelog --------- Co-authored-by: Waket Zheng <waketzheng@gmail.com>
This commit is contained in:
@@ -54,10 +54,18 @@ class Migrate:
|
||||
|
||||
@classmethod
|
||||
def get_all_version_files(cls) -> List[str]:
|
||||
return sorted(
|
||||
filter(lambda x: x.endswith("py"), os.listdir(cls.migrate_location)),
|
||||
key=lambda x: int(x.split("_")[0]),
|
||||
)
|
||||
def get_file_version(file_name: str) -> str:
|
||||
return file_name.split("_")[0]
|
||||
|
||||
def is_version_file(file_name: str) -> bool:
|
||||
if not file_name.endswith("py"):
|
||||
return False
|
||||
if "_" not in file_name:
|
||||
return False
|
||||
return get_file_version(file_name).isdigit()
|
||||
|
||||
files = filter(is_version_file, os.listdir(cls.migrate_location))
|
||||
return sorted(files, key=lambda x: int(get_file_version(x)))
|
||||
|
||||
@classmethod
|
||||
def _get_model(cls, model: str) -> Type[Model]:
|
||||
|
||||
Reference in New Issue
Block a user