([\w]+))/i){
33
|
1
|
|
|
1
|
|
722
|
push(@table,$+{'table'}); |
|
1
|
|
|
|
|
502
|
|
|
1
|
|
|
|
|
789
|
|
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
|
push(@version,$id); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
0
|
|
|
|
if(defined $action && $action eq 'delete'){ |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do("SET FOREIGN_KEY_CHECKS = 0;"); |
40
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do("DROP TABLE IF EXISTS `$_`;") for (@table); |
41
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do("DROP TABLE IF EXISTS `_version`;"); |
42
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do("SET FOREIGN_KEY_CHECKS = 1;"); |
43
|
0
|
|
|
|
|
|
$self->app->mysql->db->commit; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif(defined $action && $action eq 'create'){ |
46
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do('CREATE TABLE IF NOT EXISTS `_version` (`version_id` int unsigned NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`version_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'); |
47
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do('INSERT INTO `_version` (`version_id`,`date`) VALUES(0,UTC_TIMESTAMP());'); |
48
|
0
|
|
|
|
|
|
$self->app->mysql->db->commit; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif(defined $action && $action eq 'update'){ |
51
|
0
|
|
|
|
|
|
my $collection = $self->app->mysql->query('SELECT `version_id` FROM `_version` ORDER BY `version_id` DESC LIMIT 1;'); |
52
|
0
|
|
|
|
|
|
my $version_id = $collection->last->{'version_id'}; |
53
|
0
|
|
|
|
|
|
say colored ['bright_yellow'],'current sql version:'.$version_id; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
for my $file_version (sort {$a <=> $b} @version){ |
|
0
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if($file_version > int $version_id){ |
57
|
0
|
|
|
|
|
|
my $sql = data_section($migration_object,$file_version); |
58
|
0
|
0
|
|
|
|
|
if(defined $sql){ |
59
|
0
|
|
|
|
|
|
$sql =~ s/\t//g; |
60
|
0
|
|
|
|
|
|
$sql =~ s/\n//g; |
61
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do($sql); |
62
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do("INSERT INTO `_version` (`version_id`,`date`) VALUES($file_version,UTC_TIMESTAMP());"); |
63
|
0
|
|
|
|
|
|
say colored ['bright_green'],'update sql version:'.$file_version; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
|
say colored ['bright_red'],'skip sql version:'.$file_version; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif(defined $action && $action eq 'fake' && $self->app->mode eq 'development'){ |
72
|
0
|
|
|
|
|
|
my $fake_object = $self->app->mysql->{'fake'}->{$id}; |
73
|
0
|
|
|
|
|
|
my $e = load_class $fake_object; |
74
|
0
|
0
|
|
|
|
|
warn qq{Loading "$fake_object" failed: $e} if ref $e; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my @version = (); |
77
|
0
|
|
|
|
|
|
while(my ($id) = each(%{$all})){ |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
push(@version,$id); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
for my $version (sort {$a <=> $b} @version){ |
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $sql = data_section($fake_object,$version); |
83
|
0
|
0
|
|
|
|
|
if(defined $sql){ |
84
|
0
|
|
|
|
|
|
$sql =~ s/\t//g; |
85
|
0
|
|
|
|
|
|
$sql =~ s/\n//g; |
86
|
0
|
|
|
|
|
|
$self->app->mysql->id($id)->do($sql); |
87
|
0
|
|
|
|
|
|
say colored ['bright_blue'],'fake sql version:'.$version; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else{ |
92
|
0
|
|
|
|
|
|
say $self->usage; |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
|
$self->app->mysql->db->commit; |
95
|
0
|
|
|
|
|
|
return $self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__DATA__ |