feat(backend): pg schema + store queries incl. path-keyed progress

This commit is contained in:
2026-09-04 23:48:05 +08:00
parent d4972d6d4c
commit c1761d0f3e
7 changed files with 504 additions and 14 deletions
+28
View File
@@ -0,0 +1,28 @@
package db
import (
"context"
_ "embed"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
//go:embed schema.sql
var schema string
func Connect(ctx context.Context, url string) (*pgxpool.Pool, error) {
cfg, err := pgxpool.ParseConfig(url)
if err != nil {
return nil, err
}
cfg.MaxConns = 10
return pgxpool.NewWithConfig(ctx, cfg)
}
func Migrate(ctx context.Context, p *pgxpool.Pool) error {
if _, err := p.Exec(ctx, schema); err != nil {
return fmt.Errorf("migrate: %w", err)
}
return nil
}