mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 14:57:23 +08:00
Added table based sequence.
This commit is contained in:
@@ -99,6 +99,14 @@ class Schema extends \yii\db\Schema {
|
|||||||
'xml' => self::TYPE_STRING
|
'xml' => self::TYPE_STRING
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a query builder for the MySQL database.
|
||||||
|
* @return QueryBuilder query builder instance
|
||||||
|
*/
|
||||||
|
public function createQueryBuilder() {
|
||||||
|
return new QueryBuilder($this->db);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the table name and schema name (if any).
|
* Resolves the table name and schema name (if any).
|
||||||
* @param TableSchema $table the table metadata object
|
* @param TableSchema $table the table metadata object
|
||||||
@@ -233,6 +241,12 @@ SQL;
|
|||||||
foreach ($columns as $column) {
|
foreach ($columns as $column) {
|
||||||
$column = $this->loadColumnSchema($column);
|
$column = $this->loadColumnSchema($column);
|
||||||
$table->columns[$column->name] = $column;
|
$table->columns[$column->name] = $column;
|
||||||
|
if ($column->isPrimaryKey === true) {
|
||||||
|
$table->primaryKey[] = $column->name;
|
||||||
|
if ($table->sequenceName === null && preg_match("/nextval\('\w+'(::regclass)?\)/", $column->defaultValue) === 1) {
|
||||||
|
$table->sequenceName = preg_replace(array('/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'), '', $column->defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user