- POST /api/v1/auth/register with mandatory consents
- POST /api/v1/auth/login
- GET /api/v1/me (protected)
- GET /api/v1/legal/{terms,privacy,disclaimer}
- Migrations for users, consent_log, audit_log
- bcrypt + JWT (access + refresh)
- Docker Compose stack
39 lines
758 B
Go
39 lines
758 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
func RunMigrations(ctx context.Context, db *DB, dir string) error {
|
|
files, err := os.ReadDir(dir)
|
|
if err != nil {
|
|
return fmt.Errorf("read migrations dir: %w", err)
|
|
}
|
|
|
|
var ups []string
|
|
for _, f := range files {
|
|
if !f.IsDir() && strings.HasSuffix(f.Name(), ".up.sql") {
|
|
ups = append(ups, f.Name())
|
|
}
|
|
}
|
|
sort.Strings(ups)
|
|
|
|
for _, name := range ups {
|
|
path := filepath.Join(dir, name)
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return fmt.Errorf("read %s: %w", name, err)
|
|
}
|
|
if _, err := db.Pool.Exec(ctx, string(data)); err != nil {
|
|
return fmt.Errorf("exec %s: %w", name, err)
|
|
}
|
|
fmt.Printf("[migrate] applied %s\n", name)
|
|
}
|
|
return nil
|
|
}
|