This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
bactdb/datastore/db_test.go
Matthew Dillon 8fa594e3f0 DB Migrations
Replacing modl’s built-in table creation and removal
with manual migrations. Thanks to @DavidHuie for
gomigrate!
2014-10-06 17:09:41 -08:00

27 lines
473 B
Go

package datastore
import (
"log"
"os"
"strings"
)
func init() {
// Make sure we don't run the tests on the main DB (will destroy the data)
dbname := os.Getenv("PGDATABASE")
if dbname == "" {
dbname = "bactdbtest"
}
if !strings.HasSuffix(dbname, "test") {
dbname += "test"
}
if err := os.Setenv("PGDATABASE", dbname); err != nil {
log.Fatal(err)
}
// Reset DB
Connect()
migrationsPath := "./migrations"
Drop(migrationsPath)
Create(migrationsPath)
}