| 1 | package DBIO::Sybase::Deploy; | ||
| 2 | # ABSTRACT: Deploy and upgrade Sybase ASE schemas via test-deploy-and-compare | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use base 'DBIO::Deploy::Base::TempDatabase'; | ||
| 8 | |||
| 9 | use DBIO::Sybase::Diff; | ||
| 10 | use DBIO::Sybase::Introspect; | ||
| 11 | use DBIO::Sybase::DDL; | ||
| 12 | |||
| 13 | |||
| 14 | # Class-name hooks consumed by DBIO::Deploy::Base. | ||
| 15 | sub _ddl_class { 'DBIO::Sybase::DDL' } | ||
| 16 | sub _introspect_class { 'DBIO::Sybase::Introspect' } | ||
| 17 | sub _diff_class { 'DBIO::Sybase::Diff' } | ||
| 18 | |||
| 19 | # --- temp-database glue (engine-specific) --------------------------------- | ||
| 20 | |||
| 21 | # Create a uniquely-named temp database and return its name. CREATE DATABASE | ||
| 22 | # cannot run inside a transaction, so AutoCommit is forced on for the call. | ||
| 23 | sub _create_temp_db { | ||
| 24 | my ($self, $dbh) = @_; | ||
| 25 | my $name = $self->temp_db_prefix . $$ . '_' . time(); | ||
| 26 | |||
| 27 | $dbh->do('COMMIT') if $dbh->{AutoCommit} == 0; | ||
| 28 | local $dbh->{AutoCommit} = 1; | ||
| 29 | $dbh->do("CREATE DATABASE $name"); | ||
| 30 | return $name; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub _drop_temp_db { | ||
| 34 | my ($self, $dbh, $name) = @_; | ||
| 35 | local $dbh->{AutoCommit} = 1; | ||
| 36 | $dbh->do("DROP DATABASE $name"); | ||
| 37 | return 1; | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | 1; | ||
| 46 | |||
| 47 | __END__ | ||
| 48 | |||
| 49 | =pod | ||
| 50 | |||
| 51 | =encoding UTF-8 | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | DBIO::Sybase::Deploy - Deploy and upgrade Sybase ASE schemas via test-deploy-and-compare | ||
| 56 | |||
| 57 | =head1 VERSION | ||
| 58 | |||
| 59 | version 0.900001 | ||
| 60 | |||
| 61 | =head1 DESCRIPTION | ||
| 62 | |||
| 63 | C<DBIO::Sybase::Deploy> orchestrates schema deployment and upgrades for | ||
| 64 | Sybase ASE using the test-deploy-and-compare strategy. | ||
| 65 | |||
| 66 | For upgrades it: | ||
| 67 | |||
| 68 | =over 4 | ||
| 69 | |||
| 70 | =item 1. Introspects the live database via C<INFORMATION_SCHEMA> | ||
| 71 | |||
| 72 | =item 2. Deploys the desired schema (from DBIO classes) to a temporary database | ||
| 73 | |||
| 74 | =item 3. Introspects the temporary database the same way | ||
| 75 | |||
| 76 | =item 4. Computes the diff between the two models using L<DBIO::Sybase::Diff> | ||
| 77 | |||
| 78 | =back | ||
| 79 | |||
| 80 | =head1 METHODS | ||
| 81 | |||
| 82 | =head2 install | ||
| 83 | |||
| 84 | $deploy->install; | ||
| 85 | |||
| 86 | Generates DDL via L<DBIO::Sybase::DDL/install_ddl> and executes each | ||
| 87 | statement against the connected database. Suitable for fresh installs. | ||
| 88 | |||
| 89 | B<NOTE>: L<DBIO::Sybase::DDL> does not yet exist. This method currently | ||
| 90 | falls back to the SQL::Translator codepath via L<DBIO::Schema/deploy>. | ||
| 91 | |||
| 92 | =head2 diff | ||
| 93 | |||
| 94 | my $diff = $deploy->diff; | ||
| 95 | |||
| 96 | Computes the difference between the live database and the desired state. | ||
| 97 | Deploys the desired schema to a temporary database, introspects both, | ||
| 98 | and returns a L<DBIO::Sybase::Diff> object. | ||
| 99 | |||
| 100 | =head2 apply | ||
| 101 | |||
| 102 | $deploy->apply($diff); | ||
| 103 | |||
| 104 | Applies a L<DBIO::Sybase::Diff> object by executing each statement from | ||
| 105 | C<< $diff->as_sql >>. No-op if the diff has no changes. | ||
| 106 | |||
| 107 | =head2 upgrade | ||
| 108 | |||
| 109 | my $diff = $deploy->upgrade; | ||
| 110 | |||
| 111 | Convenience: calls L</diff> then L</apply>. Returns the diff object if | ||
| 112 | changes were applied, or C<undef> if the database was already up to date. | ||
| 113 | |||
| 114 | =seealso | ||
| 115 | |||
| 116 | =over 4 | ||
| 117 | |||
| 118 | =item * L<DBIO::Sybase> - schema component | ||
| 119 | |||
| 120 | =item * L<DBIO::Sybase::Introspect> - reads live database state | ||
| 121 | |||
| 122 | =item * L<DBIO::Sybase::Diff> - compares two introspected models | ||
| 123 | |||
| 124 | =item * L<DBIO::DuckDB::Deploy> - reference implementation | ||
| 125 | |||
| 126 | =back | ||
| 127 | |||
| 128 | =head1 AUTHOR | ||
| 129 | |||
| 130 | DBIO & DBIx::Class Authors | ||
| 131 | |||
| 132 | =head1 COPYRIGHT AND LICENSE | ||
| 133 | |||
| 134 | Copyright (C) 2026 DBIO Authors | ||
| 135 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||
| 136 | Based on DBIx::Class, heavily modified. | ||
| 137 | |||
| 138 | This is free software; you can redistribute it and/or modify it under | ||
| 139 | the same terms as the Perl 5 programming language system itself. | ||
| 140 | |||
| 141 | =cut |