Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce migrate/create-all to generate migrations for all tables in… #3

Merged
merged 3 commits into from
Mar 29, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/controllers/MigrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function massDecision($type, $table, $actionMethod)
}

/**
* Creates new migration for a given tables.
* Creates new migration for a given table.
* @param string $table Table names separated by commas.
* @throws InvalidParamException
*/
Expand All @@ -432,6 +432,27 @@ public function actionCreate($table)
});
}

/**
* Creates new migrations for every table in your database.
* @throws InvalidParamException
*/
public function actionCreateAll()
{
$tables = $this->db->schema->getTableNames();

if (!$tables) {
return $this->stdout("Your Database does not contain any tables yet.");
}

if ($this->prompt("Are you sure you want to generate " . count($tables) . " migrations? [yes/no]") === 'yes') {
foreach ($tables as $table) {
$this->actionCreate($table);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of iterating over the tables you can call this action once and pass the imploded list of names - thanks to this the same mass decision can be used for each table if user would like to change the default one in case of file to be generated already exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok ! Good to know. Will adjust.

}
} else {
$this->stdout("Operation cancelled by user\n");
}
}

/**
* Creates new update migration for a given tables.
* @param string $table Table names separated by commas.
Expand Down