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

Helm Chart: Numerous improvements #4000

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clean ups
  • Loading branch information
nwmac committed Oct 31, 2019
commit 28182b73025c86a38b3ba00fd609d1f7a29b42dd
37 changes: 11 additions & 26 deletions src/jetstream/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,25 @@ func GetConnection(dc DatabaseConfig, env *env.VarSet) (*sql.DB, *goose.DBConf,
return nil, nil, err
}

log.Infof("%+v", conf)

db, err := sql.Open(conf.Driver.Name, conf.Driver.OpenStr)
return db, conf, err
}

// GetSQLLiteConnectionWithPath returns an SQLite DB Connection
func GetSQLLiteConnectionWithPath(databaseFile string, sqliteKeepDB bool) (*sql.DB, *goose.DBConf, error) {
if !sqliteKeepDB {
os.Remove(databaseFile)
}
// GetInMemorySQLLiteConnection returns an SQLite DB Connection
func GetInMemorySQLLiteConnection() (*sql.DB, *goose.DBConf, error) {

databaseFile := "file::memory:?cache=shared"
log.Info("Using In Memory Database file")
db, err := sql.Open("sqlite3", databaseFile)
if err != nil {
return nil, nil, err
}

conf := CreateFakeSQLiteGooseDriver()
driver := newDBDriver("sqlite3", databaseFile)
conf := &goose.DBConf{
Driver: driver,
}

err = ApplyMigrations(conf, db)
if err != nil {
return nil, nil, err
Expand All @@ -170,27 +171,11 @@ func GetSQLLiteConnectionWithPath(databaseFile string, sqliteKeepDB bool) (*sql.
return db, conf, nil
}

// CreateFakeSQLiteGooseDriver creates a fake Goose Driver for SQLite
func CreateFakeSQLiteGooseDriver() *goose.DBConf {
// Create fake goose db conf object for SQLite
d := goose.DBDriver{
Name: "sqlite3",
Import: "github.com/mattn/go-sqlite3",
Dialect: &goose.Sqlite3Dialect{},
}

conf := &goose.DBConf{
Driver: d,
}
return conf
}

// NewGooseDBConf creates a new Goose config for database migrations
func NewGooseDBConf(dc DatabaseConfig, env *env.VarSet) (*goose.DBConf, error) {

var openStr, name string

log.Info(dc.DatabaseProvider)

if dc.DatabaseProvider == PGSQL {
name = "postgres"
openStr = buildConnectionString(dc)
Expand All @@ -202,6 +187,7 @@ func NewGooseDBConf(dc DatabaseConfig, env *env.VarSet) (*goose.DBConf, error) {
sqlDbDir := env.String("SQLITE_DB_DIR", ".")
openStr = path.Join(sqlDbDir, SQLiteDatabaseFile)
sqliteKeepDB := env.MustBool("SQLITE_KEEP_DB")
log.Infof("SQLite Database file: %s", openStr)

if !sqliteKeepDB {
os.Remove(openStr)
Expand All @@ -219,7 +205,6 @@ func NewGooseDBConf(dc DatabaseConfig, env *env.VarSet) (*goose.DBConf, error) {

// Create a new DBDriver and populate driver specific
// fields for drivers that we know about.
// Further customization may be done in NewDBConf
func newDBDriver(name, open string) goose.DBDriver {

d := goose.DBDriver{
Expand Down
2 changes: 1 addition & 1 deletion src/jetstream/setup_console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestConsoleSetup(t *testing.T) {

Convey("Check that we can migrate data from the old console_config table", t, func() {

db, _, err := datastore.GetSQLLiteConnectionWithPath("file::memory:?cache=shared", true)
db, _, err := datastore.GetInMemorySQLLiteConnection()
if err != nil {
t.Errorf("can not open sqlite database for testing: %v", err)
}
Expand Down