From 45d28b7bc1b8c460bb7f8c2b4d1dcbf9830f25e6 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 13 Dec 2015 00:56:35 -0800 Subject: [PATCH 1/2] max 255 varchar for mysql unique indexes --- store/migration/mysql/1_init.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/store/migration/mysql/1_init.sql b/store/migration/mysql/1_init.sql index a593cb4ce..736dfa9b0 100644 --- a/store/migration/mysql/1_init.sql +++ b/store/migration/mysql/1_init.sql @@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS users ( user_id INTEGER PRIMARY KEY AUTO_INCREMENT -,user_login VARCHAR(500) +,user_login VARCHAR(255) ,user_token VARCHAR(500) ,user_secret VARCHAR(500) ,user_expiry INTEGER @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS repos ( ,repo_user_id INTEGER ,repo_owner VARCHAR(255) ,repo_name VARCHAR(255) -,repo_full_name VARCHAR(511) +,repo_full_name VARCHAR(255) ,repo_avatar VARCHAR(500) ,repo_link VARCHAR(1000) ,repo_clone VARCHAR(1000) @@ -120,6 +120,5 @@ DROP TABLE logs; DROP TABLE jobs; DROP TABLE builds; DROP TABLE `keys`; -DROP TABLE stars; DROP TABLE repos; DROP TABLE users; From 43894050b522acfa789da74a7bdbf625775c7397 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 13 Dec 2015 01:00:03 -0800 Subject: [PATCH 2/2] cleanup the database on restart to remove stuck jobs --- store/datastore/store.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/store/datastore/store.go b/store/datastore/store.go index 2f4276520..b6e4de483 100644 --- a/store/datastore/store.go +++ b/store/datastore/store.go @@ -83,6 +83,7 @@ func Open(driver, config string) *sql.DB { log.Errorln(err) log.Fatalln("migration failed") } + cleanupDatabase(db) return db } @@ -128,6 +129,13 @@ func setupDatabase(driver string, db *sql.DB) error { return err } +// helper function to avoid stuck jobs when Drone unexpectedly +// restarts. This is a temp fix for https://github.com/drone/drone/issues/1195 +func cleanupDatabase(db *sql.DB) { + db.Exec("update builds set build_status = 'error' where build_status IN ('pending','running')") + db.Exec("update jobs set job_status = 'error' where job_status IN ('pending','running')") +} + // helper function to setup the meddler default driver // based on the selected driver name. func setupMeddler(driver string) {