Skip to content

Commit

Permalink
Merge pull request harness#1311 from bradrydzewski/master
Browse files Browse the repository at this point in the history
ddl statements should use IF NOT EXISTS
  • Loading branch information
bradrydzewski committed Nov 11, 2015
2 parents afb73d8 + f1022d0 commit 23e2faf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions store/datastore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func Open(driver, config string) *sql.DB {
log.Errorln(err)
log.Fatalln("database connection failed")
}
if driver == "mysql" {
// per issue https://github.com/go-sql-driver/mysql/issues/257
db.SetMaxIdleConns(0)
}

setupMeddler(driver)

Expand Down
16 changes: 8 additions & 8 deletions store/migration/mysql/1_init.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- +migrate Up

CREATE TABLE users (
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY AUTO_INCREMENT
,user_login VARCHAR(500)
,user_token VARCHAR(500)
Expand All @@ -15,7 +15,7 @@ CREATE TABLE users (
,UNIQUE(user_login)
);

CREATE TABLE repos (
CREATE TABLE IF NOT EXISTS repos (
repo_id INTEGER PRIMARY KEY AUTO_INCREMENT
,repo_user_id INTEGER
,repo_owner VARCHAR(255)
Expand All @@ -37,7 +37,7 @@ CREATE TABLE repos (
,UNIQUE(repo_full_name)
);

CREATE TABLE `keys` (
CREATE TABLE IF NOT EXISTS `keys` (
key_id INTEGER PRIMARY KEY AUTO_INCREMENT
,key_repo_id INTEGER
,key_public MEDIUMBLOB
Expand All @@ -46,7 +46,7 @@ CREATE TABLE `keys` (
,UNIQUE(key_repo_id)
);

CREATE TABLE builds (
CREATE TABLE IF NOT EXISTS builds (
build_id INTEGER PRIMARY KEY AUTO_INCREMENT
,build_repo_id INTEGER
,build_number INTEGER
Expand All @@ -72,9 +72,9 @@ CREATE TABLE builds (
,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_node_id INTEGER
,job_build_id INTEGER
Expand All @@ -89,8 +89,8 @@ CREATE TABLE jobs (
,UNIQUE(job_build_id, job_number)
);

CREATE INDEX 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_build ON jobs (job_build_id);
CREATE INDEX IF NOT EXISTS ix_job_node ON jobs (job_node_id);

CREATE TABLE IF NOT EXISTS logs (
log_id INTEGER PRIMARY KEY AUTO_INCREMENT
Expand Down
4 changes: 2 additions & 2 deletions store/migration/mysql/2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
ALTER TABLE repos ADD COLUMN repo_scm VARCHAR(25);
ALTER TABLE builds ADD COLUMN build_deploy VARCHAR(500);

UPDATE repos SET repo_scm = 'git';
UPDATE builds SET build_deploy = '';
UPDATE repos SET repo_scm = 'git' WHERE repo_scm = null;
UPDATE builds SET build_deploy = '' WHERE build_deploy = null;

-- +migrate Down

Expand Down

0 comments on commit 23e2faf

Please sign in to comment.