Help us shape the future of Go! Take the 2026 Go Developer Survey

seeders

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Overview

Package seeders builds database fixtures: the first-admin setup row and deterministic development users. It is standalone — SQL against the documented schema plus pkg/crypto for password hashing; no identity-module imports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasAnyUser

func HasAnyUser(ctx context.Context, db Executor) (bool, error)

HasAnyUser reports whether the accounts table is non-empty — the freshness gate for the setup flow.

func SetupAdmin

func SetupAdmin(ctx context.Context, db Executor, params AdminParams) (string, error)

SetupAdmin creates the first admin account with a hashed password. It fails when any user already exists — the setup flow is only valid on a fresh database. Input validation runs before the freshness gate so misconfiguration is reported precisely.

Types

type AdminParams

type AdminParams struct {
	Username string
	Email    string
	Password string
}

AdminParams carries the setup-admin fields.

type Executor

type Executor interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

Executor is the datastore.Executor surface the seeder needs. QueryRow returns pgx.Row directly — Go return-type invariance means a concrete pgx.Row cannot satisfy a custom Scanner iface.

type UserFactory

type UserFactory struct {
	// contains filtered or unexported fields
}

UserFactory creates deterministic development users (base_NNNN) with throwaway hashed passwords. Standalone: plain SQL plus pkg/crypto. Safe for concurrent use.

func NewUserFactory

func NewUserFactory(db Executor, seed uint64) *UserFactory

NewUserFactory builds a factory over db. An explicit seed sets the starting suffix (mod 10000); zero selects a crypto-randomized start for ad-hoc runs.

func (*UserFactory) Create

func (f *UserFactory) Create(ctx context.Context, base string) (string, error)

Create builds one user with the next sequential suffix, wrapping past 9999 back to 0000. Passwords are the username plus a fixed dev suffix — hashed, never stored in plaintext.

func (*UserFactory) CreateMany

func (f *UserFactory) CreateMany(ctx context.Context, base string, count int) ([]string, error)

CreateMany builds count users sharing the same base name, returning their UUIDs in creation order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL