NAME

DBIO::SQLite::Diff::Index - Diff operations for SQLite indexes

VERSION

version 0.900007

DESCRIPTION

Represents an index-level diff operation: CREATE INDEX or DROP INDEX. SQLite has no ALTER INDEX, so changed definitions become a drop-then-create pair.

Auto-generated indexes (origin u for UNIQUE constraints, pk for primary keys) are skipped -- they belong to the table itself, not to explicit CREATE INDEX statements.

What counts as a changed index

An index has changed when its uniqueness or its columns differ, and -- for the sake of what those two do not show, the WHERE of a partial index and the expressions of an expression index -- when the CREATE INDEX statements of the two sides differ.

The statements are compared as what they say, not as text. How a name is quoted is no difference:

CREATE INDEX idx_name ON item (name) WHERE active = 1
CREATE INDEX "idx_name" ON "item" ("name") WHERE active = 1

are one index. DBIO::SQLite::DDL wrote the first until it began to quote every name, so a database deployed before that holds the first and the target of an upgrade the second; compared as text, every explicit index of every such database would be dropped and created again, once, for nothing.

What is read that way are the names at the places where the statement can only have a name: the index, the table, and an entry of the column list that is one name and nothing else. There x, "x", `x` and [x] are the same. Whitespace and comments between any two tokens are no difference either.

The letter case of a name is compared as it is written. Everything else has to be the same, token for token: an entry of the list that is an expression or carries COLLATE, ASC or DESC, and the whole of the WHERE. That is the SQL a schema gives as expression and where (DBIO::SQLite::Result), which DBIO::SQLite::DDL writes as given, so it comes back the same from an unchanged schema -- and a change in it is a change of the index, WHERE active = 1 against WHERE "active" = 1 included: there a quoted word and a bare one need not mean the same ("null" is a column, null is not). A string in apostrophes is never read as a name. A statement that does not begin as a CREATE INDEX is compared with only its whitespace set aside.

ATTRIBUTES

replaced

True on the drop of a changed index: the index is not removed, the create that follows puts it back with its new definition. "classify" in DBIO::Diff::Base counts such a drop as changing, not destructive. It changes neither the SQL nor the order of the operations.

METHODS

diff

my @ops = DBIO::SQLite::Diff::Index->diff(
  $source, $target, $source_tables, $target_tables);

$source and $target are the indexes sub-models from DBIO::SQLite::Introspect: { $table_name => { $idx_name => $info } }.

The optional $source_tables / $target_tables hashrefs are the tables sections of the two models (threaded in by DBIO::SQLite::Diff). They are used to detect tables that are being dropped in this same diff pass: SQLite's DROP TABLE automatically removes that table's own indexes, so emitting a later standalone DROP INDEX for one of them would fail with no such index and abort the deploy. When these arguments are absent (e.g. direct unit-test calls) the dropped set is empty and no drops are suppressed, preserving the original two-argument behaviour.

Which indexes come out as changed is described under "What counts as a changed index".

as_sql

Returns CREATE INDEX (preferring the original sql from sqlite_master if available) or DROP INDEX. A statement the op writes itself has every name quoted ("quote_identifier" in DBIO::SQLite::Util): DROP INDEX "idx_name";.

summary

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.