Skip to content

Commit

Permalink
fix: use predictable SQLite in memory DSNs (#2415)
Browse files Browse the repository at this point in the history
Closes #2059
  • Loading branch information
aeneasr committed Apr 29, 2022
1 parent 75d0826 commit 51a13f7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
"github.com/tidwall/gjson"

"github.com/ory/x/configx"
"github.com/ory/x/dbal"
"github.com/ory/x/jsonx"
"github.com/ory/x/logrusx"
"github.com/ory/x/stringsx"
Expand All @@ -55,7 +54,7 @@ import (
const (
DefaultIdentityTraitsSchemaID = "default"
DefaultBrowserReturnURL = "default_browser_return_url"
DefaultSQLiteMemoryDSN = dbal.SQLiteInMemory
DefaultSQLiteMemoryDSN = "sqlite://file::memory:?_fk=true&cache=shared"
DefaultPasswordHashingAlgorithm = "argon2"
DefaultCipherAlgorithm = "noop"
UnknownVersion = "unknown version"
Expand Down
2 changes: 1 addition & 1 deletion driver/registry_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func (m *RegistryDefault) Init(ctx context.Context, opts ...RegistryOption) erro
}

// if dsn is memory we have to run the migrations on every start
if dbal.IsMemorySQLite(m.Config(ctx).DSN()) || m.Config(ctx).DSN() == dbal.SQLiteInMemory || m.Config(ctx).DSN() == dbal.SQLiteSharedInMemory || m.Config(ctx).DSN() == "memory" {
if dbal.IsMemorySQLite(m.Config(ctx).DSN()) || m.Config(ctx).DSN() == "memory" {
m.Logger().Infoln("Ory Kratos is running migrations on every startup as DSN is memory. This means your data is lost when Kratos terminates.")
if err := p.MigrateUp(ctx); err != nil {
m.Logger().WithError(err).Warnf("Unable to run migrations, retrying.")
Expand Down
4 changes: 2 additions & 2 deletions internal/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewConfigurationWithDefaults(t *testing.T) *config.Config {
os.Stderr,
configx.WithValues(map[string]interface{}{
"log.level": "trace",
config.ViperKeyDSN: dbal.SQLiteInMemory,
config.ViperKeyDSN: dbal.NewSQLiteTestDatabase(t),
config.ViperKeyHasherArgon2ConfigMemory: 16384,
config.ViperKeyHasherArgon2ConfigIterations: 1,
config.ViperKeyHasherArgon2ConfigParallelism: 1,
Expand Down Expand Up @@ -71,7 +71,7 @@ func NewFastRegistryWithMocks(t *testing.T) (*config.Config, *driver.RegistryDef
// NewRegistryDefaultWithDSN returns a more standard registry without mocks. Good for e2e and advanced integration testing!
func NewRegistryDefaultWithDSN(t *testing.T, dsn string) (*config.Config, *driver.RegistryDefault) {
c := NewConfigurationWithDefaults(t)
c.MustSet(config.ViperKeyDSN, stringsx.Coalesce(dsn, dbal.SQLiteInMemory))
c.MustSet(config.ViperKeyDSN, stringsx.Coalesce(dsn, dbal.NewSQLiteTestDatabase(t)))

reg, err := driver.NewRegistryFromDSN(c, logrusx.New("", ""))
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion persistence/sql/persister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func pl(t *testing.T) func(lvl logging.Level, s string, args ...interface{}) {
}

func createCleanDatabases(t *testing.T) map[string]*driver.RegistryDefault {
conns := map[string]string{"sqlite": dbal.SQLiteSharedInMemory}
conns := map[string]string{"sqlite": dbal.NewSQLiteTestDatabase(t)}

var l sync.Mutex
if !testing.Short() {
Expand Down

0 comments on commit 51a13f7

Please sign in to comment.