Skip to content

Commit 62dee78

Browse files
author
euromark
committed
adding models for schema generate
1 parent 5e0e850 commit 62dee78

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/Cake/Console/Command/SchemaShell.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public function generate() {
127127
$this->out(__d('cake_console', 'Generating Schema...'));
128128
$options = array();
129129
if ($this->params['force']) {
130-
$options = array('models' => false);
130+
$options['models'] = false;
131+
} elseif (!empty($this->params['models'])) {
132+
$options['models'] = String::tokenize($this->params['models']);
131133
}
132134

133135
$snapshot = false;
@@ -464,6 +466,10 @@ public function getOptionParser() {
464466
'short' => 's',
465467
'help' => __d('cake_console', 'Snapshot number to use/make.')
466468
);
469+
$models = array(
470+
'short' => 'm',
471+
'help' => __d('cake_console', 'Specify models as comma separated list.'),
472+
);
467473
$dry = array(
468474
'help' => __d('cake_console', 'Perform a dry run on create and update commands. Queries will be output instead of run.'),
469475
'boolean' => true
@@ -489,7 +495,7 @@ public function getOptionParser() {
489495
))->addSubcommand('generate', array(
490496
'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'),
491497
'parser' => array(
492-
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force'),
498+
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force', 'models'),
493499
'arguments' => array(
494500
'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.'))
495501
)

lib/Cake/Test/Case/Console/Command/SchemaShellTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,41 @@ public function testGenerateWithPlugins() {
362362
CakePlugin::unload();
363363
}
364364

365+
/**
366+
* test generate with specific models
367+
*
368+
* @return void
369+
*/
370+
public function testGenerateModels() {
371+
App::build(array(
372+
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
373+
), App::RESET);
374+
CakePlugin::load('TestPlugin');
375+
376+
$this->db->cacheSources = false;
377+
$this->Shell->params = array(
378+
'plugin' => 'TestPlugin',
379+
'connection' => 'test',
380+
'models' => 'TestPluginComment',
381+
'force' => false,
382+
'overwrite' => true
383+
);
384+
$this->Shell->startup();
385+
$this->Shell->Schema->path = TMP . 'tests' . DS;
386+
387+
$this->Shell->generate();
388+
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
389+
$contents = $this->file->read();
390+
391+
$this->assertRegExp('/class TestPluginSchema/', $contents);
392+
$this->assertRegExp('/public \$test_plugin_comments/', $contents);
393+
$this->assertNotRegExp('/public \$authors/', $contents);
394+
$this->assertNotRegExp('/public \$auth_users/', $contents);
395+
$this->assertNotRegExp('/public \$posts/', $contents);
396+
CakePlugin::unload();
397+
}
398+
399+
365400
/**
366401
* Test schema run create with no table args.
367402
*

0 commit comments

Comments
 (0)