mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-07 07:42:45 +01:00
refactor: remove pocketbase (#1138)
This commit is contained in:
42
app/migration/sql.go
Normal file
42
app/migration/sql.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sqlmigrations "github.com/SecurityBrewery/catalyst/app/database/migrations"
|
||||
"github.com/SecurityBrewery/catalyst/app/database/sqlc"
|
||||
"github.com/SecurityBrewery/catalyst/app/upload"
|
||||
)
|
||||
|
||||
type sqlMigration struct {
|
||||
sqlName string
|
||||
upSQL string
|
||||
}
|
||||
|
||||
func newSQLMigration(name string) func() (migration, error) {
|
||||
return func() (migration, error) {
|
||||
up, err := sqlmigrations.Migrations.ReadFile(name + ".up.sql")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read up migration file for %s: %w", name, err)
|
||||
}
|
||||
|
||||
return &sqlMigration{
|
||||
sqlName: name,
|
||||
upSQL: string(up),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m sqlMigration) name() string {
|
||||
return m.sqlName
|
||||
}
|
||||
|
||||
func (m sqlMigration) up(ctx context.Context, queries *sqlc.Queries, _ string, _ *upload.Uploader) error {
|
||||
_, err := queries.WriteDB.ExecContext(ctx, m.upSQL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("migration %s up failed: %w", m.sqlName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user