NAME

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

VERSION

version 0.900007

DESCRIPTION

Index-level diff operations for DB2. DB2 supports CREATE INDEX and DROP INDEX. Changed index definitions become a drop-then-create pair. Index names must be unique within a schema.

new, action and summary_prefix come from DBIO::Diff::Op.

METHODS

diff

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

Compares index sets across all tables. Index identity is by name; changed definitions produce a drop-then-create pair. An index with origin => 'pk' (the one behind the primary key, which the model holds, see DBIO::DB2::Introspect::Indexes) is the primary key and never an operation, on either side: not a CREATE INDEX when only the target has one, not a DROP INDEX when only the source does. ADR 0011.

The optional $source_tables / $target_tables hashrefs are the tables sections of the two models (threaded in by DBIO::DB2::Diff). They are used to detect tables being dropped in this same diff pass: DB2's DROP TABLE already removes that table's own indexes, so emitting a standalone DROP INDEX for one of them would fail (the index is already gone) 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.

The optional last argument $source_columns (the columns section of the source model) tells which columns this pass drops: Db2 drops an index with a column it covers, so no DROP INDEX is written for such an index.

The optional $target_columns and $target_unique_constraints (the columns and unique_constraints sections of the target model) let the diff know what already covers a column sequence. Db2 makes no index over columns that the primary key, a UNIQUE constraint or another index already has in the same order -- SQL0605W, nothing created -- so no CREATE INDEX is emitted for one (a unique index is a duplicate only of a unique cover; see "_index_is_duplicate" in DBIO::DB2::DDL), and the follow-up diff stays empty. A DROP INDEX that frees a column sequence a created index takes over (a rename) is moved in front of the creates, where the server would otherwise refuse the create. ADR 0010.

as_sql

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.