Skip to content

Commit

Permalink
DB: Use UNIX_TIMESTAMP() instead of CURRENT_TIMESTAMP()
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Jun 7, 2019
1 parent e784b30 commit 1a05027
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions schema/mysql-migrations/v0.9.1.sql
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
26 changes: 13 additions & 13 deletions schema/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1a05027

Please sign in to comment.