mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-21 20:25:57 +00:00
unit testing postgres, mysql. temporary workaround for backticks
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/rubenv/sql-migrate"
|
||||
"github.com/russross/meddler"
|
||||
)
|
||||
|
||||
func Load(env envconfig.Env) *sql.DB {
|
||||
@@ -36,6 +37,12 @@ func Open(driver, config string) *sql.DB {
|
||||
log.Errorln(err)
|
||||
log.Fatalln("database connection failed")
|
||||
}
|
||||
switch driver {
|
||||
case "mysql":
|
||||
meddler.Default = meddler.MySQL
|
||||
case "postgres":
|
||||
meddler.Default = meddler.PostgreSQL
|
||||
}
|
||||
|
||||
var migrations = &migrate.AssetMigrationSource{
|
||||
Asset: Asset,
|
||||
|
@@ -37,16 +37,6 @@ CREATE TABLE repos (
|
||||
,UNIQUE(repo_full_name)
|
||||
);
|
||||
|
||||
CREATE TABLE stars (
|
||||
star_id INTEGER PRIMARY KEY AUTO_INCREMENT
|
||||
,star_repo_id INTEGER
|
||||
,star_user_id INTEGER
|
||||
|
||||
,UNIQUE(star_repo_id, star_user_id)
|
||||
);
|
||||
|
||||
CREATE INDEX ix_star_user ON stars (star_user_id);
|
||||
|
||||
CREATE TABLE `keys` (
|
||||
key_id INTEGER PRIMARY KEY AUTO_INCREMENT
|
||||
,key_repo_id INTEGER
|
||||
@@ -82,8 +72,7 @@ CREATE TABLE builds (
|
||||
,UNIQUE(build_number, build_repo_id)
|
||||
);
|
||||
|
||||
CREATE INDEX ix_build_repo ON builds (build_repo_id);
|
||||
CREATE INDEX ix_build_author ON builds (build_author);
|
||||
CREATE INDEX ix_build_repo ON builds (build_repo_id);
|
||||
|
||||
CREATE TABLE jobs (
|
||||
job_id INTEGER PRIMARY KEY AUTO_INCREMENT
|
||||
|
@@ -37,16 +37,6 @@ CREATE TABLE repos (
|
||||
,UNIQUE(repo_full_name)
|
||||
);
|
||||
|
||||
CREATE TABLE stars (
|
||||
star_id SERIAL PRIMARY KEY
|
||||
,star_repo_id INTEGER
|
||||
,star_user_id INTEGER
|
||||
|
||||
,UNIQUE(star_repo_id, star_user_id)
|
||||
);
|
||||
|
||||
CREATE INDEX ix_star_user ON builds (star_user_id);
|
||||
|
||||
CREATE TABLE keys (
|
||||
key_id SERIAL PRIMARY KEY
|
||||
,key_repo_id INTEGER
|
||||
@@ -82,8 +72,7 @@ CREATE TABLE builds (
|
||||
,UNIQUE(build_number, build_repo_id)
|
||||
);
|
||||
|
||||
CREATE INDEX ix_build_repo ON builds (build_repo_id);
|
||||
CREATE INDEX ix_build_author ON builds (build_author);
|
||||
CREATE INDEX ix_build_repo ON builds (build_repo_id);
|
||||
|
||||
CREATE TABLE jobs (
|
||||
job_id SERIAL PRIMARY KEY
|
||||
@@ -121,8 +110,9 @@ CREATE TABLE IF NOT EXISTS nodes (
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO nodes VALUES(null, 'unix:///var/run/docker.sock', 'linux_amd64', '', '', '');
|
||||
INSERT INTO nodes VALUES(null, 'unix:///var/run/docker.sock', 'linux_amd64', '', '', '');
|
||||
INSERT INTO nodes (node_addr, node_arch, node_cert, node_key, node_ca) VALUES
|
||||
('unix:///var/run/docker.sock', 'linux_amd64', '', '', ''),
|
||||
('unix:///var/run/docker.sock', 'linux_amd64', '', '', '');
|
||||
|
||||
-- +migrate Down
|
||||
|
||||
|
@@ -18,13 +18,16 @@ func Rebind(query string) string {
|
||||
rqb := make([]byte, 0, len(qb)+5)
|
||||
j := 1
|
||||
for _, b := range qb {
|
||||
if b == '?' {
|
||||
switch b {
|
||||
case '?':
|
||||
rqb = append(rqb, '$')
|
||||
for _, b := range strconv.Itoa(j) {
|
||||
rqb = append(rqb, byte(b))
|
||||
}
|
||||
j++
|
||||
} else {
|
||||
case '`':
|
||||
rqb = append(rqb, ' ')
|
||||
default:
|
||||
rqb = append(rqb, b)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user