Commit 5a380360 by Gevik Babakhani

Added table based sequence.

parent cbde22af
...@@ -100,6 +100,14 @@ class Schema extends \yii\db\Schema { ...@@ -100,6 +100,14 @@ class Schema extends \yii\db\Schema {
); );
/** /**
* 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
* @param string $name the table name * @param string $name the table name
...@@ -146,7 +154,7 @@ class Schema extends \yii\db\Schema { ...@@ -146,7 +154,7 @@ class Schema extends \yii\db\Schema {
* @param TableSchema $table the table metadata * @param TableSchema $table the table metadata
*/ */
protected function findConstraints($table) { protected function findConstraints($table) {
try { try {
$constraints = $this->db->createCommand($sql)->queryAll(); $constraints = $this->db->createCommand($sql)->queryAll();
} catch (\Exception $e) { } catch (\Exception $e) {
...@@ -233,6 +241,12 @@ SQL; ...@@ -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;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment