Skip to content

Commit

Permalink
DB migration: add indexes for latest and published
Browse files Browse the repository at this point in the history
  • Loading branch information
annda committed Jan 18, 2024
1 parent cdd1649 commit 52637a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions action/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,33 @@ protected function migration19($sqlite)
return $ok;
}

/**
* Executes Migration 20
*
* Adds indexes on "latest" and "published".
* Those fields are not part of (autoindexed) primary key, but are used in many queries.
*
* @param SQLiteDB $sqlite
* @return bool
*/
protected function migration20($sqlite)
{
$ok = true;

/** @noinspection SqlResolve */
$sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND (name LIKE 'data_%' OR name LIKE 'multi_%')";
$tables = $sqlite->queryAll($sql);

foreach ($tables as $row) {
$table = $row['name']; // no escaping needed, it's our own tables
$sql = "CREATE INDEX idx_$table" . "_latest ON $table(latest);";
$ok = $ok && $sqlite->query($sql);
$sql = "CREATE INDEX idx_$table" . "_published ON $table(published);";
$ok = $ok && $sqlite->query($sql);
}
return $ok;
}


/**
* Returns a select statement to fetch Lookup columns in the current schema
Expand Down
2 changes: 1 addition & 1 deletion db/latest.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19
20
3 changes: 3 additions & 0 deletions db/update0020.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- this migration is handled in action/migrations.php in migration20()
--
-- it adds indexes on fields that are not automatically indexed (latest, published)

0 comments on commit 52637a9

Please sign in to comment.