-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add database driver for SQLCipher #436
Add database driver for SQLCipher #436
Conversation
Here's a small demo application that I used against my local fork: package main
import (
"database/sql"
"errors"
"fmt"
"log"
"net/url"
"github.com/golang-migrate/migrate/database/sqlcipher"
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/source/file"
_ "github.com/mutecomm/go-sqlcipher/v4"
)
func main() {
key := url.QueryEscape("secret")
dbname := fmt.Sprintf("file:example.db?_pragma_key=%s&_pragma_cipher_page_size=4096", key)
db, err := sql.Open("sqlite3", dbname)
if err != nil {
log.Fatal("sql.Open: ", err)
}
driver, err := sqlcipher.WithInstance(db, &sqlcipher.Config{})
if err != nil {
log.Fatal("sqlcipher.WithInstance: ", err)
}
m, err := migrate.NewWithDatabaseInstance(
"file://migrations",
"sqlcipher", driver)
if err != nil {
log.Fatal("migrate.NewWithDatabaseInstance: ", err)
}
err = m.Up()
if err != nil {
if errors.Is(err, migrate.ErrNoChange) {
log.Println("already migrated, nothing to do")
} else {
log.Fatal(err)
}
}
} |
/cc @frankbraun |
This is a copy of the existing sqlite3 driver, except that it imports `_ "github.com/mutecomm/go-sqlcipher/v4"` as database driver. This allows to use migrate with encrypted sqlite databases.
e71a8dc
to
85d673f
Compare
Pull Request Test Coverage Report for Build 853
💛 - Coveralls |
I could not find a failing even though the CI run with Go 1.14 exited with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Add sqlcipher
to DATABASE_TEST
in the Makefile
.
If you want sqlcipher
in the CLI, you'll also need to add the proper build_sqlcipher.go
file in internal/cli
.
database/sqlcipher/README.md
Outdated
@@ -0,0 +1,3 @@ | |||
# sqlcipher | |||
|
|||
This is just a copy of the sqlite3 driver except that it imports `github.com/mutecomm/go-sqlcipher`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link to the sqlite3 db driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for tests to pass
This is a copy of the existing sqlite3 driver, except that it imports
_ "github.com/mutecomm/go-sqlcipher/v4"
as database driver. This allows to use migrate with encrypted sqlite databases.