From 90fad55722130ab219af249b7729699fd82224b4 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sun, 13 Aug 2017 02:39:44 +0200 Subject: [PATCH] magneticod: use mysql in strict mode, increase name column to 1024 characters --- src/magneticod/persistence.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/magneticod/persistence.go b/src/magneticod/persistence.go index 9b33f58..4cae745 100644 --- a/src/magneticod/persistence.go +++ b/src/magneticod/persistence.go @@ -229,11 +229,17 @@ func setupSqliteDatabase(database *sql.DB) error { } func setupMySQLDatabase(database *sql.DB) error { - _, err := database.Exec( + // Set strict mode to prevent silent truncation + _, err := database.Exec(`SET SESSION SQL_MODE = 'STRICT_ALL_TABLES';`) + if err != nil { + return err + } + + _, err = database.Exec( `CREATE TABLE IF NOT EXISTS torrents (" id INTEGER PRIMARY KEY AUTO_INCREMENT, info_hash BINARY(20) NOT NULL UNIQUE, - name VARCHAR(255) NOT NULL, + name VARCHAR(1024) NOT NULL, total_size BIGINT UNSIGNED NOT NULL, discovered_on INTEGER UNSIGNED NOT NULL );