database
import "github.com/prescriptoo/prescriptoo-api/pkg/development/database"Package database implements service migrations and local development fixtures.
Index
- Constants
- func Clean(ctx context.Context, db *pgxpool.Pool) error
- func HasManagedPrefix(table string) bool
- func Migrate(ctx context.Context, db *sql.DB, service string, out io.Writer) error
- func Open(rawURL string) (*sql.DB, error)
- func OpenPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error)
- func ResetMigrations(ctx context.Context, db *sql.DB, out io.Writer) error
- func Seed(ctx context.Context, db *pgxpool.Pool, password string, items ...SeedItem) error
- func SeedAccountEmails(items ...SeedItem) []string
- func SeedDoctorCatalogs(ctx context.Context, db *pgxpool.Pool) error
- func ServiceNames() []string
- func Status(ctx context.Context, db *sql.DB, service string, out io.Writer) (err error)
- func ValidateLocalTarget(rawURL, environment string) (*url.URL, error)
- func ValidateMigrationTarget(rawURL string) (*url.URL, error)
- func ValidateSeedPassword(password string) error
- func ValidateService(service string) error
- type ClinicalSeedSummary
- type MedicineSeedSummary
- type MigrationStatus
- type SeedItem
- type SuggestionSeedSummary
Constants
AllServices selects every registered service migration set.
const AllServices = "all"func Clean
func Clean(ctx context.Context, db *pgxpool.Pool) errorClean truncates managed application tables in a single transaction.
func HasManagedPrefix
func HasManagedPrefix(table string) boolHasManagedPrefix reports whether a table belongs to a managed application namespace.
func Migrate
func Migrate(ctx context.Context, db *sql.DB, service string, out io.Writer) errorMigrate applies pending migrations for the selected services and writes their results.
func Open
func Open(rawURL string) (*sql.DB, error)Open validates a PostgreSQL target and opens a handle without connecting yet.
func OpenPool
func OpenPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error)OpenPool creates a PostgreSQL connection pool and verifies connectivity.
func ResetMigrations
func ResetMigrations(ctx context.Context, db *sql.DB, out io.Writer) errorResetMigrations rolls back all service migrations in reverse dependency order.
func Seed
func Seed(ctx context.Context, db *pgxpool.Pool, password string, items ...SeedItem) errorSeed creates the selected account datasets, including scoped authorization. With no explicit selection, it creates the admin and doctor fixtures.
func SeedAccountEmails
func SeedAccountEmails(items ...SeedItem) []stringSeedAccountEmails lists the accounts created by the selected datasets.
func SeedDoctorCatalogs
func SeedDoctorCatalogs(ctx context.Context, db *pgxpool.Pool) errorSeedDoctorCatalogs adds reusable professional terms without creating accounts. Stable IDs and conflict handling preserve administrator edits on repeat runs.
func ServiceNames
func ServiceNames() []stringServiceNames returns service names in migration dependency order.
func Status
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
func ValidateLocalTarget(rawURL, environment string) (*url.URL, error)ValidateLocalTarget requires a development environment and a local PostgreSQL target.
func ValidateMigrationTarget
func ValidateMigrationTarget(rawURL string) (*url.URL, error)ValidateMigrationTarget checks the PostgreSQL URL and rejects system or missing database names.
func ValidateSeedPassword
func ValidateSeedPassword(password string) errorValidateSeedPassword checks an optional shared password override. An empty override uses each development account's email as its password.
func ValidateService
func ValidateService(service string) errorValidateService checks whether the selector names a registered service or all services.
type ClinicalSeedSummary
ClinicalSeedSummary reports bundled coverage and the actual transactional load outcome.
type ClinicalSeedSummary struct {
ChiefComplaints int
Histories int
Categories map[string]int
Inserted int
Reused int
Skipped int
}func SeedClinicalSuggestions
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.
type MedicineSeedSummary struct {
Manufacturers int
Generics int
Brands int
Drugs int
}func SeedMedicine
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.
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
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.
type SeedItem stringAvailable development datasets, in execution order.
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
func ParseSeedItems(names []string) ([]SeedItem, error)ParseSeedItems validates and deduplicates selections in execution order.
func SeedItems
func SeedItems() []SeedItemSeedItems returns the selectable development datasets.
func (SeedItem) Label
func (s SeedItem) Label() stringLabel returns a human-readable dataset name.
type SuggestionSeedSummary
SuggestionSeedSummary counts the entries in the bundled suggestion catalog.
type SuggestionSeedSummary struct {
Diagnoses int
Advice int
Investigations int
}func SeedSuggestions
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