| 1 | package Tapper::Cmd::DbDeploy; | ||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||
| 3 | # ABSTRACT: Tapper - Backend functions for DB deployment | ||||||||||
| 4 | 2 | $Tapper::Cmd::DbDeploy::VERSION = '5.0.14'; | |||||||||
| 5 | 2 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Tapper::Config; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Tapper::Schema::TestrunDB; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | extends 'Tapper::Cmd'; | |||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | sub insert_initial_values | ||||||||||
| 18 | 0 | ▶ | { | ||||||||
|
Subroutine
insert_initial_values: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 19 | 0 | my ($self, $db) = @_; | |||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | if ($db eq 'TestrunDB') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | { | ||||||||||
| 23 | 0 | my $dsn = Tapper::Config->subconfig->{database}{$db}{dsn}; | |||||||||
| 24 | 0 | my $user = Tapper::Config->subconfig->{database}{$db}{username}; | |||||||||
| 25 | 0 | my $pw = Tapper::Config->subconfig->{database}{$db}{password}; | |||||||||
| 26 | 0 | my $schema = Tapper::Schema::TestrunDB->connect ($dsn, $user, $pw); | |||||||||
| 27 | |||||||||||
| 28 | # ---------- Topic ---------- | ||||||||||
| 29 | |||||||||||
| 30 | 0 | require DateTime; | |||||||||
| 31 | |||||||||||
| 32 | # official topics | ||||||||||
| 33 | 0 | my %topic_description = %Tapper::Schema::TestrunDB::Result::Topic::topic_description; | |||||||||
| 34 | |||||||||||
| 35 | 0 | foreach my $topic_name(keys %topic_description) { | |||||||||
| 36 | $schema->resultset('Topic')->find_or_create | ||||||||||
| 37 | ({ name => $topic_name, | ||||||||||
| 38 | 0 | description => $topic_description{$topic_name}, | |||||||||
| 39 | }); | ||||||||||
| 40 | } | ||||||||||
| 41 | 0 | $schema->resultset('Queue')->find_or_create | |||||||||
| 42 | ({ name => 'AdHoc', | ||||||||||
| 43 | priority => 1000, | ||||||||||
| 44 | active => 1, | ||||||||||
| 45 | }); | ||||||||||
| 46 | |||||||||||
| 47 | 0 | $schema->resultset('ChartTypes')->find_or_create | |||||||||
| 48 | ({ chart_type_name => 'points', | ||||||||||
| 49 | chart_type_description => 'points', | ||||||||||
| 50 | chart_type_flot_name => 'points', | ||||||||||
| 51 | created_at => DateTime->now(), | ||||||||||
| 52 | }); | ||||||||||
| 53 | 0 | $schema->resultset('ChartTypes')->find_or_create | |||||||||
| 54 | ({ chart_type_name => 'lines', | ||||||||||
| 55 | chart_type_description => 'lines', | ||||||||||
| 56 | chart_type_flot_name => 'lines', | ||||||||||
| 57 | created_at => DateTime->now(), | ||||||||||
| 58 | }); | ||||||||||
| 59 | |||||||||||
| 60 | 0 | $schema->resultset('ChartAxisTypes')->find_or_create | |||||||||
| 61 | ({ chart_axis_type_name => 'numeric', | ||||||||||
| 62 | created_at => DateTime->now(), | ||||||||||
| 63 | }); | ||||||||||
| 64 | 0 | $schema->resultset('ChartAxisTypes')->find_or_create | |||||||||
| 65 | ({ chart_axis_type_name => 'alphanumeric', | ||||||||||
| 66 | created_at => DateTime->now(), | ||||||||||
| 67 | }); | ||||||||||
| 68 | 0 | $schema->resultset('ChartAxisTypes')->find_or_create | |||||||||
| 69 | ({ chart_axis_type_name => 'date', | ||||||||||
| 70 | created_at => DateTime->now(), | ||||||||||
| 71 | }); | ||||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | sub dbdeploy | ||||||||||
| 77 | 0 | ▶ | { | ||||||||
|
Subroutine
dbdeploy: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 78 | 0 | my ($self, $db) = @_; | |||||||||
| 79 | |||||||||||
| 80 | 0 | local $| =1; | |||||||||
| 81 | |||||||||||
| 82 | 0 | my $dsn = Tapper::Config->subconfig->{database}{$db}{dsn}; | |||||||||
| 83 | 0 | my $user = Tapper::Config->subconfig->{database}{$db}{username}; | |||||||||
| 84 | 0 | my $pw = Tapper::Config->subconfig->{database}{$db}{password}; | |||||||||
| 85 | 0 | my $answer; | |||||||||
| 86 | |||||||||||
| 87 | # ----- really? ----- | ||||||||||
| 88 | 0 | print "REALLY DROP AND RE-CREATE DATABASE TABLES [$dsn] (y/N)? "; | |||||||||
| 89 | 0 | ▶ | if ( lc substr(<STDIN>, 0, 1) ne 'y') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | say "Skip."; | |||||||||
| 91 | 0 | return; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | # ----- delete sqlite file ----- | ||||||||||
| 95 | 0 | ▶ | if ($dsn =~ /dbi:SQLite:dbname/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | my ($tmpfname) = $dsn =~ m,dbi:SQLite:dbname=([\w./]+),i; | |||||||||
| 97 | 0 | unlink $tmpfname; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 0 | my $stderr = ''; | |||||||||
| 101 | { | ||||||||||
| 102 | 0 | my $schema; | |||||||||
| 103 | 0 | $schema = Tapper::Schema::TestrunDB->connect ($dsn, $user, $pw); | |||||||||
| 104 | 0 | $schema->deploy({add_drop_table => 1}); # fails with {add_drop_table => 1}, does not provide correct order to drop tables | |||||||||
| 105 | } | ||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 2 | 1; | |||||||||
| 109 | |||||||||||
| 110 | __END__ | ||||||||||