Permalink
Browse files

SchemaShell: Implement "exclude" parameter

Allows for passing a list of tables to ignore when generating schemas.
Closes #3652.
  • Loading branch information...
1 parent 9cffb0b commit c920209f58e18134ed1e5044abab746e1066807f Alexander Hofbauer committed with aleho Mar 4, 2013
Showing with 35 additions and 1 deletion.
  1. +11 −1 lib/Cake/Console/Command/SchemaShell.php
  2. +24 −0 lib/Cake/Test/Case/Console/Command/SchemaShellTest.php
@@ -152,6 +152,13 @@ public function generate() {
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) {
$fileName = rtrim($this->params['file'], '.php');
$Folder = new Folder($this->Schema->path);
@@ -479,6 +486,9 @@ public function getOptionParser() {
$write = array(
'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->description(
@@ -492,7 +502,7 @@ public function getOptionParser() {
))->addSubcommand('generate', array(
'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'),
'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(
'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.'))
)
@@ -398,6 +398,30 @@ public function testGenerateModels() {
}
/**
+ * 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.
*
* @return void

0 comments on commit c920209

Please sign in to comment.