generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use dbmate package for running migrations (#546)
...rather than the CLI tool. Fixes #540 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3932e5c
commit 1ddb00b
Showing
33 changed files
with
126 additions
and
93 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
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
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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
File renamed without changes.
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,41 @@ | ||
package sql | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"embed" | ||
"net/url" | ||
|
||
"github.com/alecthomas/errors" | ||
"github.com/amacneil/dbmate/v2/pkg/dbmate" | ||
_ "github.com/amacneil/dbmate/v2/pkg/driver/postgres" | ||
_ "github.com/jackc/pgx/v5/stdlib" // SQL driver | ||
|
||
"github.com/TBD54566975/ftl/backend/common/log" | ||
) | ||
|
||
//go:embed schema | ||
var schema embed.FS | ||
|
||
// Migrate the database. | ||
func Migrate(ctx context.Context, dsn string) error { | ||
u, err := url.Parse(dsn) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid DSN") | ||
} | ||
conn, err := sql.Open("pgx", dsn) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to connect to database") | ||
} | ||
defer conn.Close() | ||
|
||
db := dbmate.New(u) | ||
db.FS = schema | ||
db.Log = log.FromContext(ctx).Scope("migrate").WriterAt(log.Debug) | ||
db.MigrationsDir = []string{"schema"} | ||
err = db.CreateAndMigrate() | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create and migrate database") | ||
} | ||
return nil | ||
} |
File renamed without changes.
5 changes: 2 additions & 3 deletions
5
backend/controller/internal/sql/models.go → backend/controller/sql/models.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 4 additions & 5 deletions
9
backend/controller/internal/sql/querier.go → backend/controller/sql/querier.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.