Add database URL. (#365)

* Add database URL.

This allows specification of either a file://, env://, or other string.
If it starts with file:// or env:// the actual value will be read from
those resources.

* Tidy up the KMS output

* Also run migrations in test mode when specifying the URL
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-16 09:28:39 -04:00
1 parent c2b49dbc7d
commit c4e2b88022
5 files changed
+83 -7

No files matched your search

+12 -6
View File
@@ -139,24 +139,30 @@ func InitStore(dialect string, cleanup func() error, url string) error {
source, err := migrations.NewMigrationSource(dialect)
if err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error creating migration driver: %w", err))
if err := cleanup(); err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error cleaning up from creating driver: %w", err))
if cleanup != nil {
if err := cleanup(); err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error cleaning up from creating driver: %w", err))
}
}
return mErr.ErrorOrNil()
}
m, err := migrate.NewWithSourceInstance("httpfs", source, url)
if err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error creating migrations: %w", err))
if err := cleanup(); err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error cleaning up from creating migrations: %w", err))
if cleanup != nil {
if err := cleanup(); err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error cleaning up from creating migrations: %w", err))
}
}
return mErr.ErrorOrNil()
}
if err := m.Up(); err != nil && err != migrate.ErrNoChange {
mErr = multierror.Append(mErr, fmt.Errorf("error running migrations: %w", err))
if err := cleanup(); err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error cleaning up from running migrations: %w", err))
if cleanup != nil {
if err := cleanup(); err != nil {
mErr = multierror.Append(mErr, fmt.Errorf("error cleaning up from running migrations: %w", err))
}
}
return mErr.ErrorOrNil()
}