ddl statements should use IF NOT EXISTS

This commit is contained in:
Brad Rydzewski 2015-11-11 10:23:44 -08:00
parent afb73d888c
commit f1022d045a
3 changed files with 14 additions and 10 deletions

View file

@ -67,6 +67,10 @@ func Open(driver, config string) *sql.DB {
log.Errorln(err) log.Errorln(err)
log.Fatalln("database connection failed") log.Fatalln("database connection failed")
} }
if driver == "mysql" {
// per issue https://github.com/go-sql-driver/mysql/issues/257
db.SetMaxIdleConns(0)
}
setupMeddler(driver) setupMeddler(driver)

View file

@ -1,6 +1,6 @@
-- +migrate Up -- +migrate Up
CREATE TABLE users ( CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY AUTO_INCREMENT user_id INTEGER PRIMARY KEY AUTO_INCREMENT
,user_login VARCHAR(500) ,user_login VARCHAR(500)
,user_token VARCHAR(500) ,user_token VARCHAR(500)
@ -15,7 +15,7 @@ CREATE TABLE users (
,UNIQUE(user_login) ,UNIQUE(user_login)
); );
CREATE TABLE repos ( CREATE TABLE IF NOT EXISTS repos (
repo_id INTEGER PRIMARY KEY AUTO_INCREMENT repo_id INTEGER PRIMARY KEY AUTO_INCREMENT
,repo_user_id INTEGER ,repo_user_id INTEGER
,repo_owner VARCHAR(255) ,repo_owner VARCHAR(255)
@ -37,7 +37,7 @@ CREATE TABLE repos (
,UNIQUE(repo_full_name) ,UNIQUE(repo_full_name)
); );
CREATE TABLE `keys` ( CREATE TABLE IF NOT EXISTS `keys` (
key_id INTEGER PRIMARY KEY AUTO_INCREMENT key_id INTEGER PRIMARY KEY AUTO_INCREMENT
,key_repo_id INTEGER ,key_repo_id INTEGER
,key_public MEDIUMBLOB ,key_public MEDIUMBLOB
@ -46,7 +46,7 @@ CREATE TABLE `keys` (
,UNIQUE(key_repo_id) ,UNIQUE(key_repo_id)
); );
CREATE TABLE builds ( CREATE TABLE IF NOT EXISTS builds (
build_id INTEGER PRIMARY KEY AUTO_INCREMENT build_id INTEGER PRIMARY KEY AUTO_INCREMENT
,build_repo_id INTEGER ,build_repo_id INTEGER
,build_number INTEGER ,build_number INTEGER
@ -72,9 +72,9 @@ CREATE TABLE builds (
,UNIQUE(build_number, build_repo_id) ,UNIQUE(build_number, build_repo_id)
); );
CREATE INDEX ix_build_repo ON builds (build_repo_id); CREATE INDEX IF NOT EXISTS ix_build_repo ON builds (build_repo_id);
CREATE TABLE jobs ( CREATE TABLE IF NOT EXISTS jobs (
job_id INTEGER PRIMARY KEY AUTO_INCREMENT job_id INTEGER PRIMARY KEY AUTO_INCREMENT
,job_node_id INTEGER ,job_node_id INTEGER
,job_build_id INTEGER ,job_build_id INTEGER
@ -89,8 +89,8 @@ CREATE TABLE jobs (
,UNIQUE(job_build_id, job_number) ,UNIQUE(job_build_id, job_number)
); );
CREATE INDEX ix_job_build ON jobs (job_build_id); CREATE INDEX IF NOT EXISTS ix_job_build ON jobs (job_build_id);
CREATE INDEX ix_job_node ON jobs (job_node_id); CREATE INDEX IF NOT EXISTS ix_job_node ON jobs (job_node_id);
CREATE TABLE IF NOT EXISTS logs ( CREATE TABLE IF NOT EXISTS logs (
log_id INTEGER PRIMARY KEY AUTO_INCREMENT log_id INTEGER PRIMARY KEY AUTO_INCREMENT

View file

@ -3,8 +3,8 @@
ALTER TABLE repos ADD COLUMN repo_scm VARCHAR(25); ALTER TABLE repos ADD COLUMN repo_scm VARCHAR(25);
ALTER TABLE builds ADD COLUMN build_deploy VARCHAR(500); ALTER TABLE builds ADD COLUMN build_deploy VARCHAR(500);
UPDATE repos SET repo_scm = 'git'; UPDATE repos SET repo_scm = 'git' WHERE repo_scm = null;
UPDATE builds SET build_deploy = ''; UPDATE builds SET build_deploy = '' WHERE build_deploy = null;
-- +migrate Down -- +migrate Down