mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
This moves `get_migration_status` to its own file in zerver/lib/migration_status.py. This is a prep work to refactor the check migration function of import/export later on. Some of the imports are moved into `get_migration_status` because we're planning to share this file with `check-database-compatibility` which is also called when one does `production-upgrade`, so we'd want to avoid doing file-wide import on certain types of modules because it will fail under that scenario. In `test_fixtures.py`, `get_migration_status` is imported within `Database.what_to_do_with_migrations` so that it is called after `cov.start()` in `test-backend`. This is to avoid wierd interaction with coverage, see more details in #33063. Fixes #33063.
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import argparse
|
|
import os
|
|
from typing import Any
|
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
|
from typing_extensions import override
|
|
|
|
from scripts.lib.zulip_tools import get_dev_uuid_var_path
|
|
from zerver.lib.management import ZulipBaseCommand
|
|
from zerver.lib.migration_status import get_migration_status
|
|
|
|
|
|
class Command(ZulipBaseCommand):
|
|
help = "Get status of migrations."
|
|
|
|
@override
|
|
def add_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
parser.add_argument(
|
|
"app_label", nargs="?", help="App label of an application to synchronize the state."
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--database",
|
|
default=DEFAULT_DB_ALIAS,
|
|
help='Nominates a database to synchronize. Defaults to the "default" database.',
|
|
)
|
|
|
|
parser.add_argument("--output", help="Path to store the status to (default to stdout).")
|
|
|
|
@override
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
|
result = get_migration_status(**options)
|
|
if options["output"] is not None:
|
|
uuid_var_path = get_dev_uuid_var_path()
|
|
path = os.path.join(uuid_var_path, options["output"])
|
|
with open(path, "w") as f:
|
|
f.write(result)
|
|
else:
|
|
self.stdout.write(result)
|