aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-20 02:57:58 +0100
committerTeddy Wing2018-11-20 02:57:58 +0100
commit2068de68350c3dd3ac527a8eb2090d0a9f961866 (patch)
tree8a9791297bb198f7c977fea1570992153f301ba0
parent1e75c341d16bad57e1f881463798ce2b55d0184e (diff)
downloaddome-key-web-2068de68350c3dd3ac527a8eb2090d0a9f961866.tar.bz2
create_purchasers: Remove `DEFAULT UTC_TIMESTAMP()`
Ended up with this error when running my migrations against the production server: error: migration failed in line 0: BEGIN; CREATE TABLE purchasers ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, secret VARCHAR(255), created_at DATETIME NOT NULL DEFAULT UTC_TIMESTAMP(), updated_at DATETIME NOT NULL DEFAULT UTC_TIMESTAMP() ); CREATE TRIGGER purchasers_updated_at BEFORE UPDATE ON purchasers FOR EACH ROW SET NEW.updated_at = UTC_TIMESTAMP(); COMMIT; (details: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UTC_TIMESTAMP(), updated_at DATETIME NOT NULL DEFAULT UTC_TIMESTAMP() ); CR' at line 6) Using MySQL 5.6.34 in production and MariaDB 10.3.10 locally. Guess you can't use `DEFAULT UTC_TIMESTAMP()` there. To use `UTC_TIMESTAMP()`, create a couple new triggers to set the timestamp in the `created_at` and `updated_at` columns.
-rw-r--r--license-generator/migrations/20181109031633_create_purchasers.down.sql4
-rw-r--r--license-generator/migrations/20181109031633_create_purchasers.up.sql16
2 files changed, 16 insertions, 4 deletions
diff --git a/license-generator/migrations/20181109031633_create_purchasers.down.sql b/license-generator/migrations/20181109031633_create_purchasers.down.sql
index d17db9c..3fa17a5 100644
--- a/license-generator/migrations/20181109031633_create_purchasers.down.sql
+++ b/license-generator/migrations/20181109031633_create_purchasers.down.sql
@@ -1,6 +1,8 @@
BEGIN;
-DROP TRIGGER purchasers_updated_at;
+DROP TRIGGER purchasers_created_at_before_insert;
+DROP TRIGGER purchasers_updated_at_before_insert;
+DROP TRIGGER purchasers_updated_at_before_update;
DROP TABLE purchasers;
COMMIT;
diff --git a/license-generator/migrations/20181109031633_create_purchasers.up.sql b/license-generator/migrations/20181109031633_create_purchasers.up.sql
index 8bf597c..19669bd 100644
--- a/license-generator/migrations/20181109031633_create_purchasers.up.sql
+++ b/license-generator/migrations/20181109031633_create_purchasers.up.sql
@@ -5,11 +5,21 @@ CREATE TABLE purchasers (
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
secret VARCHAR(255),
- created_at DATETIME NOT NULL DEFAULT UTC_TIMESTAMP(),
- updated_at DATETIME NOT NULL DEFAULT UTC_TIMESTAMP()
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL
);
-CREATE TRIGGER purchasers_updated_at
+CREATE TRIGGER purchasers_created_at_before_insert
+ BEFORE INSERT
+ ON purchasers FOR EACH ROW
+ SET NEW.created_at = UTC_TIMESTAMP();
+
+CREATE TRIGGER purchasers_updated_at_before_insert
+ BEFORE INSERT
+ ON purchasers FOR EACH ROW
+ SET NEW.updated_at = UTC_TIMESTAMP();
+
+CREATE TRIGGER purchasers_updated_at_before_update
BEFORE UPDATE
ON purchasers FOR EACH ROW
SET NEW.updated_at = UTC_TIMESTAMP();