Merge branch '1-primary-keys-in-ddls'

because I accidentally lost these changes in some weird merges
This commit is contained in:
Joby Elliott 2018-09-25 11:37:45 -06:00
commit 4bddaea0a8
4 changed files with 30 additions and 6 deletions

View file

@ -52,10 +52,19 @@ class MySQLDriver extends AbstractDriver
$lines = []; $lines = [];
$lines[] = "`json_data` JSON DEFAULT NULL"; $lines[] = "`json_data` JSON DEFAULT NULL";
foreach ($args['virtualColumns'] as $path => $col) { 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) { 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"; $lines[] = "UNIQUE KEY `{$args['table']}_{$col['name']}_idx` (`{$col['name']}`) USING $as";
} elseif ($as = @$col['index']) { } elseif ($as = @$col['index']) {
$lines[] = "KEY `{$args['table']}_{$col['name']}_idx` (`{$col['name']}`) USING $as"; $lines[] = "KEY `{$args['table']}_{$col['name']}_idx` (`{$col['name']}`) USING $as";

View file

@ -36,7 +36,8 @@ class Factory implements DSOFactoryInterface
'name'=>'dso_id', 'name'=>'dso_id',
'type'=>'VARCHAR(16)', 'type'=>'VARCHAR(16)',
'index' => 'BTREE', 'index' => 'BTREE',
'unique' => true 'unique' => true,
'primary' => true
], ],
'dso.type' => [ 'dso.type' => [
'name'=>'dso_type', 'name'=>'dso_type',
@ -57,7 +58,8 @@ class Factory implements DSOFactoryInterface
'name'=>'dso_id', 'name'=>'dso_id',
'type'=>'VARCHAR(16)', 'type'=>'VARCHAR(16)',
'index' => 'BTREE', 'index' => 'BTREE',
'unique' => true 'unique' => true,
'primary' => true
], ],
'dso.type' => [ 'dso.type' => [
'name'=>'dso_type', 'name'=>'dso_type',
@ -265,4 +267,9 @@ class Factory implements DSOFactoryInterface
} while ($check->hasProfanity($id)); } while ($check->hasProfanity($id));
return $id; return $id;
} }
public function errorInfo()
{
return $this->driver->errorInfo();
}
} }

View file

@ -74,7 +74,11 @@ class SQLiteDriver extends AbstractLegacyDriver
$lines = []; $lines = [];
$lines[] = "`json_data` TEXT DEFAULT NULL"; $lines[] = "`json_data` TEXT DEFAULT NULL";
foreach (Factory::CORE_VIRTUAL_COLUMNS as $path => $col) { 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[] = implode(','.PHP_EOL, $lines);
$out[] = ");"; $out[] = ");";

View file

@ -23,7 +23,11 @@ abstract class AbstractDriverIntegrationTest extends TestCase
{ {
$factory = $this->createFactory(); $factory = $this->createFactory();
//should work the first time //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 //but not the second time, because it already exists
$this->assertFalse($factory->createTable()); $this->assertFalse($factory->createTable());
//table should exist and have zero rows //table should exist and have zero rows