NAME

DBIO::Oracle::Diff::View - Diff operations for Oracle views

VERSION

version 0.900007

DESCRIPTION

Compares the views of two models: CREATE OR REPLACE VIEW for a view only the target has and for one whose definition changed, DROP VIEW for one only the source has. The definition is the views section of the model, per view { view_name => $name, definition => $sql, columns => \@names, depends_on => \@views } (DBIO::Oracle::Introspect::Views); the kind of an object is the kind of its entry in tables. The statement is CREATE OR REPLACE VIEW "name" ("col", ...) AS definition, the definition as the target model has it and the column list from columns (below). A changed view is replaced as a whole: its columns are not altered one by one, and DBIO::Oracle::Diff::Column leaves the columns of a view alone.

DBIO::Oracle::Diff puts the drops before the operations on tables and the creations and replacements after them. A view that rests on another view is ordered by the dependency (the depends_on list of its entry in views, read from all_dependencies): the views written (created or replaced) rest-on first, in the order of the target model's dependencies; the views dropped dependents first, in the order of the source model's. A view that rests on one this run does not write needs no edge, and a dependency on a view of another schema is the key schema.view. Views that rest on each other (a cycle, possible only in a model written by hand) are refused with a DBIO::Exception naming them, before the first statement.

The column list. The text of a view does not hold the names given by CREATE VIEW v (a, b) AS ...; they are only in the columns of the view. The model therefore carries them (columns, the names from all_tab_columns in COLUMN_ID order, as Oracle spells them) and the diff writes them in front of AS, each quoted as the model has it, so an alias that came from a column list survives the replace. A view whose query is the same but whose column list differs (a name or the order) is changed. A model without columns (written by hand) gets a statement without a list, and its column list is not compared.

Comparison. Two definitions are equal when they are equal after leading and trailing whitespace and a trailing semicolon are removed and every run of whitespace outside a string literal ('...') or a quoted identifier ("...") is one space. Everything else is compared as written, case included.

What Oracle stores. The text in all_views.text is what Oracle keeps of the statement, not the statement. Measured on Oracle 23ai Free (t/57, t/87):

  • Only the query is kept: CREATE [OR REPLACE] [FORCE] VIEW name AS and the whitespace behind AS are gone, and so is a trailing semicolon. A comment (/* ... */) in front of the SELECT is dropped; a -- ... comment inside the query stays.

  • A column list CREATE VIEW v (a, b) AS ... is not part of the text: a view written with one reads back as the bare query, and the names are only in the view's columns, which the model carries as columns (see above).

  • SELECT * is expanded to the columns, written "a","b" without a space after the comma. WITH READ ONLY and WITH CHECK OPTION stay in the text.

  • Case and the whitespace inside the query are kept as written.

Both models of a diff come from the server (the live schema and the temporary user of DBIO::Oracle::Deploy), so both have passed through this rewriting and equal queries compare equal. A model written by hand is compared with one read from a server only as far as its text agrees with what the server stores. A view whose definition is missing (not set, undef or empty) in the target model, or in the source model of a view both have, is refused with a DBIO::Exception naming the view, before the first statement: the diff does not guess whether it changed, and it does not replace it every time. A view that is only dropped needs no definition.

ATTRIBUTES

view_name

The key of the view: a bare name, or schema.view for a view of another schema, written "schema"."view".

definition

The defining query, for a create or alter op.

columns

The names of the columns of the view in order (an ArrayRef), for a create or alter op; undef when the model carries none.

METHODS

table_name

The same as "view_name": every operation of a diff answers table_name with the key of the object it is on (the conformance runner and the callers that filter operations by object ask for it).

diff

my @ops = DBIO::Oracle::Diff::View->diff(
    $source_tables, $target_tables, $source_views, $target_views,
);

The tables and views sections of the two models. Returns create ops for the views only the target has, alter ops for those whose definition changed, and drop ops for those only the source has, each group in the order of the names. The ops are told apart by action; the caller places the drops before the table operations and the others after them.

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.