Skip to content

Commit

Permalink
Fix MySQL column definitions
Browse files Browse the repository at this point in the history
- Add AUTO_INCREMENT to `id` fields
- Fix DEFAULT definitions on TEXT/BLOB fields

TEXT/BLOB field default values must be expressions:
https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html
  • Loading branch information
deanishe committed Sep 22, 2019
1 parent 76a7856 commit ddf7c37
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ func OpenMySQLDatabase(connString string) (mysqlDB *MySQLDatabase, err error) {

// Create tables
tx.MustExec(`CREATE TABLE IF NOT EXISTS account(
id INT(11) NOT NULL,
id INT(11) NOT NULL AUTO_INCREMENT,
username VARCHAR(250) NOT NULL,
password BINARY(80) NOT NULL,
owner TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
UNIQUE KEY account_username_UNIQUE (username))`)

tx.MustExec(`CREATE TABLE IF NOT EXISTS bookmark(
id INT(11) NOT NULL,
id INT(11) NOT NULL AUTO_INCREMENT,
url TEXT NOT NULL,
title TEXT NOT NULL,
excerpt TEXT NOT NULL DEFAULT "",
author TEXT NOT NULL DEFAULT "",
excerpt TEXT NOT NULL DEFAULT (""),
author TEXT NOT NULL DEFAULT (""),
public BOOLEAN NOT NULL DEFAULT 0,
content MEDIUMTEXT NOT NULL DEFAULT "",
html MEDIUMTEXT NOT NULL DEFAULT "",
content MEDIUMTEXT NOT NULL DEFAULT (""),
html MEDIUMTEXT NOT NULL DEFAULT (""),
modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(id),
UNIQUE KEY bookmark_url_UNIQUE (url(255)),
Expand Down

0 comments on commit ddf7c37

Please sign in to comment.