@@ -13,6 +13,7 @@ import (
1313 "github.com/ory/dockertest/v3/docker"
1414 "golang.org/x/xerrors"
1515
16+ "github.com/coder/coder/coderd/database"
1617 "github.com/coder/coder/cryptorand"
1718)
1819
@@ -39,9 +40,21 @@ func Open() (string, func(), error) {
3940 }
4041
4142 dbName = "ci" + dbName
42- _ , err = db .Exec ("CREATE DATABASE " + dbName )
43- if err != nil {
44- return "" , nil , xerrors .Errorf ("create db: %w" , err )
43+ if os .Getenv ("DB_FROM" ) == "" {
44+ _ , err = db .Exec ("CREATE DATABASE " + dbName )
45+ if err != nil {
46+ return "" , nil , xerrors .Errorf ("create db: %w" , err )
47+ }
48+
49+ err = database .MigrateUp (db )
50+ if err != nil {
51+ return "" , nil , xerrors .Errorf ("migrate db: %w" , err )
52+ }
53+ } else {
54+ _ , err = db .Exec ("CREATE DATABASE " + dbName + " WITH TEMPLATE " + os .Getenv ("DB_FROM" ))
55+ if err != nil {
56+ return "" , nil , xerrors .Errorf ("create db with template: %w" , err )
57+ }
4558 }
4659
4760 deleteDB := func () {
@@ -74,7 +87,7 @@ func Open() (string, func(), error) {
7487
7588 resource , err := pool .RunWithOptions (& dockertest.RunOptions {
7689 Repository : "postgres" ,
77- Tag : "11 " ,
90+ Tag : "13 " ,
7891 Env : []string {
7992 "POSTGRES_PASSWORD=postgres" ,
8093 "POSTGRES_USER=postgres" ,
0 commit comments