From 1a05027f8a9a9a1cf567fb1b5793a62dc6194713 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 7 Jun 2019 10:13:17 +0200 Subject: [PATCH] DB: Use UNIX_TIMESTAMP() instead of CURRENT_TIMESTAMP() --- schema/mysql-migrations/v0.9.1.sql | 5 +++-- schema/mysql.sql | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/schema/mysql-migrations/v0.9.1.sql b/schema/mysql-migrations/v0.9.1.sql index 42d3c036..bd71b376 100644 --- a/schema/mysql-migrations/v0.9.1.sql +++ b/schema/mysql-migrations/v0.9.1.sql @@ -1,5 +1,6 @@ -UPDATE timeframe SET start = 'first day of January this year midnight', mtime = CURRENT_TIMESTAMP() * 1000 WHERE name = 'Current Year'; -UPDATE timeframe SET start = 'first day of January last year midnight', mtime = CURRENT_TIMESTAMP() * 1000 WHERE name = 'Last Year'; +UPDATE timeframe SET start = 'first day of January this year midnight' WHERE name = 'Current Year'; +UPDATE timeframe SET start = 'first day of January last year midnight' WHERE name = 'Last Year'; +UPDATE timeframe SET ctime = UNIX_TIMESTAMP() * 1000, mtime = UNIX_TIMESTAMP() * 1000; ALTER TABLE timeframe MODIFY COLUMN name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci; ALTER TABLE timeframe ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=default; diff --git a/schema/mysql.sql b/schema/mysql.sql index 8711cb57..015e1c2c 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -11,19 +11,19 @@ CREATE TABLE timeframe ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; INSERT INTO timeframe (name, title, start, end, ctime, mtime) VALUES - ('4 Hours', null, '-4 hours', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('25 Hours', null, '-25 hours', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('One Week', null, '-1 week', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('One Month', null, '-1 month', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('One Year', null, '-1 year', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Current Day', null, 'midnight', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Last Day', null, 'yesterday midnight', 'yesterday 23:59:59', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Current Week', null, 'monday this week midnight', 'sunday this week 23:59:59', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Last Week', null, 'monday last week midnight', 'sunday last week 23:59:59', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Current Month', null, 'first day of this month midnight', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Last Month', null, 'first day of last month midnight', 'last day of last month 23:59:59', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Current Year', null, 'first day of January this year midnight', 'now', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000), - ('Last Year', null, 'first day of January last year midnight', 'last day of December last year 23:59:59', CURRENT_TIMESTAMP() * 1000, CURRENT_TIMESTAMP() * 1000); + ('4 Hours', null, '-4 hours', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('25 Hours', null, '-25 hours', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('One Week', null, '-1 week', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('One Month', null, '-1 month', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('One Year', null, '-1 year', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Day', null, 'midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Day', null, 'yesterday midnight', 'yesterday 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Week', null, 'monday this week midnight', 'sunday this week 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Week', null, 'monday last week midnight', 'sunday last week 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Month', null, 'first day of this month midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Month', null, 'first day of last month midnight', 'last day of last month 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Year', null, 'first day of January this year midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Year', null, 'first day of January last year midnight', 'last day of December last year 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000); CREATE TABLE report ( id int(10) unsigned NOT NULL AUTO_INCREMENT,