From ad61b5d8b2876a2a5b430dfbe12ed3167eab7d42 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 7 Oct 2018 11:33:03 +1000 Subject: [PATCH] MySQL being stupid x.x - #3 --- query_gen/lib/mysql.go | 9 +++++---- schema/mysql/query_likes.sql | 2 +- schema/mysql/query_polls_votes.sql | 2 +- schema/mysql/query_registration_logs.sql | 2 +- schema/mysql/query_replies.sql | 2 +- schema/mysql/query_revisions.sql | 2 +- schema/mysql/query_topics.sql | 2 +- schema/mysql/query_users.sql | 2 +- schema/mysql/query_users_2fa_keys.sql | 2 +- schema/mysql/query_users_groups_scheduler.sql | 2 +- schema/mysql/query_users_replies.sql | 2 +- 11 files changed, 15 insertions(+), 14 deletions(-) diff --git a/query_gen/lib/mysql.go b/query_gen/lib/mysql.go index 76482ded..c0134c0a 100644 --- a/query_gen/lib/mysql.go +++ b/query_gen/lib/mysql.go @@ -141,9 +141,10 @@ func (adapter *MysqlAdapter) parseColumn(column DBTableColumn) (col DBTableColum // Make it easier to support Cassandra in the future if column.Type == "createdAt" { column.Type = "datetime" - if column.Default == "" { + // MySQL doesn't support this x.x + /*if column.Default == "" { column.Default = "UTC_TIMESTAMP()" - } + }*/ } else if column.Type == "json" { column.Type = "text" } @@ -154,9 +155,9 @@ func (adapter *MysqlAdapter) parseColumn(column DBTableColumn) (col DBTableColum // TODO: Exclude the other variants of text like mediumtext and longtext too if column.Default != "" && column.Type != "text" { end = " DEFAULT " - if column.Type == "datetime" && column.Default[len(column.Default)-1] == ')' { + /*if column.Type == "datetime" && column.Default[len(column.Default)-1] == ')' { end += column.Default - } else if adapter.stringyType(column.Type) && column.Default != "''" { + } else */if adapter.stringyType(column.Type) && column.Default != "''" { end += "'" + column.Default + "'" } else { end += column.Default diff --git a/schema/mysql/query_likes.sql b/schema/mysql/query_likes.sql index 2168e2a3..aa070390 100644 --- a/schema/mysql/query_likes.sql +++ b/schema/mysql/query_likes.sql @@ -3,6 +3,6 @@ CREATE TABLE `likes` ( `targetItem` int not null, `targetType` varchar(50) DEFAULT 'replies' not null, `sentBy` int not null, - `createdAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `createdAt` datetime not null, `recalc` tinyint DEFAULT 0 not null ); \ No newline at end of file diff --git a/schema/mysql/query_polls_votes.sql b/schema/mysql/query_polls_votes.sql index b706a4ae..364940af 100644 --- a/schema/mysql/query_polls_votes.sql +++ b/schema/mysql/query_polls_votes.sql @@ -2,6 +2,6 @@ CREATE TABLE `polls_votes` ( `pollID` int not null, `uid` int not null, `option` int DEFAULT 0 not null, - `castAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `castAt` datetime not null, `ipaddress` varchar(200) DEFAULT '0.0.0.0.0' not null ) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; \ No newline at end of file diff --git a/schema/mysql/query_registration_logs.sql b/schema/mysql/query_registration_logs.sql index 42713456..4ff25633 100644 --- a/schema/mysql/query_registration_logs.sql +++ b/schema/mysql/query_registration_logs.sql @@ -5,6 +5,6 @@ CREATE TABLE `registration_logs` ( `failureReason` varchar(100) not null, `success` bool DEFAULT 0 not null, `ipaddress` varchar(200) not null, - `doneAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `doneAt` datetime not null, primary key(`rlid`) ); \ No newline at end of file diff --git a/schema/mysql/query_replies.sql b/schema/mysql/query_replies.sql index d5becf6e..636b46d5 100644 --- a/schema/mysql/query_replies.sql +++ b/schema/mysql/query_replies.sql @@ -3,7 +3,7 @@ CREATE TABLE `replies` ( `tid` int not null, `content` text not null, `parsed_content` text not null, - `createdAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `createdAt` datetime not null, `createdBy` int not null, `lastEdit` int DEFAULT 0 not null, `lastEditBy` int DEFAULT 0 not null, diff --git a/schema/mysql/query_revisions.sql b/schema/mysql/query_revisions.sql index c0c21573..c74c994f 100644 --- a/schema/mysql/query_revisions.sql +++ b/schema/mysql/query_revisions.sql @@ -3,6 +3,6 @@ CREATE TABLE `revisions` ( `content` text not null, `contentID` int not null, `contentType` varchar(100) DEFAULT 'replies' not null, - `createdAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `createdAt` datetime not null, primary key(`reviseID`) ) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; \ No newline at end of file diff --git a/schema/mysql/query_topics.sql b/schema/mysql/query_topics.sql index 9ab59825..10f2a89d 100644 --- a/schema/mysql/query_topics.sql +++ b/schema/mysql/query_topics.sql @@ -3,7 +3,7 @@ CREATE TABLE `topics` ( `title` varchar(100) not null, `content` text not null, `parsed_content` text not null, - `createdAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `createdAt` datetime not null, `lastReplyAt` datetime not null, `lastReplyBy` int not null, `createdBy` int not null, diff --git a/schema/mysql/query_users.sql b/schema/mysql/query_users.sql index 26fc659f..7425f95a 100644 --- a/schema/mysql/query_users.sql +++ b/schema/mysql/query_users.sql @@ -6,7 +6,7 @@ CREATE TABLE `users` ( `group` int not null, `active` boolean DEFAULT 0 not null, `is_super_admin` boolean DEFAULT 0 not null, - `createdAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `createdAt` datetime not null, `lastActiveAt` datetime not null, `session` varchar(200) DEFAULT '' not null, `last_ip` varchar(200) DEFAULT '0.0.0.0.0' not null, diff --git a/schema/mysql/query_users_2fa_keys.sql b/schema/mysql/query_users_2fa_keys.sql index 69874119..1cfd8a6f 100644 --- a/schema/mysql/query_users_2fa_keys.sql +++ b/schema/mysql/query_users_2fa_keys.sql @@ -9,6 +9,6 @@ CREATE TABLE `users_2fa_keys` ( `scratch6` varchar(50) not null, `scratch7` varchar(50) not null, `scratch8` varchar(50) not null, - `createdAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `createdAt` datetime not null, primary key(`uid`) ) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; \ No newline at end of file diff --git a/schema/mysql/query_users_groups_scheduler.sql b/schema/mysql/query_users_groups_scheduler.sql index b9b547e3..255c8621 100644 --- a/schema/mysql/query_users_groups_scheduler.sql +++ b/schema/mysql/query_users_groups_scheduler.sql @@ -2,7 +2,7 @@ CREATE TABLE `users_groups_scheduler` ( `uid` int not null, `set_group` int not null, `issued_by` int not null, - `issued_at` datetime DEFAULT UTC_TIMESTAMP() not null, + `issued_at` datetime not null, `revert_at` datetime not null, `temporary` boolean not null, primary key(`uid`) diff --git a/schema/mysql/query_users_replies.sql b/schema/mysql/query_users_replies.sql index 6a871bb0..6d5130b4 100644 --- a/schema/mysql/query_users_replies.sql +++ b/schema/mysql/query_users_replies.sql @@ -3,7 +3,7 @@ CREATE TABLE `users_replies` ( `uid` int not null, `content` text not null, `parsed_content` text not null, - `createdAt` datetime DEFAULT UTC_TIMESTAMP() not null, + `createdAt` datetime not null, `createdBy` int not null, `lastEdit` int DEFAULT 0 not null, `lastEditBy` int DEFAULT 0 not null,