Skip to content

Ask before migration:fresh, reset and refresh in production - #9

Merged
necessarylion merged 1 commit into
mainfrom
migration-production-confirm
Nov 2, 2026
Merged

necessarylion merged 1 commit into
mainfrom
migration-production-confirm

Conversation

@mydoxie

@mydoxie mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Problem

dox migration:fresh, migration:reset and migration:refresh drop all tables. In production they ran with no check. One wrong command could wipe the database.

Fix

These three commands now check APP_ENV first. It is read the same way the Migrator reads it: the real environment, then .env (loadEnv from dox_migration).

  • APP_ENV is not production: nothing changes.
  • production and stdin is a terminal: ask APP_ENV is production. This drops all tables. Continue? (y/N). Any answer other than y stops with exit code 1.
  • production and no terminal (CI, deploy scripts): print a warning and run, as before.
  • --force: skip the question. It is removed from the args before bin/migrate.dart runs.

No breaking change. Scripts without a terminal work as before.

Tests

New test/confirm_drop_test.dart covers production or not, terminal or not, and --force. dart analyze and dart test pass.

@mydoxie

mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Bot review

Verdict: changes requested. The logic is right and the tests are good. Three things must change before merge.

Checked: dart analyze (no issues) and dart test (93 pass) on this branch. I also merged main into it locally, fixed the conflicts, ran ci/use-siblings.sh, and got dart analyze clean and dart test 120 pass. No version bump in pubspec.yaml. The changelog line is under ## Unreleased. Behaviour outside production and without a terminal is the same as before.

Blocking

  1. Import from dox_migration/src can break the whole CLI. confirm_drop.dart imports package:dox_migration/src/utils/env.dart with // ignore: implementation_imports. src is private, so a later dox_migration patch can move or rename that file. Users install the CLI with dart pub global activate dox, which takes the newest dox_migration ^3. If the file moves, dox fails to compile, and every command stops, not only the migration ones. Sibling CI here does not catch it, because a dox_migration PR does not run dox-cli tests.
    Fix: in dartondox/dox-orm, add a small public library packages/dox-migration/lib/env.dart with export 'src/utils/env.dart' show loadEnv;. It is a new file, so no app gets a new top-level name. Then import package:dox_migration/env.dart here and drop the lint ignore. CI can use the sibling branch with the same name. Raise the dox_migration constraint at release, not in this PR.
  2. Merge conflict with main in CHANGELOG.md and lib/src/command_registry.dart. The branch starts before docs: fix getting started steps #6, CI: test against the newest code of the other Dox repos #7 and Find and run dox commands from packages and the app #8. Rebase it on main. Put this line together with the Find and run dox commands from packages and the app #8 lines under the one ## Unreleased heading. In _migration, run the confirmDropAll check first, then the new writeMigrateEntry() block from Find and run dox commands from packages and the app #8. I tested that order and it works.
  3. docs: migration commands ask before dropping tables in production dox#315 also conflicts, and it holds old commits. That branch is built on three commits from #308 (2ed4dcb, f5b2ea7, e8fd720). #308 was squash merged, and later PRs changed the same files, so docs/database/query-builder.md conflicts. Rebase it on main with only f4eace9 (the migration.md line). The other changes are already on main.

Non-blocking

  • The tests cover yes, no, no terminal, --force and non-production, but only in confirmDropAll. No test checks that _migration stops before it runs bin/migrate.dart, or that it removes --force from the args. One small test would guard that.
  • migration:rollback also runs down() and can drop tables. It has no check. That is fine for this PR. Maybe add it later.
  • --force is now removed from the args of every migration command, also migration:run. That is harmless, but dox migrate --force now does nothing and gives no message.
  • docs/reference/cli.md (around line 334) lists --seed for these commands but not --force. Add one line in #315.

@mydoxie
mydoxie force-pushed the migration-production-confirm branch from a172eb0 to 026efac Compare November 2, 2026 04:54
@mydoxie

mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Fixer reply

All three blocking items are fixed.

  1. No more src import. dox-orm#34 (dox_migration: export loadEnv from a public env.dart dox-orm#34) adds packages/dox-migration/lib/env.dart, which exports loadEnv. It has a changelog line under ## Unreleased and no version bump. Its branch has the same name as this one, so sibling CI uses it. confirm_drop.dart now imports package:dox_migration/env.dart, and the lint ignore is gone. The dox_migration constraint is not changed. Raise it at release.
  2. Rebased on main. Both changelog entries are under one ## Unreleased. In _migration, the confirmDropAll check runs first, then the writeMigrateEntry() block from Find and run dox commands from packages and the app #8.
  3. dox#315 rebased. It now has only the migration.md commit on top of main. It also has one new line for --force in docs/reference/cli.md, next to --seed.

Checks, after ci/use-siblings.sh with the dox-orm branch: dart analyze has no issues, and dart test passes (120 tests).

I left the non-blocking items alone. The coordinator will log them in todo.md.

@mydoxie

mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Bot review

Round 2. Verdict: nothing blocks. Ready to merge (merge dox-orm#34 first).

Checked with dox-cli and dox-orm side by side on the PR branches, ci/use-siblings.sh, dart pub get: dart analyze has no issues, dart test passes (120 tests).

Blocking

None.

Non-blocking

  • All three PRs are mergeable with main. No conflicts. dox-cli and dox-orm each have exactly one commit on top of main. dox#315 has two docs commits, both its own.
  • The import is now package:dox_migration/env.dart with show loadEnv. No src import and no lint ignore.
  • In _migration, the confirm check runs before the writeMigrateEntry() block. Nothing is written when the user says no.
  • The dox-cli changelog line sits under the one ## Unreleased. The dox_migration entry sits under its own ## Unreleased. No version changes (both still 3.0.1).
  • No breaking change: outside production, with --force, or with no terminal, the code returns true and runs as before. --force is now removed from the args sent to bin/migrate.dart, but nothing reads it there.
  • Docs are correct and plain. They match the code.
  • Small thing: the "Stopped" path exits with code 1. This is fine and is in the changelog.

@necessarylion
necessarylion merged commit cacf282 into main Nov 2, 2026
1 check passed
@necessarylion
necessarylion deleted the migration-production-confirm branch November 2, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants