Skip to content
Snippets Groups Projects
Unverified Commit b340058e authored by Thomas Flori's avatar Thomas Flori
Browse files

change migrations table to use snake case instead of camel case

Camel case is not supported by some database. Postgres for example
returns every column name in lower case. That does not lead to errors
but even more dangerous it jus silently fails when you try to access
`Migration::$executionTime`.
parent 68acee7a
No related branches found
No related tags found
No related merge requests found
...@@ -16,12 +16,12 @@ class CreateMigrationTable extends AbstractMigration ...@@ -16,12 +16,12 @@ class CreateMigrationTable extends AbstractMigration
reverted TIMESTAMP, reverted TIMESTAMP,
status CHARACTER VARYING (16) NOT NULL DEFAULT 'done', status CHARACTER VARYING (16) NOT NULL DEFAULT 'done',
statements TEXT, statements TEXT,
executionTime DOUBLE PRECISION, execution_time DOUBLE PRECISION,
PRIMARY KEY (file) PRIMARY KEY (file)
)"); )");
$this->exec("CREATE INDEX {$table}_executed_index ON {$table} (executed)"); $this->exec("CREATE INDEX {$table}_executed_index ON {$table} (executed)");
$this->exec("CREATE INDEX {$table}_status_index ON {$table} (status)"); $this->exec("CREATE INDEX {$table}_status_index ON {$table} (status)");
$this->exec("CREATE INDEX {$table}_executionTime_index ON {$table} (executionTime)"); $this->exec("CREATE INDEX {$table}_execution_time_index ON {$table} (execution_time)");
} }
/** @codeCoverageIgnore */ /** @codeCoverageIgnore */
......
...@@ -283,7 +283,7 @@ class Migrations ...@@ -283,7 +283,7 @@ class Migrations
foreach ($migrations as $migration) { foreach ($migrations as $migration) {
$this->progress->beforeMigration($migration); $this->progress->beforeMigration($migration);
$this->statements = $migration->statements; $this->statements = $migration->statements;
$start = microtime(true) - $migration->executionTime; $start = microtime(true) - $migration->execution_time;
try { try {
$this->db->beginTransaction(); $this->db->beginTransaction();
$class = self::internalClass($migration->file) ?? $class = self::internalClass($migration->file) ??
...@@ -367,7 +367,7 @@ class Migrations ...@@ -367,7 +367,7 @@ class Migrations
$migration->statements = $this->statements; $migration->statements = $this->statements;
$migration->status = $status; $migration->status = $status;
$migration->executionTime = $executionTime; $migration->execution_time = $executionTime;
if (!$exists) { if (!$exists) {
$this->db->prepare("INSERT INTO {$table} $this->db->prepare("INSERT INTO {$table}
...@@ -378,7 +378,7 @@ class Migrations ...@@ -378,7 +378,7 @@ class Migrations
$migration->executed->format('c'), $migration->executed->format('c'),
$migration->status, $migration->status,
json_encode($migration->statements), json_encode($migration->statements),
$migration->executionTime $migration->execution_time
]); ]);
} else { } else {
$this->db->prepare("UPDATE {$table} SET $this->db->prepare("UPDATE {$table} SET
...@@ -389,7 +389,7 @@ class Migrations ...@@ -389,7 +389,7 @@ class Migrations
$migration->reverted ? $migration->reverted->format('c') : null, $migration->reverted ? $migration->reverted->format('c') : null,
$migration->status, $migration->status,
json_encode($migration->statements), json_encode($migration->statements),
$migration->executionTime, $migration->execution_time,
$migration->file $migration->file
]); ]);
} }
......
...@@ -23,7 +23,7 @@ class Migration ...@@ -23,7 +23,7 @@ class Migration
public $statements = []; public $statements = [];
/** @var double */ /** @var double */
public $executionTime; public $execution_time;
public function __construct() public function __construct()
{ {
......
...@@ -35,7 +35,7 @@ class CreateMigrationTableTest extends TestCase ...@@ -35,7 +35,7 @@ class CreateMigrationTableTest extends TestCase
->with(m::pattern('/create index.* on migrations\s*\(\s*status\s*\)/i')) ->with(m::pattern('/create index.* on migrations\s*\(\s*status\s*\)/i'))
->once(); ->once();
$adapter->shouldHaveReceived('exec') $adapter->shouldHaveReceived('exec')
->with(m::pattern('/create index.* on migrations\s*\(\s*executionTime\s*\)/i')) ->with(m::pattern('/create index.* on migrations\s*\(\s*execution_time\s*\)/i'))
->once(); ->once();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment