2023-08-29 17:30:00 +02:00
|
|
|
/*
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
*/
|
2023-08-01 17:10:35 +02:00
|
|
|
package dbschema
|
|
|
|
|
|
|
|
import (
|
|
|
|
// External
|
|
|
|
_ "github.com/lib/pq"
|
|
|
|
|
|
|
|
// Standard
|
|
|
|
"database/sql"
|
|
|
|
)
|
|
|
|
|
2023-08-29 17:30:00 +02:00
|
|
|
// An upgrader verifies the schema for one or more databases and upgrades them if possible.
|
2023-08-01 17:10:35 +02:00
|
|
|
type Upgrader struct {
|
|
|
|
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
|
2023-08-01 19:50:27 +02:00
|
|
|
upgrader *Upgrader
|
2023-08-01 17:10:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: foldmethod=marker
|