mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-06 13:15:35 -06:00
nit, format, varname nit
This commit is contained in:
@@ -36,11 +36,7 @@ class ExtendedRouter(Router):
|
|||||||
try:
|
try:
|
||||||
modules = models
|
modules = models
|
||||||
if isinstance(module, bool):
|
if isinstance(module, bool):
|
||||||
modules = [
|
modules = [m for _, m, ispkg in pkgutil.iter_modules([f"{router.CURDIR}"]) if ispkg]
|
||||||
m
|
|
||||||
for _, m, ispkg in pkgutil.iter_modules([f"{router.CURDIR}"])
|
|
||||||
if ispkg
|
|
||||||
]
|
|
||||||
models = [m for module in modules for m in router.load_models(module)]
|
models = [m for module in modules for m in router.load_models(module)]
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -48,7 +44,7 @@ class ExtendedRouter(Router):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if self.ignore:
|
if self.ignore:
|
||||||
models = [m for m in models if m._meta.name not in self.ignore] # type: ignore[]
|
models = [m for m in models if m._meta.name not in self.ignore] # type: ignore
|
||||||
|
|
||||||
for migration in self.diff:
|
for migration in self.diff:
|
||||||
self.run_one(migration, self.migrator, fake=True)
|
self.run_one(migration, self.migrator, fake=True)
|
||||||
@@ -91,9 +87,7 @@ def main(*args: str) -> None:
|
|||||||
diff = router.diff
|
diff = router.diff
|
||||||
|
|
||||||
if len(diff) == 0:
|
if len(diff) == 0:
|
||||||
logger.info(
|
logger.info("No migrations found, no pending migrations to apply. Creating initial migration.")
|
||||||
"No migrations found, no pending migrations to apply. Creating initial migration."
|
|
||||||
)
|
|
||||||
|
|
||||||
migration = router.create("initial", auto=target_models)
|
migration = router.create("initial", auto=target_models)
|
||||||
if not migration:
|
if not migration:
|
||||||
@@ -107,13 +101,9 @@ def main(*args: str) -> None:
|
|||||||
logger.info(
|
logger.info(
|
||||||
"Note: Selecting a migration will apply all migrations up to and including the selected migration."
|
"Note: Selecting a migration will apply all migrations up to and including the selected migration."
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info("e.g. Applying 004 while only 001 is applied would apply 002, 003, and 004.")
|
||||||
"e.g. Applying 004 while only 001 is applied would apply 002, 003, and 004."
|
|
||||||
)
|
|
||||||
|
|
||||||
choice = questionary.select(
|
choice = questionary.select("Select highest migration to apply:", choices=diff).ask()
|
||||||
"Select highest migration to apply:", choices=diff
|
|
||||||
).ask()
|
|
||||||
if choice is None:
|
if choice is None:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"For safety reasons, you won't be able to create migrations without applying the pending ones."
|
"For safety reasons, you won't be able to create migrations without applying the pending ones."
|
||||||
@@ -163,14 +153,10 @@ def main(*args: str) -> None:
|
|||||||
logger.info(f"Migration created: {migration}")
|
logger.info(f"Migration created: {migration}")
|
||||||
|
|
||||||
if len(router.diff) == 1:
|
if len(router.diff) == 1:
|
||||||
if questionary.confirm(
|
if questionary.confirm("Do you want to apply this migration immediately?").ask():
|
||||||
"Do you want to apply this migration immediately?"
|
|
||||||
).ask():
|
|
||||||
router.run(migration)
|
router.run(migration)
|
||||||
logger.info("Done.")
|
logger.info("Done.")
|
||||||
logger.warning(
|
logger.warning("!!! Commit and push this migration file immediately!")
|
||||||
"!!! Commit and push this migration file immediately!"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Changes anticipated with show() but no migration created with create(), model definition may have reverted."
|
"Changes anticipated with show() but no migration created with create(), model definition may have reverted."
|
||||||
@@ -178,10 +164,10 @@ def main(*args: str) -> None:
|
|||||||
else:
|
else:
|
||||||
logger.info("No database changes detected.")
|
logger.info("No database changes detected.")
|
||||||
|
|
||||||
migration_limit: int = 15
|
migration_squash_threshold: int = 15
|
||||||
if len(current) > migration_limit:
|
if len(current) > migration_squash_threshold:
|
||||||
if questionary.confirm(
|
if questionary.confirm(
|
||||||
f"There are more than {migration_limit} migrations applied. Do you want to merge them?",
|
f"There are more than {migration_squash_threshold} migrations applied. Do you want to merge them?",
|
||||||
default=False,
|
default=False,
|
||||||
).ask():
|
).ask():
|
||||||
logger.info("Merging migrations...")
|
logger.info("Merging migrations...")
|
||||||
|
|||||||
Reference in New Issue
Block a user