File tree 1 file changed +10
-15
lines changed
1 file changed +10
-15
lines changed Original file line number Diff line number Diff line change 31
31
32
32
my $curr_tz = ' Etc/UTC' ;
33
33
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
+
34
40
my $part_tables ;
35
41
36
42
my $dbh = DBI-> connect ($dsn , $db_user_name , $db_password );
@@ -149,27 +155,16 @@ sub name_next_part {
149
155
my $period = shift ;
150
156
my $curr_part = shift ;
151
157
152
- my $name_template ;
158
+ unless (defined $partition_name_templates -> {$period }) {
159
+ die " unsupported partitioning period '$period '\n " ;
160
+ }
153
161
154
162
my $curr_date = DateTime-> now( time_zone => $curr_tz );
155
163
156
164
$curr_date -> truncate ( to => $period );
157
165
$curr_date -> add( $period .' s' => $curr_part );
158
166
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 });
173
168
}
174
169
175
170
sub date_next_part {
You can’t perform that action at this time.
0 commit comments