adding workaround for schema generate snapshot. Fixes #5159 Adding documentation for schema generate snapshot.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7429 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
DarkAngelBGE 2008-08-04 16:53:39 +00:00
parent ac6c22d910
commit b3f06defcd
2 changed files with 75 additions and 62 deletions

View file

@ -136,6 +136,12 @@ class SchemaShell extends Shell {
if ($snapshot === true) {
$Folder =& new Folder($this->Schema->path);
$result = $Folder->read();
$numToUse = false;
if (isset($this->params['s'])) {
$numToUse = $this->params['s'];
}
$count = 1;
if (!empty($result[1])) {
foreach ($result[1] as $file) {
@ -144,6 +150,13 @@ class SchemaShell extends Shell {
}
}
}
if ($numToUse !== false) {
if ($numToUse > $count) {
$count = $numToUse;
}
}
$content['file'] = 'schema_'.$count.'.php';
}
@ -274,19 +287,19 @@ class SchemaShell extends Shell {
$this->_stop();
}
$this->out("\n" . __('The following tables will be dropped.', true));
$this->out("\n" . __('The following table(s) will be dropped.', true));
$this->out(array_keys($drop));
if ('y' == $this->in(__('Are you sure you want to drop the tables?', true), array('y', 'n'), 'n')) {
$this->out('Dropping tables.');
if ('y' == $this->in(__('Are you sure you want to drop the table(s)?', true), array('y', 'n'), 'n')) {
$this->out('Dropping table(s).');
$this->__run($drop, 'drop');
}
$this->out("\n" . __('The following tables will be created.', true));
$this->out("\n" . __('The following table(s) will be created.', true));
$this->out(array_keys($create));
if ('y' == $this->in(__('Are you sure you want to create the tables?', true), array('y', 'n'), 'y')) {
$this->out('Creating tables.');
if ('y' == $this->in(__('Are you sure you want to create the table(s)?', true), array('y', 'n'), 'y')) {
$this->out('Creating table(s).');
$this->__run($create, 'create');
}
@ -391,7 +404,7 @@ class SchemaShell extends Shell {
$this->out('Commands:');
$this->out("\n\tschema help\n\t\tshows this help message.");
$this->out("\n\tschema view\n\t\tread and output contents of schema file");
$this->out("\n\tschema generate\n\t\treads from 'connection' writes to 'path'\n\t\tTo force genaration of all tables into the schema, use the -f param.");
$this->out("\n\tschema generate\n\t\treads from 'connection' writes to 'path'\n\t\tTo force generation of all tables into the schema, use the -f param.\n\t\tUse 'schema generate snapshot <number>' to generate snapshots which you can use with the -s parameter in the other operations.");
$this->out("\n\tschema dump <filename>\n\t\tdump database sql based on schema file to filename in schema path. \n\t\tif filename is true, default will use the app directory name.");
$this->out("\n\tschema run create <schema> <table>\n\t\tdrop tables and create database based on schema file\n\t\toptional <schema> arg for selecting schema name\n\t\toptional <table> arg for creating only one table\n\t\tpass the -s param with a number to use a snapshot\n\t\tTo see the changes, perform a dry run with the -dry param");
$this->out("\n\tschema run update <schema> <table>\n\t\talter tables based on schema file\n\t\toptional <schema> arg for selecting schema name.\n\t\toptional <table> arg for altering only one table.\n\t\tTo use a snapshot, pass the -s param with the snapshot number\n\t\tTo see the changes, perform a dry run with the -dry param");

View file

@ -55,15 +55,15 @@ class MyAppSchema extends CakeSchema {
* @access public
*/
var $comments = array(
'id' => array('type'=>'integer', 'null' => false, 'default'=> 0, 'key' => 'primary'),
'post_id' => array('type'=>'integer', 'null' => false, 'default'=> 0),
'user_id' => array('type'=>'integer', 'null' => false),
'title' => array('type'=>'string', 'null' => false, 'length'=> 100),
'comment' => array('type'=>'text', 'null' => false, 'default'=> null),
'published' => array('type'=>'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'updated' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'indexes' => array('PRIMARY'=>array('column'=>'id', 'unique' => true)),
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'user_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* posts property
@ -72,15 +72,15 @@ class MyAppSchema extends CakeSchema {
* @access public
*/
var $posts = array(
'id' => array('type'=>'integer', 'null' => false, 'default'=> 0, 'key' => 'primary'),
'author_id' => array('type'=>'integer', 'null' => true, 'default'=> ''),
'title' => array('type'=>'string', 'null' => false, 'default'=> 'Title'),
'body' => array('type'=>'text', 'null' => true, 'default'=> null),
'summary'=>array('type'=> 'text', 'null'=> true),
'published' => array('type'=>'string', 'null' => true, 'default' => 'Y', 'length' => 1),
'created' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'updated' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'indexes' => array('PRIMARY'=>array('column'=>'id', 'unique' => true)),
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'summary' => array('type' => 'text', 'null' => true),
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* setup method
@ -104,8 +104,8 @@ class MyAppSchema extends CakeSchema {
/**
* TestAppSchema class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class TestAppSchema extends CakeSchema {
/**
@ -122,14 +122,14 @@ class TestAppSchema extends CakeSchema {
* @access public
*/
var $comments = array(
'id' => array('type'=>'integer', 'null' => false, 'default'=> 0,'key' => 'primary'),
'article_id' => array('type'=>'integer', 'null' => false),
'user_id' => array('type'=>'integer', 'null' => false),
'comment' => array('type'=>'text', 'null' => true, 'default'=> null),
'published' => array('type'=>'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'updated' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'indexes' => array('PRIMARY'=>array('column'=>'id', 'unique' => true)),
'id' => array('type' => 'integer', 'null' => false, 'default' => 0,'key' => 'primary'),
'article_id' => array('type' => 'integer', 'null' => false),
'user_id' => array('type' => 'integer', 'null' => false),
'comment' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* posts property
@ -138,14 +138,14 @@ class TestAppSchema extends CakeSchema {
* @access public
*/
var $posts = array(
'id' => array('type'=>'integer', 'null' => false, 'default'=> 0, 'key' => 'primary'),
'author_id' => array('type'=>'integer', 'null' => false),
'title' => array('type'=>'string', 'null' => false),
'body' => array('type'=>'text', 'null' => true, 'default'=> null),
'published' => array('type'=>'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'updated' => array('type'=>'datetime', 'null' => true, 'default'=> null),
'indexes' => array('PRIMARY'=>array('column'=>'id', 'unique' => true)),
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* posts_tags property
@ -165,11 +165,11 @@ class TestAppSchema extends CakeSchema {
* @access public
*/
var $tags = array(
'id' => array('type' => 'integer', 'null'=> false, 'default'=> 0, 'key' => 'primary'),
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'tag' => array('type' => 'string', 'null' => false),
'created' => array('type' => 'datetime', 'null' => true, 'default'=> null),
'updated' => array('type' => 'datetime', 'null' => true, 'default'=> null),
'indexes' => array('PRIMARY'=>array('column'=>'id', 'unique' => true)),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* datatypes property
@ -178,9 +178,9 @@ class TestAppSchema extends CakeSchema {
* @access public
*/
var $datatypes = array(
'id' => array('type' => 'integer', 'null'=> false, 'default'=> 0, 'key' => 'primary'),
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
'indexes' => array('PRIMARY'=>array('column'=>'id', 'unique' => true)),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* setup method
@ -405,7 +405,7 @@ class CakeSchemaTest extends CakeTestCase {
* @return void
*/
function testSchemaRead() {
$read = $this->Schema->read(array('connection'=>'test_suite', 'name'=>'TestApp', 'models' => array('SchemaPost', 'SchemaComment', 'SchemaTag', 'SchemaDatatype')));
$read = $this->Schema->read(array('connection' => 'test_suite', 'name' => 'TestApp', 'models' => array('SchemaPost', 'SchemaComment', 'SchemaTag', 'SchemaDatatype')));
unset($read['tables']['missing']);
$this->assertEqual($read['tables'], $this->Schema->tables);
$this->assertIdentical($read['tables']['datatypes']['float_field'], $this->Schema->tables['datatypes']['float_field']);
@ -418,7 +418,7 @@ class CakeSchemaTest extends CakeTestCase {
*/
function testSchemaWrite() {
$write = $this->Schema->write(array('name'=>'MyOtherApp', 'tables'=> $this->Schema->tables, 'path'=> TMP . 'tests'));
$write = $this->Schema->write(array('name' => 'MyOtherApp', 'tables' => $this->Schema->tables, 'path' => TMP . 'tests'));
$file = file_get_contents(TMP . 'tests' . DS .'schema.php');
$this->assertEqual($write, $file);
@ -437,19 +437,19 @@ class CakeSchemaTest extends CakeTestCase {
$New = new MyAppSchema();
$compare = $New->compare($this->Schema);
$expected = array(
'comments'=> array(
'add'=> array('post_id'=> array('type'=> 'integer', 'null'=> false, 'default'=> 0),
'title'=> array('type'=> 'string', 'null'=> false, 'length'=> 100)
'comments' => array(
'add' => array('post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'title' => array('type' => 'string', 'null' => false, 'length' => 100)
),
'drop'=> array('article_id'=> array('type'=> 'integer', 'null'=> false)),
'change'=> array('comment'=> array('type'=>'text', 'null'=> false, 'default'=> null))
'drop' => array('article_id' => array('type' => 'integer', 'null' => false)),
'change' => array('comment' => array('type' => 'text', 'null' => false, 'default' => null))
),
'posts'=> array(
'add'=> array('summary'=>array('type'=> 'text', 'null'=> 1)),
'change'=> array('author_id'=> array('type'=>'integer', 'null'=> true, 'default'=> ''),
'title'=> array('type'=>'string', 'null'=> false, 'default'=> 'Title'),
'published'=> array('type'=>'string', 'null'=> true, 'default'=>'Y', 'length'=> '1')
'posts' => array(
'add' => array('summary' => array('type' => 'text', 'null' => 1)),
'change' => array('author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => '1')
),
),
);
@ -463,7 +463,7 @@ class CakeSchemaTest extends CakeTestCase {
* @return void
*/
function testSchemaLoading() {
$Other = $this->Schema->load(array('name'=>'MyOtherApp', 'path'=> TMP . 'tests'));
$Other = $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests'));
$this->assertEqual($Other->name, 'MyOtherApp');
$this->assertEqual($Other->tables, $this->Schema->tables);
}