Skip to content

database ​

go
import "github.com/prescriptoo/prescriptoo-api/pkg/development/database"

Package database implements service migrations and local development fixtures.

Index ​

Constants ​

AllServices selects every registered service migration set.

go
const AllServices = "all"

func Clean ​

go
func Clean(ctx context.Context, db *pgxpool.Pool) error

Clean truncates managed application tables in a single transaction.

func HasManagedPrefix ​

go
func HasManagedPrefix(table string) bool

HasManagedPrefix reports whether a table belongs to a managed application namespace.

func Migrate ​

go
func Migrate(ctx context.Context, db *sql.DB, service string, out io.Writer) error

Migrate applies pending migrations for the selected services and writes their results.

func Open ​

go
func Open(rawURL string) (*sql.DB, error)

Open validates a PostgreSQL target and opens a handle without connecting yet.

func OpenPool ​

go
func OpenPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error)

OpenPool creates a PostgreSQL connection pool and verifies connectivity.

func ResetMigrations ​

go
func ResetMigrations(ctx context.Context, db *sql.DB, out io.Writer) error

ResetMigrations rolls back all service migrations in reverse dependency order.

func Seed ​

go
func Seed(ctx context.Context, db *pgxpool.Pool, password string, items ...SeedItem) error

Seed creates the selected account datasets, including scoped authorization. With no explicit selection, it creates the admin and doctor fixtures.

func SeedAccountEmails ​

go
func SeedAccountEmails(items ...SeedItem) []string

SeedAccountEmails lists the accounts created by the selected datasets.

func SeedDoctorCatalogs ​

go
func SeedDoctorCatalogs(ctx context.Context, db *pgxpool.Pool) error

SeedDoctorCatalogs adds reusable professional terms without creating accounts. Stable IDs and conflict handling preserve administrator edits on repeat runs.

func ServiceNames ​

go
func ServiceNames() []string

ServiceNames returns service names in migration dependency order.

func Status ​

go
func Status(ctx context.Context, db *sql.DB, service string, out io.Writer) (err error)

Status writes a table of migration states for the selected services.

func ValidateLocalTarget ​

go
func ValidateLocalTarget(rawURL, environment string) (*url.URL, error)

ValidateLocalTarget requires a development environment and a local PostgreSQL target.

func ValidateMigrationTarget ​

go
func ValidateMigrationTarget(rawURL string) (*url.URL, error)

ValidateMigrationTarget checks the PostgreSQL URL and rejects system or missing database names.

func ValidateSeedPassword ​

go
func ValidateSeedPassword(password string) error

ValidateSeedPassword checks an optional shared password override. An empty override uses each development account's email as its password.

func ValidateService ​

go
func ValidateService(service string) error

ValidateService checks whether the selector names a registered service or all services.

type ClinicalSeedSummary ​

ClinicalSeedSummary reports bundled coverage and the actual transactional load outcome.

go
type ClinicalSeedSummary struct {
    ChiefComplaints int
    Histories       int
    Categories      map[string]int
    Inserted        int
    Reused          int
    Skipped         int
}

func SeedClinicalSuggestions ​

go
func SeedClinicalSuggestions(ctx context.Context, db *pgxpool.Pool) (*ClinicalSeedSummary, error)

SeedClinicalSuggestions loads both catalogs atomically and preserves all Admin edits. Immutable seed reservations survive renames, category changes and soft deletion.

type MedicineSeedSummary ​

MedicineSeedSummary counts the distinct catalog entries in the bundled seed.

go
type MedicineSeedSummary struct {
    Manufacturers int
    Generics      int
    Brands        int
    Drugs         int
}

func SeedMedicine ​

go
func SeedMedicine(ctx context.Context, db *pgxpool.Pool) (*MedicineSeedSummary, error)

SeedMedicine loads the bundled Bangladesh catalog in one repeatable transaction. Matching live entries are reused without changing their status or description.

type MigrationStatus ​

MigrationStatus describes one embedded service migration.

go
type MigrationStatus struct {
    Service string `json:"service" doc:"Service that owns the migration."`
    Version int64  `json:"version" doc:"Migration version."`
    State   string `json:"state" doc:"Whether the migration is applied or pending."`
    Path    string `json:"path" doc:"Embedded SQL migration filename."`
}

func ListMigrationStatuses ​

go
func ListMigrationStatuses(ctx context.Context, db *sql.DB, service string) ([]MigrationStatus, error)

ListMigrationStatuses returns migration states in service dependency order.

type SeedItem ​

SeedItem identifies an independently selectable development dataset.

go
type SeedItem string

Available development datasets, in execution order.

go
const (
    SeedAdmin                   SeedItem = "admin"
    SeedOrganization            SeedItem = "organization"
    SeedDoctors                 SeedItem = "doctors"
    SeedMedicines               SeedItem = "medicines"
    SeedPrescriptionSuggestions SeedItem = "suggestions"
    SeedProfessionalCatalogs    SeedItem = "doctor-catalogs"
    SeedClinicalCatalogs        SeedItem = "clinical-suggestions"
)

func ParseSeedItems ​

go
func ParseSeedItems(names []string) ([]SeedItem, error)

ParseSeedItems validates and deduplicates selections in execution order.

func SeedItems ​

go
func SeedItems() []SeedItem

SeedItems returns the selectable development datasets.

func (SeedItem) Label ​

go
func (s SeedItem) Label() string

Label returns a human-readable dataset name.

type SuggestionSeedSummary ​

SuggestionSeedSummary counts the entries in the bundled suggestion catalog.

go
type SuggestionSeedSummary struct {
    Diagnoses      int
    Advice         int
    Investigations int
}

func SeedSuggestions ​

go
func SeedSuggestions(ctx context.Context, db *pgxpool.Pool) (*SuggestionSeedSummary, error)

SeedSuggestions loads all three suggestion catalogs in one repeatable transaction. Existing IDs and labels are preserved, including entries edited after seeding.

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.