mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-24 00:56:15 -06:00
more updates
This commit is contained in:
parent
2786b5f887
commit
7b01304dac
18 changed files with 1368 additions and 133 deletions
|
|
@ -37,11 +37,13 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/cache"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect/pgdialect"
|
||||
"github.com/uptrace/bun/dialect/sqlitedialect"
|
||||
"github.com/uptrace/bun/migrate"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
|
|
@ -73,6 +75,29 @@ type bunDBService struct {
|
|||
conn *DBConn
|
||||
}
|
||||
|
||||
func doMigration(ctx context.Context, db *bun.DB, log *logrus.Logger) error {
|
||||
l := log.WithField("func", "doMigration")
|
||||
|
||||
migrator := migrate.NewMigrator(db, migrations.Migrations)
|
||||
|
||||
if err := migrator.Init(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
group, err := migrator.Migrate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if group.ID == 0 {
|
||||
l.Info("there are no new migrations to run")
|
||||
return nil
|
||||
}
|
||||
|
||||
l.Infof("MIGRATED DATABASE TO %s", group)
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewBunDBService returns a bunDB derived from the provided config, which implements the go-fed DB interface.
|
||||
// Under the hood, it uses https://github.com/uptrace/bun to create and maintain a database connection.
|
||||
func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger) (db.DB, error) {
|
||||
|
|
@ -131,6 +156,9 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger)
|
|||
}
|
||||
|
||||
accounts := &accountDB{config: c, conn: conn, cache: cache.NewAccountCache()}
|
||||
if err := doMigration(ctx, conn.DB, log); err != nil {
|
||||
return nil, fmt.Errorf("db migration error: %s", err)
|
||||
}
|
||||
|
||||
ps := &bunDBService{
|
||||
Account: accounts,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue