« blib/lib/UR/Namespace/Command/Show/Properties.pm
↑ Summary
blib/lib/UR/Namespace/Command/Test/Callcount/List.pm »
| 1 | package UR::Namespace::Command::Show::Schema; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | class UR::Namespace::Command::Show::Schema { | ||
| 6 | is => 'Command::V2', | ||
| 7 | has_input => [ | ||
| 8 | class_names => { | ||
| 9 | is => 'Text', | ||
| 10 | is_many => 1, | ||
| 11 | shell_args_position => 1, | ||
| 12 | require_user_verify => 0, | ||
| 13 | doc => 'dump the required database schema changes for a class or classes' | ||
| 14 | }, | ||
| 15 | complete => { | ||
| 16 | is => 'Boolean', | ||
| 17 | default_value => 0, | ||
| 18 | doc => 'when set, dump the complete table creation command not just the required changes', | ||
| 19 | }, | ||
| 20 | ], | ||
| 21 | doc => 'database DDL', | ||
| 22 | }; | ||
| 23 | |||
| 24 | sub execute { | ||
| 25 | my $self = shift; | ||
| 26 | my @class_names = $self->class_names; | ||
| 27 | $ENV{UR_DBI_NO_COMMIT} = 1; | ||
| 28 | my $t = UR::Context::Transaction->begin; | ||
| 29 | $DB::single = 1; | ||
| 30 | for my $class_name (@class_names) { | ||
| 31 | my $meta = $class_name->__meta__; | ||
| 32 | |||
| 33 | my $class_name = $meta->class_name; | ||
| 34 | $self->status_message("-- class $class_name\n"); | ||
| 35 | my $ds = $meta->data_source; | ||
| 36 | my @schema_objects = $ds->generate_schema_for_class_meta($meta,1); | ||
| 37 | my ($tt) = grep { $_->isa("UR::DataSource::RDBMS::Table") } @schema_objects; | ||
| 38 | my @ddl = $ds->_resolve_ddl_for_table($tt, all => 1); | ||
| 39 | if (@ddl) { | ||
| 40 | my $ddl = join("\n",@ddl); | ||
| 41 | $self->status_message($ddl); | ||
| 42 | } | ||
| 43 | else { | ||
| 44 | $self->status_message("-- no changes for $class_name, run with the 'complete' flag for the full table DDL"); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | $t->rollback; | ||
| 48 | return 1; | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; | ||
| 52 |