diff --git a/action/migration.php b/action/migration.php index 0679f22..22fe42d 100644 --- a/action/migration.php +++ b/action/migration.php @@ -340,6 +340,33 @@ class action_plugin_struct_migration extends ActionPlugin 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 diff --git a/db/latest.version b/db/latest.version index d6b2404..209e3ef 100644 --- a/db/latest.version +++ b/db/latest.version @@ -1 +1 @@ -19 +20 diff --git a/db/update0020.sql b/db/update0020.sql new file mode 100644 index 0000000..74fe593 --- /dev/null +++ b/db/update0020.sql @@ -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)