Remove migrate:begin/commit/rollback references, unify to migrate command

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2026-01-28 22:03:06 +00:00
parent 2ff2609971
commit 63816a7993
8 changed files with 59 additions and 58 deletions

View File

@@ -37,18 +37,21 @@ class Seed_Command extends LaravelSeedCommand
// Check for migration mode if we require it // Check for migration mode if we require it
if ($require_migration_mode) { if ($require_migration_mode) {
if (!file_exists($this->flag_file)) { if (!file_exists($this->flag_file)) {
$this->error(' Migration mode not active!'); $this->error('[ERROR] Migration mode not active!');
$this->error(''); $this->error('');
$this->line('In development mode, you must create a database snapshot before running seeders.'); $this->line('In development mode, seeders must be run within a migration session.');
$this->line('This prevents data corruption if seeding fails.'); $this->line('This prevents data corruption if seeding fails.');
$this->info(''); $this->info('');
$this->line('To begin a migration session:'); $this->line('To seed the database, use the --seed flag with migrate:');
$this->line(' php artisan migrate:begin'); $this->line(' php artisan migrate --seed');
$this->info('');
$this->line('Or use the --production flag to skip snapshot protection:');
$this->line(' php artisan db:seed --production');
return 1; return 1;
} }
$this->info(' Migration mode active - snapshot available for rollback'); $this->info('[OK] Migration mode active - snapshot available for rollback');
$this->info(''); $this->info('');
} }

View File

@@ -78,7 +78,7 @@ class Maint_Migrate extends Command
$this->info(' Development mode: Using automatic snapshot protection'); $this->info(' Development mode: Using automatic snapshot protection');
$this->info(''); $this->info('');
// Step 1: Create snapshot (migrate:begin logic) // Step 1: Create snapshot
$this->info('[1/4] Creating database snapshot...'); $this->info('[1/4] Creating database snapshot...');
if (!$this->create_snapshot()) { if (!$this->create_snapshot()) {
return 1; return 1;

View File

@@ -106,11 +106,14 @@ class Migrate_Normalize_Schema_Command extends Command
if (!file_exists($flag_file)) { if (!file_exists($flag_file)) {
$this->error('[ERROR] Migration mode not active!'); $this->error('[ERROR] Migration mode not active!');
$this->error(''); $this->error('');
$this->line('In development mode, you must create a database snapshot before running this command.'); $this->line('In development mode, this command should be run via "php artisan migrate"');
$this->line('This prevents partial migrations from corrupting your database.'); $this->line('which handles snapshots automatically.');
$this->info(''); $this->info('');
$this->line('To begin a migration session:'); $this->line('To run with snapshot protection:');
$this->line(' php artisan migrate:begin'); $this->line(' php artisan migrate');
$this->info('');
$this->line('Or use the --production flag to skip snapshot protection:');
$this->line(' php artisan migrate:normalize_schema --production');
return 1; return 1;
} }
@@ -298,15 +301,12 @@ class Migrate_Normalize_Schema_Command extends Command
$this->info(''); $this->info('');
$this->info('[OK] Database rolled back successfully!'); $this->info('[OK] Database rolled back successfully!');
$this->info(''); $this->info('');
$this->warn('[WARNING] You are still in migration mode.'); $this->line('Fix the issue mentioned in the error above, then run:');
$this->line('Your options:'); $this->line(' php artisan migrate');
$this->line(' 1. Fix the issue mentioned in the error above');
$this->line(' 2. Run "php artisan migrate" to try again');
$this->line(' 3. Run "php artisan migrate:commit" to exit migration mode');
} else { } else {
$this->error('[ERROR] Automatic rollback failed!'); $this->error('[ERROR] Automatic rollback failed!');
$this->error('Run "php artisan migrate:rollback" manually.');
$this->warn('[WARNING] The database may be in an inconsistent state!'); $this->warn('[WARNING] The database may be in an inconsistent state!');
$this->line('You may need to manually restore from backup.');
} }
} }

View File

@@ -25,12 +25,11 @@ class Migrate_Status_Command extends Command
$this->info('[OK] No migration session in progress'); $this->info('[OK] No migration session in progress');
$this->info(''); $this->info('');
if ($environment !== 'production') { $this->line('To run migrations:');
$this->line('To start a migration session:');
$this->line(' php artisan migrate:begin');
} else {
$this->line('In production, run migrations directly:');
$this->line(' php artisan migrate'); $this->line(' php artisan migrate');
if ($environment !== 'production') {
$this->line('');
$this->line('In development mode, snapshots are created automatically.');
} }
return 0; return 0;
@@ -57,10 +56,9 @@ class Migrate_Status_Command extends Command
} }
$this->info(''); $this->info('');
$this->line('Available Commands:'); $this->line('Migration Mode:');
$this->line(' • php artisan migrate - Run pending migrations'); $this->line(' This indicates the migrate command is running with snapshot protection.');
$this->line(' • php artisan migrate:commit - Keep changes and end session'); $this->line(' The snapshot will be auto-committed on success or auto-rolled back on failure.');
$this->line(' • php artisan migrate:rollback - Restore backup and end session');
// Check database connection // Check database connection
$this->info(''); $this->info('');

View File

