mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
SchemaShell: Implement "exclude" parameter
Allows for passing a list of tables to ignore when generating schemas. Closes #3652.
This commit is contained in:
parent
9cffb0b4c1
commit
c920209f58
2 changed files with 35 additions and 1 deletions
|
@ -152,6 +152,13 @@ class SchemaShell extends AppShell {
|
||||||
|
|
||||||
Configure::write('Cache.disable', $cacheDisable);
|
Configure::write('Cache.disable', $cacheDisable);
|
||||||
|
|
||||||
|
if (!empty($this->params['exclude']) && !empty($content)) {
|
||||||
|
$excluded = String::tokenize($this->params['exclude']);
|
||||||
|
foreach ($excluded as $table) {
|
||||||
|
unset($content['tables'][$table]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($snapshot === true) {
|
if ($snapshot === true) {
|
||||||
$fileName = rtrim($this->params['file'], '.php');
|
$fileName = rtrim($this->params['file'], '.php');
|
||||||
$Folder = new Folder($this->Schema->path);
|
$Folder = new Folder($this->Schema->path);
|
||||||
|
@ -479,6 +486,9 @@ class SchemaShell extends AppShell {
|
||||||
$write = array(
|
$write = array(
|
||||||
'help' => __d('cake_console', 'Write the dumped SQL to a file.')
|
'help' => __d('cake_console', 'Write the dumped SQL to a file.')
|
||||||
);
|
);
|
||||||
|
$exclude = array(
|
||||||
|
'help' => __d('cake_console', 'Tables to exclude as comma separated list.')
|
||||||
|
);
|
||||||
|
|
||||||
$parser = parent::getOptionParser();
|
$parser = parent::getOptionParser();
|
||||||
$parser->description(
|
$parser->description(
|
||||||
|
@ -492,7 +502,7 @@ class SchemaShell extends AppShell {
|
||||||
))->addSubcommand('generate', array(
|
))->addSubcommand('generate', array(
|
||||||
'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'),
|
'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'),
|
||||||
'parser' => array(
|
'parser' => array(
|
||||||
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force', 'models'),
|
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force', 'models', 'exclude'),
|
||||||
'arguments' => array(
|
'arguments' => array(
|
||||||
'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.'))
|
'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.'))
|
||||||
)
|
)
|
||||||
|
|
|
@ -397,6 +397,30 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
CakePlugin::unload();
|
CakePlugin::unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test generate with excluded tables
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGenerateExclude() {
|
||||||
|
$this->db->cacheSources = false;
|
||||||
|
$this->Shell->params = array(
|
||||||
|
'force' => false,
|
||||||
|
'overwrite' => true,
|
||||||
|
'exclude' => 'acos,aros'
|
||||||
|
);
|
||||||
|
$this->Shell->startup();
|
||||||
|
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
||||||
|
|
||||||
|
$this->Shell->generate();
|
||||||
|
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
||||||
|
$contents = $this->file->read();
|
||||||
|
|
||||||
|
$this->assertNotRegExp('/public \$aros = array\(/', $contents);
|
||||||
|
$this->assertNotRegExp('/public \$acos = array\(/', $contents);
|
||||||
|
$this->assertRegExp('/public \$aros_acos = array\(/', $contents);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test schema run create with no table args.
|
* Test schema run create with no table args.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue