@@ -5,15 +5,23 @@ import (
5
5
"fmt"
6
6
)
7
7
8
- // OpenDBWithDriver creates a connection to a database, and modifies goose
9
- // internals to be compatible with the supplied driver by calling SetDialect.
8
+ // OpenDBWithDriver creates a connection to a database, and modifies goose internals to be
9
+ // compatible with the supplied driver by calling SetDialect.
10
10
func OpenDBWithDriver (driver string , dbstring string ) (* sql.DB , error ) {
11
11
if err := SetDialect (driver ); err != nil {
12
12
return nil , err
13
13
}
14
14
15
- // To avoid breaking existing consumers. An implementation detail
16
- // that consumers should not care which underlying driver is used.
15
+ // The Go ecosystem has added more and more drivers over the years. As a result, there's no
16
+ // longer a one-to-one match between the driver name and the dialect name. For instance, there's
17
+ // no "redshift" driver, but that's the internal dialect name within goose. Hence, we need to
18
+ // convert the dialect name to a supported driver name. This conversion is a best-effort
19
+ // attempt, as we can't support both lib/pq and pgx, which some users might have.
20
+ //
21
+ // We recommend users to create a [NewProvider] with the desired dialect, open a connection
22
+ // using their preferred driver, and provide the *sql.DB to goose. This approach removes the
23
+ // need for mapping dialects to drivers, rendering this function unnecessary.
24
+
17
25
switch driver {
18
26
case "mssql" :
19
27
driver = "sqlserver"
@@ -22,7 +30,6 @@ func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) {
22
30
case "turso" :
23
31
driver = "libsql"
24
32
case "sqlite3" :
25
- // Internally uses the CGo-free port of SQLite: modernc.org/sqlite
26
33
driver = "sqlite"
27
34
case "postgres" , "redshift" :
28
35
driver = "pgx"
0 commit comments