NAME
DBIO::SQLite::Diff::View - Diff operations for SQLite views
VERSION
version 0.900007
DESCRIPTION
Represents a view-level diff operation: CREATE VIEW or DROP VIEW.
DBIO::SQLite::Introspect::Tables lists a view under tables, with kind => 'view', and for a long time the diff took it for a table there: DROP TABLE for a view that had gone (SQLite: use DROP VIEW to delete view), ALTER TABLE ... ADD COLUMN for one that selects another column (Cannot add a column to a view), and nothing at all for one whose definition had changed but not its columns. A view is a view: it is created as a view and removed as a view, and no column op, index op or rebuild is ever written for one.
SQLite has no ALTER VIEW, so a changed definition is a drop followed by a create.
What counts as a changed view
Two views of one name are the same view when their CREATE VIEW statements are the same in the form "comparable_statement" in DBIO::SQLite::Util gives them: the view's name is read however it is quoted, whitespace and comments between two tokens are set aside, and everything else -- the column list, the SELECT -- has to be the same token for token, in the letter case it is written in.
So CREATE VIEW v AS SELECT 1, as a database deployed before DBIO::SQLite::DDL quoted every name holds it, is the view the target declares as CREATE VIEW "v" AS SELECT 1. ... AS SELECT "id" FROM item against ... AS SELECT id FROM item is a changed view. The definition is the SQL a result class gives as view_definition, which is written as given, so it comes back the same from a schema nobody changed.
The body of a view is compared and never read. A definition that names a column its table no longer has is the schema's own: with the name written bare SQLite refuses the view when it is used, and DBIO::SQLite::Deploy dies while it builds the target of the upgrade; with the name in double quotes SQLite reads it as a string, the view is valid and returns that string, after an upgrade as after a fresh install.
The triggers of a view
DROP VIEW takes the view's INSTEAD OF triggers with it. A view that goes loses them. A view that is replaced keeps them: its create op carries the CREATE TRIGGER statements the live view had (DBIO::SQLite::Introspect::Triggers) and runs them again behind the CREATE VIEW. They come from the source model, because a schema cannot declare a trigger, and are carried as they are -- also where one names a column the new view no longer has, which SQLite accepts when the trigger is created and reports when it fires. As everywhere in this driver, triggers are carried and never compared.
A view without a statement
A create op is the view's CREATE VIEW statement and nothing else: a view cannot be written from its columns. An introspected model always has the statement. A model built by hand that lists a view without one gives the op nothing to create, and the op is refused: "statements" and "as_sql" throw, in one line that names the view and the reason, and "summary" still lists it -- the way of "Changes that are refused" in DBIO::SQLite::Diff::Column, with the same consequence: "apply" in DBIO::SQLite::Deploy throws before it has run a statement of the diff. A drop op needs no statement.
ATTRIBUTES
view_name
The name of the view.
view_info
The view's entry in the tables section of the model it comes from: the target's for a create, the source's for a drop. A create needs its sql.
triggers
For the create op of a replaced view: an arrayref of the CREATE TRIGGER statements to run again, without closing semicolons. Empty or absent otherwise.
replaced
True on the drop of a changed view: the view 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::View->diff(
$source_views, $target_views, $source_triggers,
);
Compares two hashrefs of view entries, keyed by view name -- the entries of the tables sections that have kind => 'view'. Returns a drop op for a view only the source has, a create op for a view only the target has, and both, drop first, for a view whose definition has changed ("What counts as a changed view").
$source_triggers is the triggers section of the source model; the create op of a changed view takes that view's statements from it. It may be left out.
The ops come sorted by view name. DBIO::SQLite::Diff does not run them side by side: every drop stands at the head of the diff and every create behind the tables -- see "The order of the operations" in DBIO::SQLite::Diff.
statements
my @statements = $op->statements;
The statements of the op in the order they have to run, each closed by its semicolon. A drop is one statement, with the name quoted ("quote_identifier" in DBIO::SQLite::Util):
DROP VIEW "item_names";
A create is the view's CREATE VIEW statement as the target model holds it, followed by the "triggers" it carries:
CREATE VIEW "item_names" AS SELECT "id", "name" FROM "item";
CREATE TRIGGER item_names_ins INSTEAD OF INSERT ON item_names BEGIN ...; END;
A trigger statement has semicolons inside it, which is why this is a list; "statements" in DBIO::SQLite::Diff hands it on as one.
A create whose "view_info" holds no CREATE VIEW statement throws ("A view without a statement"):
Cannot create view item_names: the target model holds no CREATE VIEW
statement for it, and a view cannot be written from its columns
as_sql
"statements", joined by newlines. Throws where that does.
summary
+ view: name or - view: name. It never throws, for an op "as_sql" refuses either.
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.