From 6347687d54f1aa98d1dcf740622e0987b42bcf7b Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 10 Apr 2020 11:25:21 -0500 Subject: [PATCH] Convert existing schedules to UTC --- .../2020_04_08_172357_alert_schedule_utc.php | 57 +++++++++++++++++++ misc/db_schema.yaml | 10 ++-- 2 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2020_04_08_172357_alert_schedule_utc.php diff --git a/database/migrations/2020_04_08_172357_alert_schedule_utc.php b/database/migrations/2020_04_08_172357_alert_schedule_utc.php new file mode 100644 index 0000000000..c56ac30a6e --- /dev/null +++ b/database/migrations/2020_04_08_172357_alert_schedule_utc.php @@ -0,0 +1,57 @@ +dateTime('start')->nullable()->default('1970-01-02 00:00:01')->change(); + $table->dateTime('end')->nullable()->default('1970-01-02 00:00:01')->change(); + $table->date('start_recurring_dt')->nullable()->change(); + $table->time('start_recurring_hr')->nullable()->change(); + $table->time('end_recurring_hr')->nullable()->change(); + }); + + DB::table('alert_schedule')->update([ + 'start' => DB::raw("CONVERT_TZ(start, @@global.time_zone, '+00:00')"), + 'end' => DB::raw("CONVERT_TZ(end, @@global.time_zone, '+00:00')"), + 'start_recurring_dt' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(start_recurring_dt, ' '), start_recurring_hr), '%Y-%m-%d %H:%i:%s'), @@global.time_zone, '+00:00'), ' ', 1)"), + 'start_recurring_hr' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(start_recurring_dt, ' '), start_recurring_hr), '%Y-%m-%d %H:%i:%s'), @@global.time_zone, '+00:00'), ' ', -1)"), + 'end_recurring_dt' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(end_recurring_dt, ' '), end_recurring_hr), '%Y-%m-%d %H:%i:%s'), @@global.time_zone, '+00:00'), ' ', 1)"), + 'end_recurring_hr' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(end_recurring_dt, ' '), end_recurring_hr), '%Y-%m-%d %H:%i:%s'), @@global.time_zone, '+00:00'), ' ', -1)"), + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + DB::table('alert_schedule')->update([ + 'start' => DB::raw("CONVERT_TZ(start, '+00:00', @@global.time_zone)"), + 'end' => DB::raw("CONVERT_TZ(end, '+00:00', @@global.time_zone)"), + 'start_recurring_dt' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(start_recurring_dt, ' '), start_recurring_hr), '%Y-%m-%d %H:%i:%s'), '+00:00', @@global.time_zone), ' ', 1)"), + 'start_recurring_hr' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(start_recurring_dt, ' '), start_recurring_hr), '%Y-%m-%d %H:%i:%s'), '+00:00', @@global.time_zone), ' ', -1)"), + 'end_recurring_dt' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(end_recurring_dt, ' '), end_recurring_hr), '%Y-%m-%d %H:%i:%s'), '+00:00', @@global.time_zone), ' ', 1)"), + 'end_recurring_hr' => DB::raw("SUBSTRING_INDEX(CONVERT_TZ(STR_TO_DATE(CONCAT(CONCAT(end_recurring_dt, ' '), end_recurring_hr), '%Y-%m-%d %H:%i:%s'), '+00:00', @@global.time_zone), ' ', -1)"), + ]); + + Schema::table('alert_schedule', function (Blueprint $table) { + $table->dateTime('start')->nullable(false)->default('1970-01-02 00:00:01')->change(); + $table->dateTime('end')->nullable(false)->default('1970-01-02 00:00:01')->change(); + $table->date('start_recurring_dt')->nullable(false)->default('1970-01-01')->change(); + $table->time('start_recurring_hr')->nullable(false)->default('00:00:00')->change(); + $table->time('end_recurring_hr')->nullable(false)->default('00:00:00')->change(); + }); + } +} diff --git a/misc/db_schema.yaml b/misc/db_schema.yaml index 766fb8ad38..f1ec2fcdd9 100644 --- a/misc/db_schema.yaml +++ b/misc/db_schema.yaml @@ -101,12 +101,12 @@ alert_schedule: Columns: - { Field: schedule_id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment } - { Field: recurring, Type: 'tinyint(1) unsigned', 'Null': false, Extra: '', Default: '0' } - - { Field: start, Type: datetime, 'Null': false, Extra: '', Default: '1970-01-02 00:00:01' } - - { Field: end, Type: datetime, 'Null': false, Extra: '', Default: '1970-01-02 00:00:01' } - - { Field: start_recurring_dt, Type: date, 'Null': false, Extra: '', Default: '1970-01-01' } + - { Field: start, Type: datetime, 'Null': true, Extra: '', Default: '1970-01-02 00:00:01' } + - { Field: end, Type: datetime, 'Null': true, Extra: '', Default: '1970-01-02 00:00:01' } + - { Field: start_recurring_dt, Type: date, 'Null': true, Extra: '', Default: '1970-01-01' } - { Field: end_recurring_dt, Type: date, 'Null': true, Extra: '' } - - { Field: start_recurring_hr, Type: time, 'Null': false, Extra: '', Default: '00:00:00' } - - { Field: end_recurring_hr, Type: time, 'Null': false, Extra: '', Default: '00:00:00' } + - { Field: start_recurring_hr, Type: time, 'Null': true, Extra: '', Default: '00:00:00' } + - { Field: end_recurring_hr, Type: time, 'Null': true, Extra: '', Default: '00:00:00' } - { Field: recurring_day, Type: varchar(15), 'Null': true, Extra: '' } - { Field: title, Type: varchar(255), 'Null': false, Extra: '' } - { Field: notes, Type: text, 'Null': false, Extra: '' }