Merge branch '1-primary-keys-in-ddls'
because I accidentally lost these changes in some weird merges
This commit is contained in:
commit
4bddaea0a8
4 changed files with 30 additions and 6 deletions
|
@ -52,10 +52,19 @@ class MySQLDriver extends AbstractDriver
|
|||
$lines = [];
|
||||
$lines[] = "`json_data` JSON DEFAULT NULL";
|
||||
foreach ($args['virtualColumns'] as $path => $col) {
|
||||
$lines[] = "`{$col['name']}` {$col['type']} GENERATED ALWAYS AS (".$this->expandPath($path).") VIRTUAL";
|
||||
$line = "`{$col['name']}` {$col['type']} GENERATED ALWAYS AS (".$this->expandPath($path).")";
|
||||
if (@$col['primary']) {
|
||||
//this needs to be "PERSISTENT" for MariaDB -- I guess there are going to be two drivers now
|
||||
$line .= ' STORED';
|
||||
} else {
|
||||
$line .= ' VIRTUAL';
|
||||
}
|
||||
$lines[] = $line;
|
||||
}
|
||||
foreach ($args['virtualColumns'] as $path => $col) {
|
||||
if (@$col['unique'] && $as = @$col['index']) {
|
||||
if (@$col['primary']) {
|
||||
$lines[] = "PRIMARY KEY (`{$col['name']}`)";
|
||||
} elseif (@$col['unique'] && $as = @$col['index']) {
|
||||
$lines[] = "UNIQUE KEY `{$args['table']}_{$col['name']}_idx` (`{$col['name']}`) USING $as";
|
||||
} elseif ($as = @$col['index']) {
|
||||
$lines[] = "KEY `{$args['table']}_{$col['name']}_idx` (`{$col['name']}`) USING $as";
|
||||
|
|
|
@ -36,7 +36,8 @@ class Factory implements DSOFactoryInterface
|
|||
'name'=>'dso_id',
|
||||
'type'=>'VARCHAR(16)',
|
||||
'index' => 'BTREE',
|
||||
'unique' => true
|
||||
'unique' => true,
|
||||
'primary' => true
|
||||
],
|
||||
'dso.type' => [
|
||||
'name'=>'dso_type',
|
||||
|
@ -57,7 +58,8 @@ class Factory implements DSOFactoryInterface
|
|||
'name'=>'dso_id',
|
||||
'type'=>'VARCHAR(16)',
|
||||
'index' => 'BTREE',
|
||||
'unique' => true
|
||||
'unique' => true,
|
||||
'primary' => true
|
||||
],
|
||||
'dso.type' => [
|
||||
'name'=>'dso_type',
|
||||
|
@ -265,4 +267,9 @@ class Factory implements DSOFactoryInterface
|
|||
} while ($check->hasProfanity($id));
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function errorInfo()
|
||||
{
|
||||
return $this->driver->errorInfo();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,11 @@ class SQLiteDriver extends AbstractLegacyDriver
|
|||
$lines = [];
|
||||
$lines[] = "`json_data` TEXT DEFAULT NULL";
|
||||
foreach (Factory::CORE_VIRTUAL_COLUMNS as $path => $col) {
|
||||
$lines[] = "`{$col['name']}` {$col['type']}";
|
||||
$line = "`{$col['name']}` {$col['type']}";
|
||||
if (@$col['primary']) {
|
||||
$line .= ' PRIMARY KEY';
|
||||
}
|
||||
$lines[] = $line;
|
||||
}
|
||||
$out[] = implode(','.PHP_EOL, $lines);
|
||||
$out[] = ");";
|
||||
|
|
|
@ -23,7 +23,11 @@ abstract class AbstractDriverIntegrationTest extends TestCase
|
|||
{
|
||||
$factory = $this->createFactory();
|
||||
//should work the first time
|
||||
$this->assertTrue($factory->createTable());
|
||||
$out = $factory->createTable();
|
||||
if (!$out) {
|
||||
var_dump($factory->errorInfo());
|
||||
}
|
||||
$this->assertTrue($out);
|
||||
//but not the second time, because it already exists
|
||||
$this->assertFalse($factory->createTable());
|
||||
//table should exist and have zero rows
|
||||
|
|
Loading…
Reference in a new issue