Initial phase 1 baseline implementation
Some checks failed
CI / Backend (push) Failing after 4s
CI / Frontend (push) Successful in 11s
CI / Contracts and repository policy (push) Failing after 5s
CI / Container (push) Has been skipped

This commit is contained in:
Elijah 2026-07-16 19:14:01 -07:00
parent 099c53badf
commit 077cf7601a
29 changed files with 1339 additions and 39 deletions

View file

@ -0,0 +1,46 @@
package postgres
import (
"context"
"fmt"
dbgen "drive.local/drivev2/internal/adapters/postgres/generated"
"github.com/jackc/pgx/v5/pgxpool"
)
// Store owns the PostgreSQL connection pool and generated repositories.
type Store struct {
pool *pgxpool.Pool
queries *dbgen.Queries
}
func Open(ctx context.Context, databaseURL string) (*Store, error) {
poolConfig, err := pgxpool.ParseConfig(databaseURL)
if err != nil {
return nil, fmt.Errorf("parse database configuration: %w", err)
}
pool, err := pgxpool.NewWithConfig(ctx, poolConfig)
if err != nil {
return nil, fmt.Errorf("create database pool: %w", err)
}
if err := pool.Ping(ctx); err != nil {
pool.Close()
return nil, fmt.Errorf("ping database: %w", err)
}
return &Store{pool: pool, queries: dbgen.New(pool)}, nil
}
func (s *Store) Close() {
s.pool.Close()
}
func (s *Store) DatabaseHealth(ctx context.Context) error {
_, err := s.queries.DatabaseHealth(ctx)
return err
}
func (s *Store) OwnerExists(ctx context.Context) (bool, error) {
return s.queries.OwnerExists(ctx)
}