From 4158aaa8864ca857d3ce149ea683e0ae039ad593 Mon Sep 17 00:00:00 2001 From: Matej Kramny Date: Fri, 29 Apr 2016 09:33:08 +0200 Subject: [PATCH] Fix SQL - for strict mode --- database/sql_migrations/v0.0.0.sql | 6 +++--- database/sql_migrations/v1.2.0.sql | 2 +- database/sql_migrations/v1.4.0.sql | 2 +- routes/projects/projects.go | 2 +- routes/users.go | 3 +++ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/database/sql_migrations/v0.0.0.sql b/database/sql_migrations/v0.0.0.sql index 7a10f2eef..08f87a5a6 100644 --- a/database/sql_migrations/v0.0.0.sql +++ b/database/sql_migrations/v0.0.0.sql @@ -1,6 +1,6 @@ create table user ( `id` int(11) not null auto_increment primary key, - `created` datetime not null default NOW(), + `created` datetime not null, `username` varchar(255) not null comment "Username, unique", `name` varchar(255) not null comment "Full name", `email` varchar(255) not null comment "Email, unique", @@ -12,7 +12,7 @@ create table user ( create table project ( `id` int(11) not null auto_increment primary key, - `created` datetime not null default NOW() comment "Created timestamp", + `created` datetime not null comment "Created timestamp", `name` varchar(255) not null comment "Project name" ) ENGINE=InnoDB CHARSET=utf8; @@ -104,7 +104,7 @@ create table task ( create table task__output ( `task_id` int(11) not null, `task` varchar(255) not null, - `time` datetime not null default NOW(), + `time` datetime not null, `output` longtext not null, unique key `id` (`task_id`, `time`), diff --git a/database/sql_migrations/v1.2.0.sql b/database/sql_migrations/v1.2.0.sql index e364f2946..e4f38443b 100644 --- a/database/sql_migrations/v1.2.0.sql +++ b/database/sql_migrations/v1.2.0.sql @@ -1,6 +1,6 @@ create table `user__token` ( `id` varchar(32) not null primary key, - `created` datetime not null default NOW(), + `created` datetime not null, `expired` tinyint(1) not null default 0, `user_id` int(11) not null, diff --git a/database/sql_migrations/v1.4.0.sql b/database/sql_migrations/v1.4.0.sql index 9920867a1..606a2c909 100644 --- a/database/sql_migrations/v1.4.0.sql +++ b/database/sql_migrations/v1.4.0.sql @@ -9,6 +9,6 @@ CREATE TABLE `event` ( KEY `created` (`created`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -alter table task add `created` datetime not null default CURRENT_TIMESTAMP, +alter table task add `created` datetime not null, add `start` datetime null, add `end` datetime null; \ No newline at end of file diff --git a/routes/projects/projects.go b/routes/projects/projects.go index aa73b2a94..bc2b4b3f2 100644 --- a/routes/projects/projects.go +++ b/routes/projects/projects.go @@ -38,7 +38,7 @@ func AddProject(c *gin.Context) { panic(err) } - if _, err := database.Mysql.Exec("insert into project__user set project_id=?, user_id=?, admin=1", body.ID, user.ID); err != nil { + if _, err := database.Mysql.Exec("insert into project__user set project_id=?, user_id=?, admin=1, created=NOW()", body.ID, user.ID); err != nil { panic(err) } diff --git a/routes/users.go b/routes/users.go index 8a29d4cdc..fd2a0a13a 100644 --- a/routes/users.go +++ b/routes/users.go @@ -2,6 +2,7 @@ package routes import ( "database/sql" + "time" "github.com/ansible-semaphore/semaphore/database" "github.com/ansible-semaphore/semaphore/models" @@ -25,6 +26,8 @@ func addUser(c *gin.Context) { return } + user.Created = time.Now() + if err := database.Mysql.Insert(&user); err != nil { panic(err) }