50 lines
961 B
Go
50 lines
961 B
Go
/*
|
|
Package dbschema is used to keep the SQL schema up to date.
|
|
|
|
func sqlProvider(dbName string, version int) (sql []byte, found bool) {
|
|
// read an SQL file and return the contents
|
|
return
|
|
}
|
|
|
|
upgrader := dbschema.NewUpgrader()
|
|
upgrader.SetSqlCallback(sqlProvider)
|
|
|
|
if err = upgrader.AddDatabase("127.0.0.1", 5432, "foo", "postgres", "password"); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if err = upgrader.Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
*/
|
|
package dbschema
|
|
|
|
import (
|
|
// External
|
|
_ "github.com/lib/pq"
|
|
|
|
// Standard
|
|
"database/sql"
|
|
)
|
|
|
|
// An upgrader verifies the schema for one or more databases and upgrades them if possible.
|
|
type Upgrader struct {
|
|
schema string
|
|
databases map[string]Database
|
|
logCallback func(string, string)
|
|
sqlCallback func(string, int) ([]byte, bool)
|
|
}
|
|
|
|
type Database struct {
|
|
Host string
|
|
Port int
|
|
DbName string
|
|
Username string
|
|
Password string
|
|
|
|
db *sql.DB
|
|
upgrader *Upgrader
|
|
}
|
|
|
|
// vim: foldmethod=marker
|