Skip to content

Commit 8570724

Browse files
beinvisiblelarcorba
authored andcommitted
separate name templates
1 parent 719898e commit 8570724

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

mysql_zbx_part.pl

+10-15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
my $curr_tz = 'Etc/UTC';
3333

34+
# name templates for the different periods
35+
my $partition_name_templates = { 'day' => 'p%Y_%m_%d',
36+
'week' => 'p%Y_w%W',
37+
'month' => 'p%Y_%m',
38+
};
39+
3440
my $part_tables;
3541

3642
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
@@ -149,27 +155,16 @@ sub name_next_part {
149155
my $period = shift;
150156
my $curr_part = shift;
151157

152-
my $name_template;
158+
unless (defined $partition_name_templates->{$period}) {
159+
die "unsupported partitioning period '$period'\n";
160+
}
153161

154162
my $curr_date = DateTime->now( time_zone => $curr_tz );
155163

156164
$curr_date->truncate( to => $period );
157165
$curr_date->add( $period.'s' => $curr_part );
158166

159-
if ( $period eq 'day' ) {
160-
$name_template = $curr_date->strftime('p%Y_%m_%d');
161-
}
162-
elsif ($period eq 'week') {
163-
$name_template = $curr_date->strftime('p%Y_w%W');
164-
}
165-
elsif ($period eq 'month') {
166-
$name_template = $curr_date->strftime('p%Y_%m');
167-
}
168-
else {
169-
die "unsupported partitioning scheme '$period'\n";
170-
}
171-
172-
return $name_template;
167+
return $curr_date->strftime($partition_name_templates->{$period});
173168
}
174169

175170
sub date_next_part {

0 commit comments

Comments
 (0)