Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
9440cf04
Commit
9440cf04
authored
Oct 19, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additions to migrations to support generating migrations from models or existing databases.
parent
16933ef9
Changes
28
Show whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
1082 additions
and
62 deletions
+1082
-62
Doctrine.php
lib/Doctrine.php
+55
-17
Export.php
lib/Doctrine/Export.php
+8
-2
Builder.php
lib/Doctrine/Import/Builder.php
+0
-1
Migration.php
lib/Doctrine/Migration.php
+19
-20
Builder.php
lib/Doctrine/Migration/Builder.php
+315
-0
Task.php
lib/Doctrine/Task.php
+1
-1
GenerateMigrationsFromDb.php
lib/Doctrine/Task/GenerateMigrationsFromDb.php
+43
-0
GenerateMigrationsFromModels.php
lib/Doctrine/Task/GenerateMigrationsFromModels.php
+44
-0
Migrate.php
lib/Doctrine/Task/Migrate.php
+2
-2
001_add_adult.class.php
sandbox/migrations/001_add_adult.class.php
+42
-0
002_add_car.class.php
sandbox/migrations/002_add_car.class.php
+37
-0
003_add_child.class.php
sandbox/migrations/003_add_child.class.php
+42
-0
004_add_contact.class.php
sandbox/migrations/004_add_contact.class.php
+37
-0
005_add_dog.class.php
sandbox/migrations/005_add_dog.class.php
+42
-0
006_add_entity.class.php
sandbox/migrations/006_add_entity.class.php
+32
-0
007_add_groups.class.php
sandbox/migrations/007_add_groups.class.php
+38
-0
008_add_self_reference.class.php
sandbox/migrations/008_add_self_reference.class.php
+57
-0
009_add_user.class.php
sandbox/migrations/009_add_user.class.php
+60
-0
010_add_user_car.class.php
sandbox/migrations/010_add_user_car.class.php
+38
-0
011_add_user_group.class.php
sandbox/migrations/011_add_user_group.class.php
+38
-0
012_apply_foreign_key_constraints.class.php
...ox/migrations/012_apply_foreign_key_constraints.class.php
+112
-0
BaseGroup.class.php
sandbox/models/generated/BaseGroup.class.php
+4
-4
BaseUserGroup.class.php
sandbox/models/generated/BaseUserGroup.class.php
+2
-2
sandbox.db
sandbox/sandbox.db
+0
-0
group.yml
sandbox/schema/group.yml
+3
-2
self_reference.yml
sandbox/schema/self_reference.yml
+7
-7
user_group.yml
sandbox/schema/user_group.yml
+3
-3
ExportTestCase.php
tests/ExportTestCase.php
+1
-1
No files found.
lib/Doctrine.php
View file @
9440cf04
...
...
@@ -826,13 +826,13 @@ final class Doctrine
*
* Migrate database to specified $to version. Migrates from current to latest if you do not specify.
*
* @param string $
directory D
irectory which contains your migration classes
* @param string $
migrationsPath Path to migrations d
irectory which contains your migration classes
* @param string $to Version you wish to migrate to.
* @return void
*/
public
static
function
migrate
(
$
directory
,
$to
=
null
)
public
static
function
migrate
(
$
migrationsPath
,
$to
=
null
)
{
$migration
=
new
Doctrine_Migration
(
$
directory
);
$migration
=
new
Doctrine_Migration
(
$
migrationsPath
);
return
$migration
->
migrate
(
$to
);
}
...
...
@@ -843,26 +843,64 @@ final class Doctrine
* Generate new migration class skeleton
*
* @param string $className Name of the Migration class to generate
* @param string $
directory D
irectory which contains your migration classes
* @param string $
migrationsPath Path to d
irectory which contains your migration classes
* @package default
*/
public
static
function
generateMigrationClass
(
$className
,
$
directory
)
public
static
function
generateMigrationClass
(
$className
,
$
migrationsPath
)
{
$migration
=
new
Doctrine_Migration
(
$directory
);
$next
=
(
string
)
$migration
->
getNextVersion
();
$builder
=
new
Doctrine_Migration_Builder
(
$migrationsPath
);
$fileName
=
str_repeat
(
'0'
,
(
3
-
strlen
(
$next
)))
.
$next
.
'_'
.
self
::
tableize
(
$className
)
.
'.class.php'
;
$path
=
$directory
.
DIRECTORY_SEPARATOR
.
$fileName
;
return
$builder
->
generateMigrationClass
(
$className
);
}
/**
* generateMigrationsFromDb
*
* @param string $migrationsPath
* @return void
*/
public
function
generateMigrationsFromDb
(
$migrationsPath
)
{
$builder
=
new
Doctrine_Migration_Builder
(
$migrationsPath
);
$code
=
'<?php'
.
PHP_EOL
;
$code
.=
"// Automatically generated by the Doctrine ORM Framework
\n
"
;
$code
.=
"class "
.
self
::
classify
(
$className
)
.
" extends Doctrine_Migration
\n
"
;
$code
.=
"{\n"
;
$code
.=
"
\t
public function up()
\n\t
{ }
\n\n
"
;
$code
.=
"
\t
public function down()
\n\t
{ }
\n
"
;
$code
.=
"}"
;
return
$builder
->
generateMigrationsFromDb
();
}
file_put_contents
(
$path
,
$code
);
/**
* generateMigrationsFromModels
*
* @param string $migrationsPath
* @param string $modelsPath
* @return void
*/
public
function
generateMigrationsFromModels
(
$migrationsPath
,
$modelsPath
=
null
)
{
$builder
=
new
Doctrine_Migration_Builder
(
$migrationsPath
);
return
$builder
->
generateMigrationsFromModels
(
$modelsPath
);
}
/**
* getTable
*
* @param string $tableName
* @return void
*/
public
function
getTable
(
$tableName
)
{
return
Doctrine_Manager
::
table
(
$tableName
);
}
/**
* connection
*
* @param string $adapter
* @param string $name
* @return void
*/
public
function
connection
(
$adapter
,
$name
=
null
)
{
return
Doctrine_Manager
::
connection
(
$adapter
,
$name
);
}
/**
...
...
lib/Doctrine/Export.php
View file @
9440cf04
...
...
@@ -114,6 +114,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
public
function
dropIndexSql
(
$table
,
$name
)
{
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
));
return
'DROP INDEX '
.
$name
;
}
/**
...
...
@@ -128,6 +129,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
));
return
$this
->
conn
->
exec
(
'ALTER TABLE '
.
$table
.
' DROP CONSTRAINT '
.
$name
);
}
/**
...
...
@@ -330,7 +332,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public
function
createConstraint
(
$table
,
$name
,
$definition
)
{
return
$this
->
conn
->
exec
(
$this
->
createConstraintSql
(
$table
,
$name
,
$definition
));
$sql
=
$this
->
createConstraintSql
(
$table
,
$name
,
$definition
);
return
$this
->
conn
->
exec
(
$sql
);
}
/**
* create a constraint on a table
...
...
@@ -467,7 +471,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public
function
createForeignKey
(
$table
,
array
$definition
)
{
return
$this
->
conn
->
execute
(
$this
->
createForeignKeySql
(
$table
,
$definition
));
$sql
=
$this
->
createForeignKeySql
(
$table
,
$definition
);
return
$this
->
conn
->
execute
(
$sql
);
}
/**
* alter an existing table
...
...
lib/Doctrine/Import/Builder.php
View file @
9440cf04
...
...
@@ -158,7 +158,6 @@ class Doctrine_Import_Builder
%
s
}
END
;
}
/*
...
...
lib/Doctrine/Migration.php
View file @
9440cf04
...
...
@@ -49,7 +49,8 @@ class Doctrine_Migration
),
$migrationTableName
=
'migration_version'
,
$migrationClassesDirectory
=
array
(),
$migrationClasses
=
array
();
$migrationClasses
=
array
(),
$loadedMigrations
=
array
();
/**
* construct
...
...
@@ -104,35 +105,34 @@ class Doctrine_Migration
return
$this
->
migrationClasses
;
}
$directory
=
$this
->
migrationClassesDirectory
;
$classes
=
get_declared_classes
();
$loadedClasses
=
array
();
if
(
$
d
irectory
!==
null
)
{
foreach
((
array
)
$
d
irectory
as
$dir
)
{
if
(
$
this
->
migrationClassesD
irectory
!==
null
)
{
foreach
((
array
)
$
this
->
migrationClassesD
irectory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
require_once
$file
->
getPathName
();
if
(
!
in_array
(
$file
->
getFileName
(),
$this
->
loadedMigrations
))
{
require_once
(
$file
->
getPathName
());
$requiredClass
=
array_diff
(
get_declared_classes
(),
$classes
);
$requiredClass
=
end
(
$requiredClass
);
$loadedClasses
[
$requiredClass
]
=
$file
->
getFileName
();
if
(
$requiredClass
)
{
$this
->
loadedMigrations
[
$requiredClass
]
=
$file
->
getFileName
();
}
}
}
}
}
}
$classes
=
$loadedClasses
;
$parent
=
new
ReflectionClass
(
'Doctrine_Migration'
);
$loadedClasses
=
array
();
foreach
(
$
classe
s
as
$name
=>
$fileName
)
{
foreach
(
$
this
->
loadedMigration
s
as
$name
=>
$fileName
)
{
$class
=
new
ReflectionClass
(
$name
);
while
(
$class
->
isSubclassOf
(
$parent
))
{
...
...
@@ -150,11 +150,9 @@ class Doctrine_Migration
$e
=
explode
(
'_'
,
$fileName
);
$classMigrationNum
=
(
int
)
$e
[
0
];
$
loaded
Classes
[
$classMigrationNum
]
=
array
(
'className'
=>
$name
,
'fileName'
=>
$fileName
);
$
this
->
migration
Classes
[
$classMigrationNum
]
=
array
(
'className'
=>
$name
,
'fileName'
=>
$fileName
);
}
$this
->
migrationClasses
=
$loadedClasses
;
return
$this
->
migrationClasses
;
}
...
...
@@ -280,6 +278,7 @@ class Doctrine_Migration
protected
function
doMigrateStep
(
$direction
,
$num
)
{
$migrate
=
$this
->
getMigrationClass
(
$num
);
$migrate
->
doMigrate
(
$direction
);
}
...
...
@@ -327,7 +326,7 @@ class Doctrine_Migration
}
if
(
$from
==
$to
)
{
throw
new
Doctrine_Migration_Exception
(
'Already
up-to-date'
);
throw
new
Doctrine_Migration_Exception
(
'Already
at version: '
.
$to
);
}
$direction
=
$from
>
$to
?
'down'
:
'up'
;
...
...
lib/Doctrine/Migration/Builder.php
0 → 100644
View file @
9440cf04
<?php
/*
* $Id: Builder.php 2939 2007-10-19 14:23:42Z Jonathan.Wage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Migration_Builder
*
* @package Doctrine
* @subpackage Migration
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jonathan H. Wage <jwage@mac.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 2939 $
*/
class
Doctrine_Migration_Builder
{
/**
* migrationsPath
*
* The path to your migration classes directory
*
* @var string
*/
private
$migrationsPath
=
''
;
/**
* suffix
*
* File suffix to use when writing class definitions
*
* @var string $suffix
*/
private
$suffix
=
'.class.php'
;
/**
* tpl
*
* Class template used for writing classes
*
* @var $tpl
*/
private
static
$tpl
;
/**
* __construct
*
* @return void
*/
public
function
__construct
(
$migrationsPath
=
null
)
{
if
(
$migrationsPath
)
{
$this
->
setMigrationsPath
(
$migrationsPath
);
}
$this
->
loadTemplate
();
}
/**
* setMigrationsPath
*
* @param string path the path where migration classes are stored and being generated
* @return
*/
public
function
setMigrationsPath
(
$path
)
{
if
(
!
file_exists
(
$path
))
{
mkdir
(
$path
,
0777
);
}
$this
->
migrationsPath
=
$path
;
}
/**
* getMigrationsPath
*
* @return string the path where migration classes are stored and being generated
*/
public
function
getMigrationsPath
()
{
return
$this
->
migrationsPath
;
}
/**
* loadTemplate
*
* Loads the class template used for generating classes
*
* @return void
*/
protected
function
loadTemplate
()
{
if
(
isset
(
self
::
$tpl
))
{
return
;
}
self
::
$tpl
=<<<
END
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
%
s
extends
%
s
{
public
function
up
()
{
%
s
}
public
function
down
()
{
%
s
}
}
END
;
}
/**
* generateMigrationsFromDb
*
* @return void
*/
public
function
generateMigrationsFromDb
()
{
$directory
=
'/tmp/tmp_doctrine_models'
;
Doctrine
::
generateModelsFromDb
(
$directory
);
$result
=
$this
->
generateMigrationsFromModels
(
$directory
);
exec
(
'rm -rf '
.
$directory
);
return
$result
;
}
/**
* generateMigrationsFromModels
*
* @param string $modelsPath
* @return void
*/
public
function
generateMigrationsFromModels
(
$modelsPath
=
null
)
{
if
(
$modelsPath
)
{
$models
=
Doctrine
::
loadModels
(
$modelsPath
);
}
else
{
$models
=
Doctrine
::
getLoadedModels
();
}
$foreignKeys
=
array
();
foreach
(
$models
as
$model
)
{
$export
=
Doctrine
::
getTable
(
$model
)
->
getExportableFormat
();
$foreignKeys
[
$export
[
'tableName'
]]
=
$export
[
'options'
][
'foreignKeys'
];
$up
=
$this
->
buildCreateTable
(
$export
);
$down
=
$this
->
buildDropTable
(
$export
);
$className
=
'Add'
.
Doctrine
::
classify
(
$export
[
'tableName'
]);
$this
->
generateMigrationClass
(
$className
,
array
(),
$up
,
$down
);
}
$className
=
'ApplyForeignKeyConstraints'
;
$up
=
''
;
$down
=
''
;
foreach
(
$foreignKeys
as
$tableName
=>
$definitions
)
{
$tableForeignKeyNames
[
$tableName
]
=
array
();
foreach
(
$definitions
as
$definition
)
{
$definition
[
'name'
]
=
$tableName
.
'_'
.
$definition
[
'foreignTable'
]
.
'_'
.
$definition
[
'local'
]
.
'_'
.
$definition
[
'foreign'
];
$up
.=
$this
->
buildCreateForeignKey
(
$tableName
,
$definition
);
$down
.=
$this
->
buildDropForeignKey
(
$tableName
,
$definition
);
}
}
$this
->
generateMigrationClass
(
$className
,
array
(),
$up
,
$down
);
}
/**
* buildCreateForeignKey
*
* @param string $tableName
* @param string $definition
* @return void
*/
public
function
buildCreateForeignKey
(
$tableName
,
$definition
)
{
return
"
\t\t\$
this->createForeignKey('"
.
$tableName
.
"', "
.
$this
->
dataToPhpCode
(
$definition
)
.
");"
;
}
/**
* buildDropForeignKey
*
* @param string $tableName
* @param string $definition
* @return void
*/
public
function
buildDropForeignKey
(
$tableName
,
$definition
)
{
return
"
\t\t\$
this->dropForeignKey('"
.
$tableName
.
"', '"
.
$definition
[
'name'
]
.
"');
\n
"
;
}
/**
* buildCreateTable
*
* @param string $tableData
* @return void
*/
public
function
buildCreateTable
(
$tableData
)
{
$code
=
"
\t\t\$
this->createTable('"
.
$tableData
[
'tableName'
]
.
"', "
;
$code
.=
$this
->
dataToPhpCode
(
$tableData
[
'columns'
])
.
", "
;
$code
.=
$this
->
dataToPhpCode
(
array
(
'indexes'
=>
$tableData
[
'options'
][
'indexes'
],
'primary'
=>
$tableData
[
'options'
][
'primary'
]));
$code
.=
");"
;
return
$code
;
}
/**
* buildDropTable
*
* @param string $tableData
* @return void
*/
public
function
buildDropTable
(
$tableData
)
{
return
"
\t\t\$
this->dropTable('"
.
$tableData
[
'tableName'
]
.
"');"
;
}
/**
* dataToPhpCode
*
* @param string $data
* @return void
*/
public
function
dataToPhpCode
(
$data
)
{
ob_start
();
var_export
(
$data
);
$results
=
ob_get_contents
();
ob_end_clean
();
return
$results
;
}
/**
* generateMigrationClass
*
* @package default
*/
public
function
generateMigrationClass
(
$className
,
$options
=
array
(),
$up
=
null
,
$down
=
null
,
$return
=
false
)
{
if
(
$return
||
!
$this
->
getMigrationsPath
())
{
return
$this
->
buildMigrationClass
(
$className
,
null
,
$options
,
$up
,
$down
);
}
else
{
if
(
!
$this
->
getMigrationsPath
())
{
throw
new
Doctrine_Migration_Exception
(
'You must specify the path to your migrations.'
);
}
$migration
=
new
Doctrine_Migration
(
$this
->
getMigrationsPath
());
$next
=
(
string
)
$migration
->
getNextVersion
();
$fileName
=
str_repeat
(
'0'
,
(
3
-
strlen
(
$next
)))
.
$next
.
'_'
.
Doctrine
::
tableize
(
$className
)
.
$this
->
suffix
;
$class
=
$this
->
buildMigrationClass
(
$className
,
$fileName
,
$options
,
$up
,
$down
);
$path
=
$this
->
getMigrationsPath
()
.
DIRECTORY_SEPARATOR
.
$fileName
;
file_put_contents
(
$path
,
$class
);
}
}
/**
* buildMigrationClass
*
* @package default
*/
public
function
buildMigrationClass
(
$className
,
$fileName
=
null
,
$options
=
array
(),
$up
=
null
,
$down
=
null
)
{
$extends
=
isset
(
$options
[
'extends'
])
?
$options
[
'extends'
]
:
'Doctrine_Migration'
;
$content
=
'<?php'
.
PHP_EOL
;
$content
.=
sprintf
(
self
::
$tpl
,
$className
,
$extends
,
$up
,
$down
);
return
$content
;
}
}
\ No newline at end of file
lib/Doctrine/Task.php
View file @
9440cf04
...
...
@@ -99,7 +99,7 @@ abstract class Doctrine_Task
*/
public
function
getArgument
(
$name
,
$default
=
null
)
{
if
(
isset
(
$this
->
arguments
[
$name
])
&&
$this
->
arguments
[
$name
])
{
if
(
isset
(
$this
->
arguments
[
$name
])
&&
$this
->
arguments
[
$name
]
!==
null
)
{
return
$this
->
arguments
[
$name
];
}
else
{
return
$default
;
...
...
lib/Doctrine/Task/GenerateMigrationsFromDb.php
0 → 100644
View file @
9440cf04
<?php
/*
* $Id: GenerateMigrationsFromDb.php 2761 2007-10-07 23:42:29Z zYne $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Task_GenerateMigrationsFromDb
*
* @package Doctrine
* @subpackage Task
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 2761 $
* @author Jonathan H. Wage <jwage@mac.com>
*/
class
Doctrine_Task_GenerateMigrationsFromDb
extends
Doctrine_Task
{
public
$description
=
'Generate migration classes for an existing database'
,
$requiredArguments
=
array
(
'migrations_path'
=>
'Specify the complete path to your migration classes folder.'
),
$optionalArguments
=
array
();
public
function
execute
()
{
Doctrine
::
generateMigrationsFromDb
(
$this
->
getArgument
(
'migrations_path'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/GenerateMigrationsFromModels.php
0 → 100644
View file @
9440cf04
<?php
/*
* $Id: GenerateMigrationsFromModels.php 2761 2007-10-07 23:42:29Z zYne $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Task_GenerateMigrationsFromModels
*
* @package Doctrine
* @subpackage Task
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 2761 $
* @author Jonathan H. Wage <jwage@mac.com>
*/
class
Doctrine_Task_GenerateMigrationsFromModels
extends
Doctrine_Task
{
public
$description
=
'Generate migration classes for an existing set of models'
,
$requiredArguments
=
array
(
'migrations_path'
=>
'Specify the path to your migration classes folder.'
,
'models_path'
=>
'Specify the path to your doctrine models folder.'
),
$optionalArguments
=
array
();
public
function
execute
()
{
Doctrine
::
generateMigrationsFromModels
(
$this
->
getArgument
(
'migrations_path'
),
$this
->
getArgument
(
'models_path'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/Migrate.php
View file @
9440cf04
...
...
@@ -33,11 +33,11 @@
class
Doctrine_Task_Migrate
extends
Doctrine_Task
{
public
$description
=
'Migrate database to latest version or the specified version'
,
$requiredArguments
=
array
(),
$requiredArguments
=
array
(
'migrations_path'
=>
'Specify path to your migrations directory.'
),
$optionalArguments
=
array
(
'version'
=>
'Version to migrate to. If you do not specify, the db will be migrated from the current version to the latest.'
);
public
function
execute
()
{
Doctrine
::
migrate
(
$this
->
getArgument
(
'version'
));
Doctrine
::
migrate
(
$this
->
getArgument
(
'
migrations_path'
),
$this
->
getArgument
(
'
version'
));
}
}
\ No newline at end of file
sandbox/migrations/001_add_adult.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddAdult
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'adult'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
'contact_id'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'adult'
);
}
}
\ No newline at end of file
sandbox/migrations/002_add_car.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddCar
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'car'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'car'
);
}
}
\ No newline at end of file
sandbox/migrations/003_add_child.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddChild
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'child'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
'adult_id'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'child'
);
}
}
\ No newline at end of file
sandbox/migrations/004_add_contact.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddContact
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'contact'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'contact'
);
}
}
\ No newline at end of file
sandbox/migrations/005_add_dog.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddDog
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'dog'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
'user_id'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'dog'
);
}
}
\ No newline at end of file
sandbox/migrations/006_add_entity.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddEntity
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'entity'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'entity'
);
}
}
\ No newline at end of file
sandbox/migrations/007_add_groups.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddGroups
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'groups'
,
array
(
'id'
=>
array
(
'notnull'
=>
true
,
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'groups'
);
}
}
\ No newline at end of file
sandbox/migrations/008_add_self_reference.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddSelfReference
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'self_reference'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
'user_id1'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
'user_id2'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
'parent_self_reference_id'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
'parent_self_reference_id2'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'self_reference'
);
}
}
\ No newline at end of file
sandbox/migrations/009_add_user.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddUser
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'user'
,
array
(
'id'
=>
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'username'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
'hair_color'
=>
array
(
'type'
=>
'string'
,
'length'
=>
255
,
),
'contact_id'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
'name_x'
=>
array
(
'fields'
=>
array
(
'username'
=>
array
(
'sorting'
=>
'ASC'
,
'length'
=>
'11'
,
'primary'
=>
true
,
),
),
'type'
=>
'unique'
,
),
),
'primary'
=>
array
(
0
=>
'id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'user'
);
}
}
\ No newline at end of file
sandbox/migrations/010_add_user_car.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddUserCar
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'user_car'
,
array
(
'user_id'
=>
array
(
'primary'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'car_id'
=>
array
(
'primary'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'user_id'
,
1
=>
'car_id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'user_car'
);
}
}
\ No newline at end of file
sandbox/migrations/011_add_user_group.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
AddUserGroup
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createTable
(
'user_group'
,
array
(
'user_id'
=>
array
(
'primary'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
'group_id'
=>
array
(
'primary'
=>
true
,
'type'
=>
'integer'
,
'length'
=>
11
,
),
),
array
(
'indexes'
=>
array
(
),
'primary'
=>
array
(
0
=>
'user_id'
,
1
=>
'group_id'
,
),
));
}
public
function
down
()
{
$this
->
dropTable
(
'user_group'
);
}
}
\ No newline at end of file
sandbox/migrations/012_apply_foreign_key_constraints.class.php
0 → 100644
View file @
9440cf04
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
ApplyForeignKeyConstraints
extends
Doctrine_Migration
{
public
function
up
()
{
$this
->
createForeignKey
(
'adult'
,
array
(
'local'
=>
'contact_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'contact'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'adult_contact_contact_id_id'
,
));
$this
->
createForeignKey
(
'child'
,
array
(
'local'
=>
'adult_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'adult'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'child_adult_adult_id_id'
,
));
$this
->
createForeignKey
(
'dog'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'user'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'dog_user_user_id_id'
,
));
$this
->
createForeignKey
(
'self_reference'
,
array
(
'local'
=>
'user_id1'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'user'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'self_reference_user_user_id1_id'
,
));
$this
->
createForeignKey
(
'self_reference'
,
array
(
'local'
=>
'user_id2'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'user'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'self_reference_user_user_id2_id'
,
));
$this
->
createForeignKey
(
'self_reference'
,
array
(
'local'
=>
'parent_self_reference_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'self_reference'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'self_reference_self_reference_parent_self_reference_id_id'
,
));
$this
->
createForeignKey
(
'self_reference'
,
array
(
'local'
=>
'parent_self_reference_id2'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'self_reference'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'self_reference_self_reference_parent_self_reference_id2_id'
,
));
$this
->
createForeignKey
(
'user'
,
array
(
'local'
=>
'contact_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'contact'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'user_contact_contact_id_id'
,
));
$this
->
createForeignKey
(
'user_car'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'user'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'user_car_user_user_id_id'
,
));
$this
->
createForeignKey
(
'user_car'
,
array
(
'local'
=>
'car_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'car'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'user_car_car_car_id_id'
,
));
$this
->
createForeignKey
(
'user_group'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'user'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'user_group_user_user_id_id'
,
));
$this
->
createForeignKey
(
'user_group'
,
array
(
'local'
=>
'group_id'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'groups'
,
'onUpdate'
=>
NULL
,
'onDelete'
=>
NULL
,
'name'
=>
'user_group_groups_group_id_id'
,
));
}
public
function
down
()
{
$this
->
dropForeignKey
(
'adult'
,
'adult_contact_contact_id_id'
);
$this
->
dropForeignKey
(
'child'
,
'child_adult_adult_id_id'
);
$this
->
dropForeignKey
(
'dog'
,
'dog_user_user_id_id'
);
$this
->
dropForeignKey
(
'self_reference'
,
'self_reference_user_user_id1_id'
);
$this
->
dropForeignKey
(
'self_reference'
,
'self_reference_user_user_id2_id'
);
$this
->
dropForeignKey
(
'self_reference'
,
'self_reference_self_reference_parent_self_reference_id_id'
);
$this
->
dropForeignKey
(
'self_reference'
,
'self_reference_self_reference_parent_self_reference_id2_id'
);
$this
->
dropForeignKey
(
'user'
,
'user_contact_contact_id_id'
);
$this
->
dropForeignKey
(
'user_car'
,
'user_car_user_user_id_id'
);
$this
->
dropForeignKey
(
'user_car'
,
'user_car_car_car_id_id'
);
$this
->
dropForeignKey
(
'user_group'
,
'user_group_user_user_id_id'
);
$this
->
dropForeignKey
(
'user_group'
,
'user_group_groups_group_id_id'
);
}
}
\ No newline at end of file
sandbox/models/generated/BaseGroup.class.php
View file @
9440cf04
...
...
@@ -8,8 +8,8 @@ abstract class BaseGroup extends Doctrine_Record
public
function
setTableDefinition
()
{
$this
->
setTableName
(
'group'
);
$this
->
hasColumn
(
'id'
,
'integer'
,
4
,
array
(
'notnull'
=>
true
,
$this
->
setTableName
(
'group
s
'
);
$this
->
hasColumn
(
'id'
,
'integer'
,
11
,
array
(
'notnull'
=>
true
,
'primary'
=>
true
,
'autoincrement'
=>
true
));
$this
->
hasColumn
(
'name'
,
'string'
,
255
);
...
...
sandbox/models/generated/BaseUserGroup.class.php
View file @
9440cf04
...
...
@@ -9,8 +9,8 @@ abstract class BaseUserGroup extends Doctrine_Record
public
function
setTableDefinition
()
{
$this
->
setTableName
(
'user_group'
);
$this
->
hasColumn
(
'user_id'
,
'integer'
,
4
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'group_id'
,
'integer'
,
4
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'user_id'
,
'integer'
,
11
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'group_id'
,
'integer'
,
11
,
array
(
'primary'
=>
true
));
...
...
sandbox/sandbox.db
View file @
9440cf04
No preview for this file type
sandbox/schema/group.yml
View file @
9440cf04
---
Group
:
tableName
:
groups
columns
:
id
:
notnull
:
true
primary
:
true
autoincrement
:
true
type
:
integer
length
:
4
length
:
11
name
:
id
name
:
type
:
string
...
...
sandbox/schema/self_reference.yml
View file @
9440cf04
...
...
@@ -3,24 +3,24 @@ SelfReference:
fields
:
id
:
type
:
integer
size
:
11
length
:
11
primary
:
true
autoincrement
:
true
name
:
type
:
string
size
:
255
length
:
255
user_id1
:
type
:
integer
size
:
11
length
:
11
user_id2
:
type
:
integer
size
:
11
length
:
11
parent_self_reference_id
:
type
:
integer
size
:
11
length
:
11
parent_self_reference_id2
:
type
:
integer
size
:
11
length
:
11
relations
:
User1
:
class
:
User
...
...
sandbox/schema/user_group.yml
View file @
9440cf04
...
...
@@ -3,11 +3,11 @@ UserGroup:
columns
:
user_id
:
type
:
integer
length
:
4
length
:
11
primary
:
true
group_id
:
type
:
integer
length
:
4
length
:
11
primary
:
true
relations
:
User
:
-
...
...
tests/ExportTestCase.php
View file @
9440cf04
...
...
@@ -56,7 +56,7 @@ class Doctrine_Export_TestCase extends Doctrine_UnitTestCase
{
$this
->
export
->
dropConstraint
(
'sometable'
,
'relevancy'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'ALTER TABLE sometable DROP CONSTRAINT relevancy'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'ALTER TABLE sometable DROP CONSTRAINT relevancy
_idx
'
);
}
public
function
testCreateIndexExecutesSql
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment