Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use the new Docker package
  • Loading branch information
kyleconroy committed Aug 25, 2025
commit a4893b19c6cff0725dd20f42de05235cf701860b
15 changes: 10 additions & 5 deletions internal/sqltest/local/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ import (

migrate "github.com/sqlc-dev/sqlc/internal/migrations"
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
"github.com/sqlc-dev/sqlc/internal/sqltest/docker"
)

var mysqlSync sync.Once
var mysqlPool *sql.DB

func MySQLServer() string {
return os.Getenv("MYSQL_SERVER_URI")
}

func MySQL(t *testing.T, migrations []string) string {
ctx := context.Background()
t.Helper()

dburi := os.Getenv("MYSQL_SERVER_URI")
if dburi == "" {
t.Skip("MYSQL_SERVER_URI is empty")
if ierr := docker.Installed(); ierr == nil {
u, err := docker.StartMySQLServer(ctx)
if err != nil {
t.Fatal(err)
}
dburi = u
} else {
t.Skip("MYSQL_SERVER_URI is empty")
}
}

mysqlSync.Do(func() {
Expand Down
15 changes: 10 additions & 5 deletions internal/sqltest/local/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
migrate "github.com/sqlc-dev/sqlc/internal/migrations"
"github.com/sqlc-dev/sqlc/internal/pgx/poolcache"
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
"github.com/sqlc-dev/sqlc/internal/sqltest/docker"
)

var flight singleflight.Group
Expand All @@ -28,17 +29,21 @@ func ReadOnlyPostgreSQL(t *testing.T, migrations []string) string {
return postgreSQL(t, migrations, false)
}

func PostgreSQLServer() string {
return os.Getenv("POSTGRESQL_SERVER_URI")
}

func postgreSQL(t *testing.T, migrations []string, rw bool) string {
ctx := context.Background()
t.Helper()

dburi := os.Getenv("POSTGRESQL_SERVER_URI")
if dburi == "" {
t.Skip("POSTGRESQL_SERVER_URI is empty")
if ierr := docker.Installed(); ierr == nil {
u, err := docker.StartPostgreSQLServer(ctx)
if err != nil {
t.Fatal(err)
}
dburi = u
} else {
t.Skip("POSTGRESQL_SERVER_URI is empty")
}
}

postgresPool, err := cache.Open(ctx, dburi)
Expand Down
Loading