-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GODT-2522): Auto recreate database if migration fails
If migration of the database fails, auto recreate the database and signal to the callee that it was newly created.
- Loading branch information
1 parent
c7380a7
commit 6f2650e
Showing
5 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package db_impl | ||
|
||
import ( | ||
"context" | ||
"github.com/ProtonMail/gluon/db" | ||
"github.com/ProtonMail/gluon/internal/db_impl/sqlite3" | ||
) | ||
|
||
func NewSQLiteDB(options ...sqlite3.Option) db.ClientInterface { | ||
return sqlite3.NewBuilder(options...) | ||
} | ||
|
||
func TestUpdateDBVersion(ctx context.Context, dbPath, userID string, version int) error { | ||
return sqlite3.TestUpdateDBVersion(ctx, dbPath, userID, version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"github.com/ProtonMail/gluon/internal/db_impl" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestFailedMigrationRestsDatabase(t *testing.T) { | ||
dbDir := t.TempDir() | ||
serverOptions := defaultServerOptions(t, withDatabaseDir(dbDir)) | ||
|
||
var userID string | ||
|
||
runServer(t, serverOptions, func(session *testSession) { | ||
userID = session.userIDs["user"] | ||
}) | ||
|
||
require.NoError(t, db_impl.TestUpdateDBVersion(context.Background(), dbDir, userID, 99999)) | ||
|
||
runServer(t, serverOptions, func(session *testSession) {}) | ||
} |