Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
PSDI Army
yii2
Commits
164c70ee
Commit
164c70ee
authored
Sep 06, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for composite FK to cubrid
parent
8abeed03
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
2 deletions
+57
-2
Schema.php
framework/yii/db/cubrid/Schema.php
+6
-2
cubrid.sql
tests/unit/data/cubrid.sql
+9
-0
mysql.sql
tests/unit/data/mysql.sql
+9
-0
sqlite.sql
tests/unit/data/sqlite.sql
+9
-0
SchemaTest.php
tests/unit/framework/db/SchemaTest.php
+19
-0
SqliteSchemaTest.php
tests/unit/framework/db/sqlite/SqliteSchemaTest.php
+5
-0
No files found.
framework/yii/db/cubrid/Schema.php
View file @
164c70ee
...
@@ -148,12 +148,16 @@ class Schema extends \yii\db\Schema
...
@@ -148,12 +148,16 @@ class Schema extends \yii\db\Schema
$foreignKeys
=
$this
->
db
->
pdo
->
cubrid_schema
(
\PDO
::
CUBRID_SCH_IMPORTED_KEYS
,
$table
->
name
);
$foreignKeys
=
$this
->
db
->
pdo
->
cubrid_schema
(
\PDO
::
CUBRID_SCH_IMPORTED_KEYS
,
$table
->
name
);
foreach
(
$foreignKeys
as
$key
)
{
foreach
(
$foreignKeys
as
$key
)
{
$table
->
foreignKeys
[]
=
array
(
if
(
isset
(
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]]))
{
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]][
$key
[
'FKCOLUMN_NAME'
]]
=
$key
[
'PKCOLUMN_NAME'
];
}
else
{
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]]
=
array
(
$key
[
'PKTABLE_NAME'
],
$key
[
'PKTABLE_NAME'
],
$key
[
'FKCOLUMN_NAME'
]
=>
$key
[
'PKCOLUMN_NAME'
]
$key
[
'FKCOLUMN_NAME'
]
=>
$key
[
'PKCOLUMN_NAME'
]
// TODO support composite foreign keys
);
);
}
}
}
$table
->
foreignKeys
=
array_values
(
$table
->
foreignKeys
);
return
$table
;
return
$table
;
}
else
{
}
else
{
...
...
tests/unit/data/cubrid.sql
View file @
164c70ee
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
* The database setup in config.php is required to perform then relevant tests:
* The database setup in config.php is required to perform then relevant tests:
*/
*/
DROP
TABLE
IF
EXISTS
tbl_composite_fk
;
DROP
TABLE
IF
EXISTS
tbl_order_item
;
DROP
TABLE
IF
EXISTS
tbl_order_item
;
DROP
TABLE
IF
EXISTS
tbl_item
;
DROP
TABLE
IF
EXISTS
tbl_item
;
DROP
TABLE
IF
EXISTS
tbl_order
;
DROP
TABLE
IF
EXISTS
tbl_order
;
...
@@ -76,6 +77,14 @@ CREATE TABLE `tbl_type` (
...
@@ -76,6 +77,14 @@ CREATE TABLE `tbl_type` (
`bool_col2`
smallint
DEFAULT
1
`bool_col2`
smallint
DEFAULT
1
);
);
CREATE
TABLE
`tbl_composite_fk`
(
`id`
int
(
11
)
NOT
NULL
,
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`tbl_order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
INSERT
INTO
tbl_customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
);
INSERT
INTO
tbl_customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
);
INSERT
INTO
tbl_customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
tbl_customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
tbl_customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
);
INSERT
INTO
tbl_customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
);
...
...
tests/unit/data/mysql.sql
View file @
164c70ee
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
* The database setup in config.php is required to perform then relevant tests:
* The database setup in config.php is required to perform then relevant tests:
*/
*/
DROP
TABLE
IF
EXISTS
tbl_composite_fk
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_order_item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_order_item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_order
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_order
CASCADE
;
...
@@ -62,6 +63,14 @@ CREATE TABLE `tbl_order_item` (
...
@@ -62,6 +63,14 @@ CREATE TABLE `tbl_order_item` (
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`tbl_item`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`tbl_item`
(
`id`
)
ON
DELETE
CASCADE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`tbl_composite_fk`
(
`id`
int
(
11
)
NOT
NULL
,
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`tbl_order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
CREATE
TABLE
`tbl_type`
(
CREATE
TABLE
`tbl_type`
(
`int_col`
int
(
11
)
NOT
NULL
,
`int_col`
int
(
11
)
NOT
NULL
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
...
...
tests/unit/data/sqlite.sql
View file @
164c70ee
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
* The database setup in config.php is required to perform then relevant tests:
* The database setup in config.php is required to perform then relevant tests:
*/
*/
DROP
TABLE
IF
EXISTS
tbl_composite_fk
;
DROP
TABLE
IF
EXISTS
tbl_order_item
;
DROP
TABLE
IF
EXISTS
tbl_order_item
;
DROP
TABLE
IF
EXISTS
tbl_item
;
DROP
TABLE
IF
EXISTS
tbl_item
;
DROP
TABLE
IF
EXISTS
tbl_order
;
DROP
TABLE
IF
EXISTS
tbl_order
;
...
@@ -48,6 +49,14 @@ CREATE TABLE tbl_order_item (
...
@@ -48,6 +49,14 @@ CREATE TABLE tbl_order_item (
PRIMARY
KEY
(
order_id
,
item_id
)
PRIMARY
KEY
(
order_id
,
item_id
)
);
);
CREATE
TABLE
`tbl_composite_fk`
(
`id`
int
(
11
)
NOT
NULL
,
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`tbl_order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
CREATE
TABLE
tbl_type
(
CREATE
TABLE
tbl_type
(
int_col
INTEGER
NOT
NULL
,
int_col
INTEGER
NOT
NULL
,
int_col2
INTEGER
DEFAULT
'1'
,
int_col2
INTEGER
DEFAULT
'1'
,
...
...
tests/unit/framework/db/SchemaTest.php
View file @
164c70ee
...
@@ -56,6 +56,11 @@ class SchemaTest extends DatabaseTestCase
...
@@ -56,6 +56,11 @@ class SchemaTest extends DatabaseTestCase
}
}
}
}
public
function
testGetNonExistingTableSchema
()
{
$this
->
assertNull
(
$this
->
getConnection
()
->
schema
->
getTableSchema
(
'nonexisting_table'
));
}
public
function
testSchemaCache
()
public
function
testSchemaCache
()
{
{
/** @var Schema $schema */
/** @var Schema $schema */
...
@@ -67,4 +72,18 @@ class SchemaTest extends DatabaseTestCase
...
@@ -67,4 +72,18 @@ class SchemaTest extends DatabaseTestCase
$cachedTable
=
$schema
->
getTableSchema
(
'tbl_type'
,
true
);
$cachedTable
=
$schema
->
getTableSchema
(
'tbl_type'
,
true
);
$this
->
assertEquals
(
$noCacheTable
,
$cachedTable
);
$this
->
assertEquals
(
$noCacheTable
,
$cachedTable
);
}
}
public
function
testCompositeFk
()
{
/** @var Schema $schema */
$schema
=
$this
->
getConnection
()
->
schema
;
$table
=
$schema
->
getTableSchema
(
'tbl_composite_fk'
);
$this
->
assertCount
(
1
,
$table
->
foreignKeys
);
$this
->
assertTrue
(
isset
(
$table
->
foreignKeys
[
0
]));
$this
->
assertEquals
(
'tbl_order_item'
,
$table
->
foreignKeys
[
0
][
0
]);
$this
->
assertEquals
(
'order_id'
,
$table
->
foreignKeys
[
0
][
'order_id'
]);
$this
->
assertEquals
(
'item_id'
,
$table
->
foreignKeys
[
0
][
'item_id'
]);
}
}
}
tests/unit/framework/db/sqlite/SqliteSchemaTest.php
View file @
164c70ee
...
@@ -6,4 +6,9 @@ use yiiunit\framework\db\SchemaTest;
...
@@ -6,4 +6,9 @@ use yiiunit\framework\db\SchemaTest;
class
SqliteSchemaTest
extends
SchemaTest
class
SqliteSchemaTest
extends
SchemaTest
{
{
protected
$driverName
=
'sqlite'
;
protected
$driverName
=
'sqlite'
;
public
function
testCompositeFk
()
{
$this
->
markTestSkipped
(
'sqlite does not allow getting enough information about composite FK.'
);
}
}
}
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