Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
6a51c1bc
Unverified
Commit
6a51c1bc
authored
7 years ago
by
Piotr Mrowczynski
Committed by
Joas Schilling
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add foreign key support to OC
parent
d081a1a5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/private/DB/OracleMigrator.php
+36
-4
36 additions, 4 deletions
lib/private/DB/OracleMigrator.php
tests/lib/DB/MigratorTest.php
+37
-2
37 additions, 2 deletions
tests/lib/DB/MigratorTest.php
with
73 additions
and
6 deletions
lib/private/DB/OracleMigrator.php
+
36
−
4
View file @
6a51c1bc
...
...
@@ -30,6 +30,7 @@ use Doctrine\DBAL\Schema\ColumnDiff;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
class
OracleMigrator
extends
NoCheckMigrator
{
...
...
@@ -81,6 +82,27 @@ class OracleMigrator extends NoCheckMigrator {
);
}
/**
* Quote an ForeignKeyConstraint's name but changing the name requires recreating
* the ForeignKeyConstraint instance and copying over all properties.
*
* @param ForeignKeyConstraint $fkc old fkc
* @return ForeignKeyConstraint new fkc instance with new name
*/
protected
function
quoteForeignKeyConstraint
(
$fkc
)
{
return
new
ForeignKeyConstraint
(
array_map
(
function
(
$columnName
)
{
return
$this
->
connection
->
quoteIdentifier
(
$columnName
);
},
$fkc
->
getLocalColumns
()),
$this
->
connection
->
quoteIdentifier
(
$fkc
->
getForeignTableName
()),
array_map
(
function
(
$columnName
)
{
return
$this
->
connection
->
quoteIdentifier
(
$columnName
);
},
$fkc
->
getForeignColumns
()),
$fkc
->
getName
(),
$fkc
->
getOptions
()
);
}
/**
* @param Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
...
...
@@ -100,7 +122,9 @@ class OracleMigrator extends NoCheckMigrator {
array_map
(
function
(
Index
$index
)
{
return
$this
->
quoteIndex
(
$index
);
},
$table
->
getIndexes
()),
$table
->
getForeignKeys
(),
array_map
(
function
(
ForeignKeyConstraint
$fck
)
{
return
$this
->
quoteForeignKeyConstraint
(
$fck
);
},
$table
->
getForeignKeys
()),
0
,
$table
->
getOptions
()
);
...
...
@@ -158,9 +182,17 @@ class OracleMigrator extends NoCheckMigrator {
return
$this
->
quoteIndex
(
$index
);
},
$tableDiff
->
renamedIndexes
);
// TODO handle $tableDiff->addedForeignKeys
// TODO handle $tableDiff->changedForeignKeys
// TODO handle $tableDiff->removedForeignKeys
$tableDiff
->
addedForeignKeys
=
array_map
(
function
(
ForeignKeyConstraint
$fkc
)
{
return
$this
->
quoteForeignKeyConstraint
(
$fkc
);
},
$tableDiff
->
addedForeignKeys
);
$tableDiff
->
changedForeignKeys
=
array_map
(
function
(
ForeignKeyConstraint
$fkc
)
{
return
$this
->
quoteForeignKeyConstraint
(
$fkc
);
},
$tableDiff
->
changedForeignKeys
);
$tableDiff
->
removedForeignKeys
=
array_map
(
function
(
ForeignKeyConstraint
$fkc
)
{
return
$this
->
quoteForeignKeyConstraint
(
$fkc
);
},
$tableDiff
->
removedForeignKeys
);
}
return
$schemaDiff
;
...
...
This diff is collapsed.
Click to expand it.
tests/lib/DB/MigratorTest.php
+
37
−
2
View file @
6a51c1bc
...
...
@@ -41,6 +41,9 @@ class MigratorTest extends \Test\TestCase {
/** @var string */
private
$tableName
;
/** @var string */
private
$tableNameTmp
;
protected
function
setUp
()
{
parent
::
setUp
();
...
...
@@ -50,11 +53,23 @@ class MigratorTest extends \Test\TestCase {
$this
->
markTestSkipped
(
'DB migration tests are not supported on OCI'
);
}
$this
->
manager
=
new
\OC\DB\MDB2SchemaManager
(
$this
->
connection
);
$this
->
tableName
=
strtolower
(
$this
->
getUniqueID
(
$this
->
config
->
getSystemValue
(
'dbtableprefix'
,
'oc_'
)
.
'test_'
));
$this
->
tableName
=
$this
->
getUniqueTableName
();
$this
->
tableNameTmp
=
$this
->
getUniqueTableName
();
}
private
function
getUniqueTableName
()
{
return
strtolower
(
$this
->
getUniqueID
(
$this
->
config
->
getSystemValue
(
'dbtableprefix'
,
'oc_'
)
.
'test_'
));
}
protected
function
tearDown
()
{
$this
->
connection
->
exec
(
'DROP TABLE '
.
$this
->
tableName
);
// Try to delete if exists (IF EXISTS NOT SUPPORTED IN ORACLE)
try
{
$this
->
connection
->
exec
(
'DROP TABLE '
.
$this
->
connection
->
quoteIdentifier
(
$this
->
tableNameTmp
));
}
catch
(
\Doctrine\DBAL\DBALException
$e
)
{}
try
{
$this
->
connection
->
exec
(
'DROP TABLE '
.
$this
->
connection
->
quoteIdentifier
(
$this
->
tableName
));
}
catch
(
\Doctrine\DBAL\DBALException
$e
)
{}
parent
::
tearDown
();
}
...
...
@@ -200,4 +215,24 @@ class MigratorTest extends \Test\TestCase {
$this
->
assertTrue
(
true
);
}
public
function
testAddingForeignKey
()
{
$startSchema
=
new
Schema
([],
[],
$this
->
getSchemaConfig
());
$table
=
$startSchema
->
createTable
(
$this
->
tableName
);
$table
->
addColumn
(
'id'
,
'integer'
,
[
'autoincrement'
=>
true
]);
$table
->
addColumn
(
'name'
,
'string'
);
$table
->
setPrimaryKey
([
'id'
]);
$fkName
=
"fkc"
;
$tableFk
=
$startSchema
->
createTable
(
$this
->
tableNameTmp
);
$tableFk
->
addColumn
(
'fk_id'
,
'integer'
);
$tableFk
->
addColumn
(
'name'
,
'string'
);
$tableFk
->
addForeignKeyConstraint
(
$this
->
tableName
,
array
(
'fk_id'
),
array
(
'id'
),
array
(),
$fkName
);
$migrator
=
$this
->
manager
->
getMigrator
();
$migrator
->
migrate
(
$startSchema
);
$this
->
assertTrue
(
$startSchema
->
getTable
(
$this
->
tableNameTmp
)
->
hasForeignKey
(
$fkName
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment