Oracle/Deploy.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Oracle/Storage/LOBSupport.pm ↑ Summary Oracle/Diff.pm »
1 package DBIO::Oracle::Deploy;
2 # ABSTRACT: Deploy and upgrade Oracle schemas via test-deploy-and-compare
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base 'DBIO::Deploy::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DBIO::Oracle::DDL ();
Subroutine BEGIN: called CC=1 SCAR=2.6
11 use DBIO::Oracle::Introspect ();
12 use DBIO::Oracle::Diff ();
13  
14  
15 # --- class-name hooks for DBIO::Deploy::Base -------------------------------
16  
17 sub _ddl_class { 'DBIO::Oracle::DDL' }
18 sub _introspect_class { 'DBIO::Oracle::Introspect' }
19 sub _diff_class { 'DBIO::Oracle::Diff' }
20  
21  
22 sub _build_target_model {
23 my ($self) = @_;
24 my $dbh = $self->_dbh;
25  
26 $dbh->do('SAVEPOINT _dbio_deploy');
27  
28 my $target_model;
29 my $err;
30 eval {
31 $self->_execute_ddl($dbh, $self->_install_ddl);
32 $target_model = $self->_new_introspect($dbh)->model;
33 1;
34 } or $err = $@;
35  
36 # Always restore the live connection, even on failure.
37 eval { $dbh->do('ROLLBACK TO SAVEPOINT _dbio_deploy'); };
38  
39 die $err if $err;
40 return $target_model;
41 }
42  
43  
44 1;
45  
46 __END__
47  
48 =pod
49  
50 =encoding UTF-8
51  
52 =head1 NAME
53  
54 DBIO::Oracle::Deploy - Deploy and upgrade Oracle schemas via test-deploy-and-compare
55  
56 =head1 VERSION
57  
58 version 0.900001
59  
60 =head1 DESCRIPTION
61  
62 C<DBIO::Oracle::Deploy> orchestrates schema deployment and upgrades for
63 Oracle using the test-deploy-and-compare strategy.
64  
65 For upgrades it:
66  
67 =over 4
68  
69 =item 1. Introspects the live database via C<all_*> views
70  
71 =item 2. Opens a C<SAVEPOINT> on the live connection (Oracle has no
72 cheap throwaway database like PostgreSQL's C<CREATE DATABASE>)
73  
74 =item 3. Deploys the desired schema (from DBIO classes) into that context
75  
76 =item 4. Introspects that schema the same way
77  
78 =item 5. Computes the diff between the two models using L<DBIO::Oracle::Diff>
79  
80 =item 6. Rolls back to the savepoint so the test deploy never persists
81  
82 =back
83  
84 The shared orchestration (L<install|/install>, L<apply|/apply>,
85 L<upgrade|/upgrade>) is inherited from L<DBIO::Deploy::Base>; this class
86 supplies the three class-name hooks and the SAVEPOINT-based
87 L</_build_target_model> -- the real engine seam.
88  
89 my $deploy = DBIO::Oracle::Deploy->new(
90 schema => MyApp::DB->connect($dsn),
91 );
92 $deploy->install; # fresh
93 my $diff = $deploy->diff; # or step-by-step
94 $deploy->apply($diff) if $diff->has_changes;
95 $deploy->upgrade; # convenience
96  
97 =head1 METHODS
98  
99 =head2 _build_target_model
100  
101 The desired-state model. Oracle has no cheap throwaway database, so
102 test-deploy-and-compare runs against the live connection inside a
103 C<SAVEPOINT>: deploy the install DDL, introspect the result, then
104 C<ROLLBACK TO SAVEPOINT> to undo the partial deploy. The rollback runs
105 unconditionally inside the eval -- even when introspect or deploy
106 throws, the connection state must be restored.
107  
108 =seealso
109  
110 =over 4
111  
112 =item * L<DBIO::Oracle> - schema component
113  
114 =item * L<DBIO::Oracle::DDL> - generates DDL
115  
116 =item * L<DBIO::Oracle::Introspect> - reads live database state
117  
118 =item * L<DBIO::Oracle::Diff> - compares two introspected models
119  
120 =item * L<DBIO::Deploy::Base> - inherited orchestration
121  
122 =back
123  
124 =head1 AUTHOR
125  
126 DBIO & DBIx::Class Authors
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 Copyright (C) 2026 DBIO Authors
131 Portions Copyright (C) 2005-2025 DBIx::Class Authors
132 Based on DBIx::Class, heavily modified.
133  
134 This is free software; you can redistribute it and/or modify it under
135 the same terms as the Perl 5 programming language system itself.
136  
137 =cut
« Oracle/Storage/LOBSupport.pm ↑ Summary Oracle/Diff.pm »