Skip to content

Commit c56f4f6

Browse files
authored
Make sure this works for mssql. (#408)
* Make sure this works for mssql. * Make sure this works for mssql.
1 parent ea037ff commit c56f4f6

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

config/Migrations/20231112807150_MigrationAddIndex.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Cake\Datasource\ConnectionManager;
34
use Phinx\Migration\AbstractMigration;
45

56
class MigrationAddIndex extends AbstractMigration {
@@ -9,11 +10,21 @@ class MigrationAddIndex extends AbstractMigration {
910
*/
1011
public function change() {
1112
// Shim: make sure this is void when a migrating with `202311128071500` instead of `20231112807150` has been run already.
12-
$result = $this->query('SELECT * FROM queue_phinxlog WHERE version = \'202311128071500\' LIMIT 1')->fetch();
13-
if ($result) {
14-
$this->execute('DELETE FROM queue_phinxlog WHERE version = \'202311128071500\' LIMIT 1');
13+
$version = '202311128071500';
14+
if (ConnectionManager::getConfig('default')['driver'] === 'Cake\Database\Driver\Sqlserver') {
15+
$result = $this->query('SELECT TOP(1) * FROM queue_phinxlog WHERE version = \'' . $version . '\'')->fetch();
16+
if ($result) {
17+
$this->execute('DELETE TOP(1) FROM queue_phinxlog WHERE version = \'' . $version . '\'');
1518

16-
return;
19+
return;
20+
}
21+
} else {
22+
$result = $this->query('SELECT * FROM queue_phinxlog WHERE version = \'' . $version . '\' LIMIT 1')->fetch();
23+
if ($result) {
24+
$this->execute('DELETE FROM queue_phinxlog WHERE version = \'' . $version . '\' LIMIT 1');
25+
26+
return;
27+
}
1728
}
1829

1930
$table = $this->table('queued_jobs');

0 commit comments

Comments
 (0)