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
3fc19008
Commit
3fc19008
authored
Jun 10, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #521 from sergon/migrate_command_primary_key
Migrate command primary key
parents
22053cdc
9268e7d3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
+32
-3
Command.php
framework/yii/db/Command.php
+2
-2
Migration.php
framework/yii/db/Migration.php
+29
-0
QueryBuilder.php
framework/yii/db/QueryBuilder.php
+1
-1
No files found.
framework/yii/db/Command.php
View file @
3fc19008
...
...
@@ -673,9 +673,9 @@ class Command extends \yii\base\Component
* @param string $table the table that the primary key constraint will be removed from.
* @return Command the command object itself
*/
public
function
dropPrimary
k
ey
(
$name
,
$table
)
public
function
dropPrimary
K
ey
(
$name
,
$table
)
{
$sql
=
$this
->
db
->
getQueryBuilder
()
->
dropPrimary
k
ey
(
$name
,
$table
);
$sql
=
$this
->
db
->
getQueryBuilder
()
->
dropPrimary
K
ey
(
$name
,
$table
);
return
$this
->
setSql
(
$sql
);
}
...
...
framework/yii/db/Migration.php
View file @
3fc19008
...
...
@@ -310,6 +310,35 @@ class Migration extends \yii\base\Component
}
/**
* Builds and executes a SQL statement for creating a primary key.
* The method will properly quote the table and column names.
* @param string $name the name of the primary key constraint.
* @param string $table the table that the primary key constraint will be added to.
* @param string|array $columns comma separated string or array of columns that the primary key will consist of.
*/
public
function
addPrimaryKey
(
$name
,
$table
,
$columns
)
{
echo
" > add primary key
$name
on
$table
("
.
(
is_array
(
$columns
)
?
implode
(
','
,
$columns
)
:
$columns
)
.
") ..."
;
$time
=
microtime
(
true
);
$this
->
db
->
createCommand
()
->
addPrimaryKey
(
$name
,
$table
,
$columns
)
->
execute
();
echo
" done (time: "
.
sprintf
(
'%.3f'
,
microtime
(
true
)
-
$time
)
.
"s)
\n
"
;
}
/**
* Builds and executes a SQL statement for dropping a primary key.
* @param string $name the name of the primary key constraint to be removed.
* @param string $table the table that the primary key constraint will be removed from.
* @return Command the command object itself
*/
public
function
dropPrimaryKey
(
$name
,
$table
)
{
echo
" > drop primary key
$name
..."
;
$time
=
microtime
(
true
);
$this
->
db
->
createCommand
()
->
dropPrimaryKey
(
$name
,
$table
)
->
execute
();
echo
" done (time: "
.
sprintf
(
'%.3f'
,
microtime
(
true
)
-
$time
)
.
"s)
\n
"
;
}
/**
* Builds a SQL statement for adding a foreign key constraint to an existing table.
* The method will properly quote the table and column names.
* @param string $name the name of the foreign key constraint.
...
...
framework/yii/db/QueryBuilder.php
View file @
3fc19008
...
...
@@ -297,7 +297,7 @@ class QueryBuilder extends \yii\base\Object
* @param string $table the table that the primary key constraint will be removed from.
* @return string the SQL statement for removing a primary key constraint from an existing table. *
*/
public
function
dropPrimary
k
ey
(
$name
,
$table
)
public
function
dropPrimary
K
ey
(
$name
,
$table
)
{
return
'ALTER TABLE '
.
$this
->
db
->
quoteTableName
(
$table
)
.
' DROP CONSTRAINT '
.
$this
->
db
->
quoteColumnName
(
$name
);
...
...
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