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
900c0161
Commit
900c0161
authored
Sep 18, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial entry.
parent
8185e1f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
359 additions
and
0 deletions
+359
-0
Migration.php
lib/Doctrine/Migration.php
+169
-0
Exception.php
lib/Doctrine/Migration/Exception.php
+34
-0
IrreversibleMigration.php
lib/Doctrine/Migration/IrreversibleMigration.php
+34
-0
Process.php
lib/Doctrine/Migration/Process.php
+122
-0
No files found.
lib/Doctrine/Migration.php
0 → 100644
View file @
900c0161
<?php
/*
* $Id: Migration.php 1080 2007-02-10 18:17:08Z jwage $
*
* 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
*
* this class represents a database view
*
* @author Jonathan H. Wage <jwage@mac.com>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
*/
class
Doctrine_Migration
{
public
$changes
=
array
(
'created_tables'
=>
array
(),
'dropped_tables'
=>
array
(),
'renamed_tables'
=>
array
(),
'added_columns'
=>
array
(),
'renamed_columns'
=>
array
(),
'changed_columns'
=>
array
(),
'removed_columns'
=>
array
(),
'added_indexes'
=>
array
(),
'removed_indexes'
=>
array
());
static
public
function
migration
(
$directory
,
$from
,
$to
)
{
if
(
$from
===
$to
OR
$from
===
0
)
{
throw
new
Doctrine_Migration_Exception
(
'You specified an invalid migration path. The from and to cannot be the same and from cannot be zero.'
);
}
$direction
=
$from
>
$to
?
'down'
:
'up'
;
$fromPath
=
$directory
.
DIRECTORY_SEPARATOR
;
$toPath
=
$directory
.
DIRECTORY_SEPARATOR
;
if
(
$direction
===
'up'
)
{
for
(
$i
=
$from
+
1
;
$i
<=
$to
;
$i
++
)
{
self
::
doDirectionStep
(
$directory
,
$direction
,
$i
);
}
}
else
{
for
(
$i
=
$from
;
$i
>
$to
;
$i
--
)
{
self
::
doDirectionStep
(
$directory
,
$direction
,
$i
);
}
}
}
public
static
function
doDirectionStep
(
$directory
,
$direction
,
$num
)
{
$className
=
'Migration'
.
$num
;
$fileName
=
$className
.
'.class.php'
;
$filePath
=
$directory
.
DIRECTORY_SEPARATOR
.
$fileName
;
if
(
file_exists
(
$filePath
))
{
require_once
(
$filePath
);
if
(
class_exists
(
$className
))
{
$migrate
=
new
$className
();
$migrate
->
migrate
(
$direction
);
}
}
}
public
function
migrate
(
$direction
)
{
if
(
method_exists
(
$this
,
$direction
))
{
$this
->
$direction
();
$this
->
processChanges
();
}
}
public
function
processChanges
()
{
foreach
(
$this
->
changes
as
$type
=>
$changes
)
{
$process
=
new
Doctrine_Migration_Process
();
$funcName
=
'process'
.
Doctrine
::
classify
(
$type
);
$process
->
$funcName
(
$changes
);
}
}
public
function
addChange
(
$type
,
array
$change
=
array
())
{
$this
->
changes
[
$type
][]
=
$change
;
}
public
function
createTable
(
$tableName
,
array
$fields
=
array
(),
array
$options
=
array
())
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'created_tables'
,
$options
);
}
public
function
dropTable
(
$tableName
)
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'dropped_tables'
,
$options
);
}
public
function
renameTable
(
$oldTableName
,
$newTableName
)
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'renamed_tables'
,
$options
);
}
public
function
addColumn
(
$tableName
,
$columnName
,
$type
,
$options
=
array
())
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'added_columns'
,
$options
);
}
public
function
renameColumn
(
$tableName
,
$oldColumnName
,
$newColumnName
)
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'renamed_columns'
,
$options
);
}
public
function
changeColumn
(
$tableName
,
$columnName
,
$type
,
array
$options
=
array
())
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'changed_columns'
,
$options
);
}
public
function
removeColumn
(
$tableName
,
$columnName
)
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'removed_columns'
,
$options
);
}
public
function
addIndex
(
$tableName
,
$indexName
,
array
$options
=
array
())
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'added_indexes'
,
$options
);
}
public
function
removeIndex
(
$tableName
,
$indexName
)
{
$options
=
get_defined_vars
();
$this
->
addChange
(
'removed_indexes'
,
$options
);
}
}
\ No newline at end of file
lib/Doctrine/Migration/Exception.php
0 → 100644
View file @
900c0161
<?php
/*
* $Id: Exception.php 1080 2007-02-10 18:17:08Z jwage $
*
* 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_Exception
*
* @author Jonathan H. Wage <jwage@mac.com>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
*/
class
Doctrine_Migration_Exception
extends
Doctrine_Exception
{
}
\ No newline at end of file
lib/Doctrine/Migration/IrreversibleMigration.php
0 → 100644
View file @
900c0161
<?php
/*
* $Id: IrreversibleMigration.php 1080 2007-02-10 18:17:08Z jwage $
*
* 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_IrreversibleMigration
*
* @author Jonathan H. Wage <jwage@mac.com>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
*/
class
Doctrine_Migration_IrreversibleMigration
extends
Doctrine_Migration_Exception
{
}
\ No newline at end of file
lib/Doctrine/Migration/Process.php
0 → 100644
View file @
900c0161
<?php
/*
* $Id: Process.php 1080 2007-02-10 18:17:08Z jwage $
*
* 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_Process
*
* @author Jonathan H. Wage <jwage@mac.com>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
*/
class
Doctrine_Migration_Process
{
public
function
processCreatedTables
(
$tables
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$tables
as
$table
)
{
$conn
->
export
->
createTable
(
$table
[
'tableName'
],
$table
[
'fields'
],
$table
[
'options'
]);
}
}
public
function
processDroppedTables
(
$tables
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$tables
as
$table
)
{
$conn
->
export
->
dropTable
(
$table
[
'tableName'
]);
}
}
public
function
processRenamedTables
(
$tables
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$tables
as
$table
)
{
$conn
->
export
->
alterTable
(
$table
[
'oldTableName'
],
array
(
'name'
=>
$table
[
'newTableName'
]),
true
);
}
}
public
function
processAddedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$options
=
array
();
$options
=
$column
[
'options'
];
$options
[
'type'
]
=
$column
[
'type'
];
$conn
->
export
->
alterTable
(
$column
[
'tableName'
],
array
(
'add'
=>
array
(
$column
[
'columnName'
]
=>
$options
)),
true
);
}
}
public
function
processRenamedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$conn
->
export
->
alterTable
(
$column
[
'tableName'
],
array
(
'rename'
=>
array
(
$column
[
'oldColumnName'
]
=>
array
(
'name'
=>
$column
[
'newColumnName'
]))),
true
);
}
}
public
function
processChangedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$options
=
array
();
$options
=
$column
[
'options'
];
$options
[
'type'
]
=
$column
[
'type'
];
$conn
->
export
->
alterTable
(
$column
[
'tableName'
],
array
(
'change'
=>
array
(
$column
[
'oldColumnName'
]
=>
array
(
'definition'
=>
$options
))),
true
);
}
}
public
function
processRemovedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$conn
->
export
->
alterTable
(
$column
[
'tableName'
],
array
(
'remove'
=>
array
(
$column
[
'columnName'
]
=>
array
())));
}
}
public
function
processAddedIndexes
(
$indexes
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$indexes
as
$index
)
{
$conn
->
export
->
createIndex
(
$index
[
'tableName'
],
$index
[
'indexName'
],
$index
[
'definition'
]);
}
}
public
function
processRemovedIndexes
(
$indexes
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$indexes
as
$index
)
{
$conn
->
export
->
dropIndex
(
$index
[
'tableName'
],
$index
[
'indexName'
]);
}
}
}
\ No newline at end of file
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