mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-09 09:05:26 +00:00
Returns error if driver name is not listed.
Also remove references to postgresql driver for now. And add some comments for `database.Init` method.
This commit is contained in:
parent
51519b62dd
commit
28fef9e3f4
3 changed files with 15 additions and 9 deletions
1
Makefile
1
Makefile
|
@ -26,7 +26,6 @@ deps:
|
||||||
go get github.com/GeertJohan/go.rice
|
go get github.com/GeertJohan/go.rice
|
||||||
go get github.com/GeertJohan/go.rice/rice
|
go get github.com/GeertJohan/go.rice/rice
|
||||||
go get github.com/go-sql-driver/mysql
|
go get github.com/go-sql-driver/mysql
|
||||||
go get github.com/lib/pq
|
|
||||||
go get github.com/mattn/go-sqlite3
|
go get github.com/mattn/go-sqlite3
|
||||||
go get github.com/russross/meddler
|
go get github.com/russross/meddler
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ func main() {
|
||||||
|
|
||||||
// setup database and handlers
|
// setup database and handlers
|
||||||
if err := database.Init(driver, datasource); err != nil {
|
if err := database.Init(driver, datasource); err != nil {
|
||||||
log.Fatal("Can't initialize database:", err)
|
log.Fatal("Can't initialize database: ", err)
|
||||||
}
|
}
|
||||||
setupStatic()
|
setupStatic()
|
||||||
setupHandlers()
|
setupHandlers()
|
||||||
|
|
|
@ -2,13 +2,13 @@ package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/drone/drone/pkg/database/migrate"
|
"github.com/drone/drone/pkg/database/migrate"
|
||||||
"github.com/drone/drone/pkg/database/schema"
|
"github.com/drone/drone/pkg/database/schema"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/lib/pq"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
"github.com/russross/meddler"
|
"github.com/russross/meddler"
|
||||||
|
@ -17,6 +17,13 @@ import (
|
||||||
// global instance of our database connection.
|
// global instance of our database connection.
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
|
|
||||||
|
// Init connects to database and performs migration if necessary.
|
||||||
|
//
|
||||||
|
// Database driver name and data source information is provided by user
|
||||||
|
// from within command line, and error checking is deferred to sql.Open.
|
||||||
|
//
|
||||||
|
// Init will just bail out and returns error if driver name
|
||||||
|
// is not listed, no fallback nor default driver sets here.
|
||||||
func Init(name, datasource string) error {
|
func Init(name, datasource string) error {
|
||||||
driver := map[string]struct {
|
driver := map[string]struct {
|
||||||
Md *meddler.Database
|
Md *meddler.Database
|
||||||
|
@ -30,14 +37,14 @@ func Init(name, datasource string) error {
|
||||||
meddler.MySQL,
|
meddler.MySQL,
|
||||||
migrate.MySQL,
|
migrate.MySQL,
|
||||||
},
|
},
|
||||||
"postgresql": {
|
|
||||||
meddler.PostgreSQL,
|
|
||||||
migrate.PostgreSQL,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
meddler.Default = driver[name].Md
|
if drv, ok := driver[name]; ok {
|
||||||
migrate.Driver = driver[name].Mg
|
meddler.Default = drv.Md
|
||||||
|
migrate.Driver = drv.Mg
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("%s driver not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
db, err := sql.Open(name, datasource)
|
db, err := sql.Open(name, datasource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue