feat: add migration

This commit is contained in:
2025-01-16 13:48:05 +01:00
parent 703f2ae096
commit a68eae8519
9 changed files with 198 additions and 16 deletions

View File

@@ -1,23 +1,17 @@
package app
import (
"context"
"fmt"
"os"
"time"
"git.front.kjuulh.io/kjuulh/orbis/internal/persistence"
"git.front.kjuulh.io/kjuulh/orbis/internal/utilities"
"github.com/jackc/pgx/v5"
)
var Postgres = utilities.Singleton(func() (*pgx.Conn, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
conn, err := pgx.Connect(ctx, os.Getenv("ORBIS_POSTGRES_DB"))
if err != nil {
return nil, fmt.Errorf("failed to connect to orbis postgres database: %w", err)
if err := persistence.Migrate(); err != nil {
return nil, fmt.Errorf("failed to migrate database: %w", err)
}
return conn, nil
return persistence.NewConnection()
})