Skip to content

Commit 82f312d

Browse files
authored
MPT-18141: rename --fake option to --manual (#43)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> Closes [MPT-18141](https://softwareone.atlassian.net/browse/MPT-18141) - Rename CLI option `--fake` to `--manual` in the migrate command - Rename `FakeCommand` class to `ManualCommand` throughout the codebase - Update migration status enum member from `FAKE_APPLY` to `MANUAL_APPLIED` with value changed from `"faked"` to `"manual"` - Rename `Migration.fake()` method to `Migration.manual()` and update semantics to set `applied_at` timestamp while clearing `started_at` - Update command factory to route manual migrations through `ManualCommand` - Update all error messages and status labels from "fake mode" to "manual mode" - Update documentation to reflect manual mode terminology - Rename and update test cases to use `--manual` flag and verify manual mode behavior <!-- end of auto-generated comment: release notes by coderabbit.ai --> [MPT-18141]: https://softwareone.atlassian.net/browse/MPT-18141?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2 parents 906a22d + 34c7848 commit 82f312d

File tree

11 files changed

+41
-37
lines changed

11 files changed

+41
-37
lines changed

docs/PROJECT_DESCRIPTION.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ This command creates:
121121
mpt-service-cli migrate --new-schema "migration_name"
122122
```
123123
124-
A new file is created in `migrations/` with a timestamped prefix (e.g., `20260113180013_migration_name.py`) and a prefilled `Command` class.
124+
A new file is created in `migrations/` with a timestamped prefix (e.g., `20260113180013_migration_name.py`) and a prefilled `Migrate` class.
125125
126126
order_id: timestamp prefix (e.g., `20260113180013`)
127127
migration_id: user-provided name (e.g., `migration_name`)
@@ -234,14 +234,14 @@ If a migration fails during execution:
234234
* The started_at timestamp is recorded
235235
* The applied_at field remains null
236236
* The error is logged
237-
* Later runs will retry the failed migration as applied_at is null, unless `--fake` is used to mark it as applied
237+
* Later runs will retry the failed migration as applied_at is null, unless `--manual` is used to mark it as applied
238238
239239
240-
### Fake Mode
240+
### Manual Mode
241241
To mark a migration as applied without running it:
242242
243243
```bash
244-
mpt-service-cli migrate --fake MIGRATION_ID
244+
mpt-service-cli migrate --manual MIGRATION_ID
245245
```
246246
247247
Where `MIGRATION_ID` is the filename without `order_id` and `.py` (e.g., `test1`).
@@ -273,7 +273,7 @@ The status column is derived from the persisted timestamps:
273273
|-------------|---------------------------------------------------------------|
274274
| running | `started_at` is set and `applied_at` is empty |
275275
| failed | `started_at` and `applied_at` are empty for an existing state |
276-
| faked | `started_at` is empty and `applied_at` is set |
276+
| manual | `started_at` is empty and `applied_at` is set |
277277
| applied | Both `started_at` and `applied_at` are set |
278278
| not applied | No state entry exists for the migration file |
279279
@@ -321,7 +321,7 @@ Run `mpt-service-cli --help` to see all available commands and params:
321321
**Migration fails to run:**
322322
- Review the error message in the terminal output
323323
- Check your `Migration.run()` implementation for syntax errors
324-
- Fix the issue and re-run the migration or use `--fake` to mark it as applied
324+
- Fix the issue and re-run the migration or use `--manual` to mark it as applied
325325
326326
**NOTE:** There is currently no automatic rollback mechanism. If a migration partially modifies data before failing, you must manually revert those changes or create a new migration to fix the state.
327327

make/common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ format: ## Format code
2020
$(RUN) bash -c "ruff check --select I --fix . && ruff format ."
2121

2222
run: ## Run service
23-
$(DC) up
23+
$(RUN_IT) bash -c "mpt-service-cli migrate --help && exec bash"
2424

2525
shell: ## Open Django shell
2626
$(RUN_IT) bash -c "swoext shell"

mpt_tool/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def migrate( # noqa: WPS211
2323
] = False,
2424
data: Annotated[bool, typer.Option("--data", help="Run data migrations.")] = False, # noqa: FBT002
2525
schema: Annotated[bool, typer.Option("--schema", help="Run schema migrations.")] = False, # noqa: FBT002
26-
fake: Annotated[
26+
manual: Annotated[
2727
str | None,
2828
typer.Option(
29-
"--fake",
29+
"--manual",
3030
help="Mark the migration provided as applied without running it",
3131
metavar="MIGRATION_ID",
3232
),

mpt_tool/commands/factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from mpt_tool.commands.check import CheckCommand
77
from mpt_tool.commands.data import DataCommand
88
from mpt_tool.commands.errors import CommandNotFoundError
9-
from mpt_tool.commands.fake import FakeCommand
109
from mpt_tool.commands.init import InitCommand
1110
from mpt_tool.commands.list import ListCommand
11+
from mpt_tool.commands.manual import ManualCommand
1212
from mpt_tool.commands.new_data import NewDataCommand
1313
from mpt_tool.commands.new_schema import NewSchemaCommand
1414
from mpt_tool.commands.schema import SchemaCommand
@@ -39,8 +39,8 @@ def get_instance(cls, param_data: dict[str, bool | str | None]) -> BaseCommand:
3939
return DataCommand()
4040
case {"schema": True}:
4141
return SchemaCommand()
42-
case {"fake": fake_value} if fake_value is not None:
43-
return FakeCommand(migration_id=cast(str, fake_value))
42+
case {"manual": manual_value} if manual_value is not None:
43+
return ManualCommand(migration_id=cast(str, manual_value))
4444
case {"new_schema": new_schema_value} if new_schema_value is not None:
4545
return NewSchemaCommand(migration_id=cast(str, new_schema_value))
4646
case {"new_data": new_data_value} if new_data_value is not None:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mpt_tool.use_cases import ApplyMigrationUseCase
55

66

7-
class FakeCommand(BaseCommand):
7+
class ManualCommand(BaseCommand):
88
"""Applies a migration without running it."""
99

1010
def __init__(self, migration_id: str):
@@ -14,7 +14,7 @@ def __init__(self, migration_id: str):
1414
@override
1515
@property
1616
def start_message(self) -> str:
17-
return f"Running migration {self.migration_id} in fake mode."
17+
return f"Running migration {self.migration_id} in manual mode."
1818

1919
@override
2020
@property

mpt_tool/enums.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MigrationStatusEnum(StrEnum):
1010

1111
RUNNING = "running"
1212
FAILED = "failed"
13-
FAKE_APPLY = "faked"
13+
MANUAL_APPLIED = "manual"
1414
APPLIED = "applied"
1515
NOT_APPLIED = "not applied"
1616

@@ -24,7 +24,7 @@ def from_state(cls, migration_state: "Migration | None") -> Self:
2424
if migration_state.started_at and not migration_state.applied_at:
2525
return cls.RUNNING
2626
if migration_state.started_at is None and migration_state.applied_at:
27-
return cls.FAKE_APPLY
27+
return cls.MANUAL_APPLIED
2828

2929
return cls.FAILED
3030

mpt_tool/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def failed(self) -> None:
5151
self.started_at = None
5252
self.applied_at = None
5353

54-
def fake(self) -> None:
55-
"""Mark the migration as fake."""
54+
def manual(self) -> None:
55+
"""Mark the migration as manual."""
5656
self.started_at = None
5757
self.applied_at = dt.datetime.now(tz=dt.UTC)
5858

mpt_tool/use_cases/apply_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ def execute(self, migration_id: str) -> None:
3838
if state.applied_at is not None:
3939
raise ApplyMigrationError(f"Migration {migration_id} already applied")
4040

41-
state.fake()
41+
state.manual()
4242
self.state_manager.save_state(state)

tests/cli/test_cli.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,21 @@ def test_migrate_data_migration_folder_not_found(runner):
4545
assert "Migration folder not found:" in result.output
4646

4747

48-
def test_migrate_fake_folder_not_found(runner):
49-
result = runner.invoke(app, ["migrate", "--fake", "not_existing_migration"])
48+
def test_migrate_manual_folder_not_found(runner):
49+
result = runner.invoke(app, ["migrate", "--manual", "not_existing_migration"])
5050

5151
assert result.exit_code == 1, result.output
52-
assert "Error running fake command: Migration folder not found: migrations" in result.output
52+
assert "Error running manual command: Migration folder not found: migrations" in result.output
5353

5454

5555
@pytest.mark.usefixtures("data_migration_file")
56-
def test_migrate_fake_migration_not_found(runner):
57-
result = runner.invoke(app, ["migrate", "--fake", "not_existing_migration"])
56+
def test_migrate_manual_migration_not_found(runner):
57+
result = runner.invoke(app, ["migrate", "--manual", "not_existing_migration"])
5858

5959
assert result.exit_code == 1, result.output
60-
assert "Error running fake command: Migration not_existing_migration not found" in result.output
60+
assert (
61+
"Error running manual command: Migration not_existing_migration not found" in result.output
62+
)
6163

6264

6365
@freeze_time("2025-04-06 12:21:34")

tests/cli/test_cli_airtable_storage.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ def test_migrate_data_run_script_fail(mock_airtable, runner, log):
9393

9494
@freeze_time("2025-04-06 10:11:24")
9595
@pytest.mark.usefixtures("data_migration_file")
96-
def test_migrate_fake(mock_airtable, runner):
97-
result = runner.invoke(app, ["migrate", "--fake", "fake_data_file_name"])
96+
def test_migrate_manual(mock_airtable, runner):
97+
result = runner.invoke(app, ["migrate", "--manual", "fake_data_file_name"])
9898

9999
assert result.exit_code == 0, result.output
100-
assert "Running migration fake_data_file_name in fake mode." in result.output
100+
assert "Running migration fake_data_file_name in manual mode." in result.output
101101
assert "Migration fake_data_file_name applied successfully." in result.output
102102
records = mock_airtable.records.get(("fake_base_id", "fake_table_name"))
103103
record_key = next(iter(records.keys()))
@@ -111,12 +111,13 @@ def test_migrate_fake(mock_airtable, runner):
111111

112112

113113
@pytest.mark.usefixtures("applied_migration", "mock_airtable")
114-
def test_migrate_fake_migration_already_applied(runner):
115-
result = runner.invoke(app, ["migrate", "--fake", "fake_data_file_name"])
114+
def test_migrate_manual_migration_already_applied(runner):
115+
result = runner.invoke(app, ["migrate", "--manual", "fake_data_file_name"])
116116

117117
assert result.exit_code == 1, result.output
118118
assert (
119-
"Error running fake command: Migration fake_data_file_name already applied" in result.output
119+
"Error running manual command: Migration fake_data_file_name already applied"
120+
in result.output
120121
)
121122

122123

0 commit comments

Comments
 (0)