-
-
Notifications
You must be signed in to change notification settings - Fork 112
fix: error when there is __init__.py in the migration folder #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Aerich changed from |
baseplate-admin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
私のアドバイスを聞いてくれてありがとう
waketzheng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key=lambda x: int(x.split("_")[0]) show that if there is any file whose name does not startswith a number will raise a ValueError.
So this function can be refactor to be:
def get_all_version_files(cls) -> List[str]:
pattern = re.compile(r"(\d+)_")
files = [i.name for i in cls.migrate_location.glob("*.py") if pattern.match(i.name)]
return sorted(files, key=lambda x: int(pattern.search(x).group(1)))|
@waketzheng |
|
@LanceMoe This PR is useful. It allow user to add custom file like Code can be as simple as: def get_all_version_files(cls) -> List[str]:
files = [p.name for p in cls.migrate_location.glob("*.py") if p.name[0].isdigit()]
return sorted(files, key=lambda x: int(x.split("_")[0]))Note: |
|
@waketzheng If |
|
@waketzheng Finally, I chose to add two closures in this function for the following reasons:
Please review again, thank you. |
|
Looks nice, just change to this: @classmethod
def get_all_version_files(cls) -> List[str]:
- def get_file_version(file_name: str):
+ def get_file_version(file_name: str) -> str:
return file_name.split("_")[0]
- def is_version_file(file_name: str):
+ def is_version_file(file_name: str) -> bool:
if not file_name.endswith("py"):
return False
- if file_name.find("_") <= 0:
+ if "_" not in file_name:
return False
return get_file_version(file_name).isdigit() |
|
@waketzheng |
No description provided.