@@ -14,7 +14,7 @@ use Illuminate\Support\Facades\DB;
* - Always allowed if IS_FRAMEWORK_DEVELOPER=true * - Always allowed if IS_FRAMEWORK_DEVELOPER=true
* - In development mode: allowed for manual execution, blocked for Claude Code * - In development mode: allowed for manual execution, blocked for Claude Code
* - In production mode: always blocked * - In production mode: always blocked
* - Must be in migration mode (migrate:begin) unless IS_FRAMEWORK_DEVELOPER=true * - Must be in migration mode unless IS_FRAMEWORK_DEVELOPER=true
*/ */
class Reset_Command extends Command class Reset_Command extends Command
{ {
@@ -67,17 +67,16 @@ class Reset_Command extends Command
// Require migration mode for non-framework developers // Require migration mode for non-framework developers
if (!$in_migration_mode) { if (!$in_migration_mode) {
$this->error(' migrate:reset requires migration mode to be active.'); $this->error('[ERROR] migrate:reset requires migration mode to be active.');
$this->newLine(); $this->newLine();
$this->warn('Database reset protection:'); $this->warn('Database reset protection:');
$this->line('This command can only be run within a migration session to ensure'); $this->line('This command can only be run within a migration session to ensure');
$this->line('you have a snapshot to restore if something goes wrong.'); $this->line('you have a snapshot to restore if something goes wrong.');
$this->newLine(); $this->newLine();
$this->info('To reset the database:'); $this->info('Note:');
$this->line('1. Start migration mode: php artisan migrate:begin'); $this->line('In development mode, "php artisan migrate" automatically creates');
$this->line('2. Reset database: php artisan migrate:reset'); $this->line('snapshots and manages rollback. This command is only needed for');
$this->line('3. Run migrations: php artisan migrate'); $this->line('full database drops, which is rarely necessary.');
$this->line('4. Commit or rollback: php artisan migrate:commit');
$this->newLine(); $this->newLine();
return 1; return 1;
} }

View File

@@ -137,14 +137,12 @@ class _Manifest_Database_Helper
// Commands that should skip code quality checks // Commands that should skip code quality checks
$migration_commands = [ $migration_commands = [
'migrate', 'migrate',
'migrate:begin',
'migrate:commit',
'migrate:fresh', 'migrate:fresh',
'migrate:install', 'migrate:install',
'migrate:refresh', 'migrate:refresh',
'migrate:reset', 'migrate:reset',
'migrate:rollback',
'migrate:status', 'migrate:status',
'migrate:normalize_schema',
'make:migration', 'make:migration',
'make:migration:safe', 'make:migration:safe',
'db:seed', 'db:seed',

View File

@@ -393,17 +393,14 @@ COMMANDS
Main migration command. Runs the full cycle: Main migration command. Runs the full cycle:
pre-normalize → migrations → post-normalize → regenerate constants (dev) pre-normalize → migrations → post-normalize → regenerate constants (dev)
### php artisan migrate:begin In development mode:
Creates MySQL snapshot before migrations (dev mode only). - Automatically creates database snapshot before migrations
Required for safety in development. - On success: commits changes, removes snapshot, regenerates constants/bundles
- On failure: automatically rolls back to snapshot
### php artisan migrate:commit In debug/production mode:
Deletes snapshot and exits migration mode. - Runs migrations directly without snapshot protection
Runs schema quality checks before committing. - Does NOT update source code (constants, bundles)
### php artisan migrate:rollback
Restores database to snapshot state.
Stays in migration mode for retry.
### php artisan migrate:normalize_schema ### php artisan migrate:normalize_schema
Manually run normalization (rarely needed). Manually run normalization (rarely needed).
@@ -415,15 +412,16 @@ COMMANDS
SNAPSHOT-BASED DEVELOPMENT SNAPSHOT-BASED DEVELOPMENT
-------------------------- --------------------------
Development migrations require snapshots for safety: In development mode, the migrate command handles snapshots automatically:
1. `php artisan migrate:begin` - Create snapshot 1. `php artisan migrate` - Does everything:
2. `php artisan migrate` - Run migrations - Creates snapshot before running
3. `php artisan migrate:commit` - Keep changes, delete snapshot - Runs all pending migrations
OR - On success: commits snapshot, regenerates constants
`php artisan migrate:rollback` - Discard changes, restore snapshot - On failure: rolls back to snapshot automatically
Production migrations skip snapshots and run directly. No manual snapshot management is needed. Just run `migrate` and the framework
handles safety automatically.
WHY NO FOREIGN KEY DROP/RECREATE? WHY NO FOREIGN KEY DROP/RECREATE?
--------------------------------- ---------------------------------

View File

@@ -266,13 +266,18 @@ DATABASE ARCHITECTURE
created_at, updated_at (with proper defaults) created_at, updated_at (with proper defaults)
Migration Safety: Migration Safety:
Development workflow uses database snapshots: The migrate command handles snapshots automatically:
- migrate:begin Creates snapshot before changes
- migrate Runs migrations with validation
- migrate:commit Commits changes and removes snapshot
- migrate:rollback Restores snapshot if problems occur
Production workflow skips snapshots (test thoroughly first). Development mode:
- php artisan migrate
- Automatically creates snapshot before running
- On success: commits and regenerates constants/bundles
- On failure: automatically rolls back to snapshot
Production mode:
- php artisan migrate
- Runs directly without snapshot protection
- Test thoroughly in development first
Site-Based Multi-Tenancy: Site-Based Multi-Tenancy:
Models extend one of two base classes: Models extend one of two base classes: