File: Schema.pm

package info (click to toggle)
libur-perl 0.470%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,184 kB
  • sloc: perl: 61,813; javascript: 255; xml: 108; sh: 13; makefile: 9
file content (52 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package UR::Namespace::Command::Show::Schema;
use strict;
use warnings;

class UR::Namespace::Command::Show::Schema {
    is => 'Command::V2',
    has_input => [
        class_names => { 
          is => 'Text', 
          is_many => 1,
          shell_args_position => 1,
          require_user_verify => 0,
          doc => 'dump the required database schema changes for a class or classes'
        },
        complete => {
          is => 'Boolean',
          default_value => 0,
          doc => 'when set, dump the complete table creation command not just the required changes',
        },
    ],
    doc => 'database DDL',
};

sub execute {
    my $self = shift;
    my @class_names = $self->class_names;
    $ENV{UR_DBI_NO_COMMIT} = 1;
    my $t = UR::Context::Transaction->begin;
    $DB::single = 1;
    for my $class_name (@class_names) {
        my $meta = $class_name->__meta__;

        my $class_name = $meta->class_name;
        $self->status_message("-- class $class_name\n");
        my $ds = $meta->data_source;
        my @schema_objects = $ds->generate_schema_for_class_meta($meta,1); 
        my ($tt) = grep { $_->isa("UR::DataSource::RDBMS::Table") } @schema_objects; 
        my @ddl = $ds->_resolve_ddl_for_table($tt, all => 1);
        if (@ddl) {
            my $ddl = join("\n",@ddl);
            $self->status_message($ddl);
        }
        else {
            $self->status_message("-- no changes for $class_name, run with the 'complete' flag for the full table DDL");
        }
    }
    $t->rollback;
    return 1;
}

1;