Activity.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« Create/Database.pm ↑ Summary
1 package Daje::Workflow::GenerateSchema::Activity;
2 1 ▶use Mojo::Base 'Daje::Workflow::Common::Activity::Base', -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 use Mojo::JSON qw{to_json};
5 use Daje::Workflow::GenerateSchema::Create::Schema;
6 use Daje::Workflow::GenerateSchema::Create::Database;
7 use Mojo::Pg;
8  
9  
10 # NAME
11 # ====
12 #
13 # Daje::Workflow::GenerateSchema::Activity - It pulls the schema out of a postgres database
14 #
15 # SYNOPSIS
16 # ========
17 #
18 # use Daje::Workflow::GenerateSchema::Activity;
19 #
20 # DESCRIPTION
21 # ===========
22 #
23 # Daje::Workflow::GenerateSchema::Activity is ...
24 #
25 # LICENSE
26 # =======
27 #
28 # Copyright (C) janeskil1525.
29 #
30 # This library is free software; you can redistribute it and/or modify
31 # it under the same terms as Perl itself.
32 #
33 # AUTHOR
34 # ======
35 #
36 # janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
37 #
38 #
39 #
40  
41 our $VERSION = "0.16";
42  
43 has 'pg';
44 has 'dbname';
45  
46 sub process ($self) {
47  
48 $self->_create_database();
49 my $schema = $self->_load_db_schema();
50  
51 $self->_save_json($schema);
52  
53 $self->_drop_database();
54  
55 return 1;
56 }
57  
58 sub _drop_database($self) {
59  
60 my $database = Daje::Workflow::GenerateSchema::Create::Database->new(
61 context => $self->context,
62 dbname => $self->dbname(),
63 );
64 }
65  
66 sub _create_database($self) {
67  
68 my $database = Daje::Workflow::GenerateSchema::Create::Database->new(
69 context => $self->context,
70 );
71  
72 $database->create();
73  
74 $self->pg($database->pg);
75 $self->dbname($database->dbname);
76 }
77  
78 sub _load_db_schema($self) {
79  
80 my $dbschema = Daje::Workflow::GenerateSchema::Create::Schema->new(
81 db => $self->pg->db,
82 excludes => $self->activity_data->{excludes},
83 )->get_db_schema('public');
84  
85 return $dbschema;
86 }
87  
88 sub _save_json($self, $schema) {
89  
90 my $data->{data} = to_json($schema);
91 $data->{file} = "schema";
92 my @data;
93 push(@data, $data);
94 $self->context->{context}->{schema} = \@data;
95 }
96  
97 1;
98 __END__
« Create/Database.pm ↑ Summary