NAME

DBIO::SQLite::Introspect - Introspect a SQLite database via sqlite_master and PRAGMAs

VERSION

version 0.900007

DESCRIPTION

DBIO::SQLite::Introspect reads the live state of a SQLite database via sqlite_master and the relevant PRAGMA statements and returns a unified model hashref. It is the source side of the test-deploy-and- compare strategy used by DBIO::SQLite::Deploy.

my $intro = DBIO::SQLite::Introspect->new(dbh => $dbh);
my $model = $intro->model;
# $model->{tables}, $model->{columns}, $model->{indexes},
# $model->{foreign_keys}, $model->{triggers}

The model shape mirrors DBIO::PostgreSQL::Introspect so the same diff/deploy patterns apply, but only covers what SQLite actually has (no schemas, types, functions, RLS).

triggers is a section of this driver, beyond the canonical model of "CANONICAL MODEL" in DBIO::Introspect::Base: the triggers of each table and view, by name, each with its CREATE TRIGGER statement ("fetch" in DBIO::SQLite::Introspect::Triggers). It is an empty hash for a database that has none. Triggers are carried, not compared. DBIO::SQLite::Diff never reports one as added, dropped or changed -- a schema cannot declare a trigger, so the target of an upgrade has none, and comparing would drop every trigger of the live database. The section is there for DBIO::SQLite::Diff::Rebuild, which has to re-create the triggers of the table it rebuilds, and for DBIO::SQLite::Diff::View, which re-creates the INSTEAD OF triggers of a view it replaces.

METHODS

table_columns_info

Overrides "table_columns_info" in DBIO::Introspect::Base for one key: is_nullable.

The base folds primary-key membership into it -- is_pk alone makes a column is_nullable => 0 -- as a statement about DBIO's model, on the grounds that a row identity which can be NULL is not usable in the Row layer (core ADR 0038). On SQLite that statement is not true of the database. A PRIMARY KEY on a rowid table really does store NULL, repeatedly, and the NULLs do not even collide; only the INTEGER PRIMARY KEY rowid alias is exempt, and WITHOUT ROWID tables report notnull = 1 for their key themselves. This introspector reports what the database holds, because what it reports is what DBIO::Generate writes into the regenerated result class and what a redeploy then emits as DDL -- and a NOT NULL derived from a key column full of NULLs produces a table that refuses the rows it was generated from.

Base's escape hatch for exactly this is a driver override of this method, which is what this is. The rule itself lives in "column_is_nullable" in DBIO::SQLite::Util, shared with "_dbh_columns_info_for" in DBIO::SQLite::Storage so the introspect path and the live PRAGMA path cannot disagree about the same column.

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.