feat: add Google Sign-In with JWT auth and Neon DB persistence

This commit is contained in:
user
2026-04-27 13:23:47 +09:00
parent 7f77c2aaf4
commit 3aa1d92c98
11 changed files with 393 additions and 19 deletions

View File

@@ -2,19 +2,38 @@ package db
import (
"context"
_ "embed"
"embed"
"fmt"
"path"
"sort"
"github.com/jackc/pgx/v5/pgxpool"
)
//go:embed migrations/001_init.sql
var initSQL string
//go:embed migrations/*.sql
var migrationsFS embed.FS
func Migrate(pool *pgxpool.Pool) error {
_, err := pool.Exec(context.Background(), initSQL)
files, err := migrationsFS.ReadDir("migrations")
if err != nil {
return fmt.Errorf("run migration: %w", err)
return fmt.Errorf("read migrations dir: %w", err)
}
sort.Slice(files, func(i, j int) bool {
return files[i].Name() < files[j].Name()
})
for _, f := range files {
if path.Ext(f.Name()) != ".sql" {
continue
}
data, err := migrationsFS.ReadFile("migrations/" + f.Name())
if err != nil {
return fmt.Errorf("read migration %s: %w", f.Name(), err)
}
if _, err := pool.Exec(context.Background(), string(data)); err != nil {
return fmt.Errorf("run migration %s: %w", f.Name(), err)
}
}
return nil
}