Skip to content

Commit 52637a9

Browse files
committed
DB migration: add indexes for latest and published
1 parent cdd1649 commit 52637a9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

action/migration.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,33 @@ protected function migration19($sqlite)
340340
return $ok;
341341
}
342342

343+
/**
344+
* Executes Migration 20
345+
*
346+
* Adds indexes on "latest" and "published".
347+
* Those fields are not part of (autoindexed) primary key, but are used in many queries.
348+
*
349+
* @param SQLiteDB $sqlite
350+
* @return bool
351+
*/
352+
protected function migration20($sqlite)
353+
{
354+
$ok = true;
355+
356+
/** @noinspection SqlResolve */
357+
$sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND (name LIKE 'data_%' OR name LIKE 'multi_%')";
358+
$tables = $sqlite->queryAll($sql);
359+
360+
foreach ($tables as $row) {
361+
$table = $row['name']; // no escaping needed, it's our own tables
362+
$sql = "CREATE INDEX idx_$table" . "_latest ON $table(latest);";
363+
$ok = $ok && $sqlite->query($sql);
364+
$sql = "CREATE INDEX idx_$table" . "_published ON $table(published);";
365+
$ok = $ok && $sqlite->query($sql);
366+
}
367+
return $ok;
368+
}
369+
343370

344371
/**
345372
* Returns a select statement to fetch Lookup columns in the current schema

db/latest.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19
1+
20

db/update0020.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- this migration is handled in action/migrations.php in migration20()
2+
--
3+
-- it adds indexes on fields that are not automatically indexed (latest, published)

0 commit comments

Comments
 (0)