Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use connection string in sqlite commands that expect a db file path #574

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
9 changes: 7 additions & 2 deletions pkg/driver/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func ConnectionString(u *url.URL) string {
return str
}

// Filepath converts a URL into just the sqlite file path
func Filepath(u *url.URL) string {
return u.Opaque
}

// Open creates a new database connection
func (drv *Driver) Open() (*sql.DB, error) {
return sql.Open("sqlite3", ConnectionString(drv.databaseURL))
Expand Down Expand Up @@ -130,7 +135,7 @@ func (drv *Driver) schemaMigrationsDump(db *sql.DB) ([]byte, error) {

// DumpSchema returns the current database schema
func (drv *Driver) DumpSchema(db *sql.DB) ([]byte, error) {
path := ConnectionString(drv.databaseURL)
path := Filepath(drv.databaseURL)
schema, err := dbutil.RunCommand("sqlite3", path, ".schema --nosys")
if err != nil {
return nil, err
Expand All @@ -147,7 +152,7 @@ func (drv *Driver) DumpSchema(db *sql.DB) ([]byte, error) {

// DatabaseExists determines whether the database exists
func (drv *Driver) DatabaseExists() (bool, error) {
_, err := os.Stat(ConnectionString(drv.databaseURL))
_, err := os.Stat(Filepath(drv.databaseURL))
if os.IsNotExist(err) {
return false, nil
}
Expand Down
Loading