bootstrap

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunInitSQL

func RunInitSQL(db *gorm.DB, sqlFilePath string) error

RunInitSQL executes SQL statements from a local .sql file segment by segment (split by semicolon ;), idempotent scripts should use IF NOT EXISTS in SQL for protection

func RunMigrations

func RunMigrations(db *gorm.DB, models []any) error

RunMigrations executes entity migration

Types

type Bootstrap

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

Bootstrap represents the bootstrap service

func NewBootstrap

func NewBootstrap(logWriter io.Writer, opts *Options) *Bootstrap

NewBootstrap creates a new Bootstrap instance

func (*Bootstrap) PrintBannerFromFile

func (b *Bootstrap) PrintBannerFromFile(filename string) error

PrintBannerFromFile Read file and print

func (*Bootstrap) SetupDatabase

func (b *Bootstrap) SetupDatabase() (*gorm.DB, error)

SetupDatabase unified entry: connect database -> run initialization SQL -> migrate entities -> (non-production) write default configuration

type Options

type Options struct {
	// InitSQLPath points to a .sql script file (optional); skip if empty
	InitSQLPath string
	// AutoMigrate whether to execute entity migration (default true)
	AutoMigrate bool
	// SeedNonProd whether to write default configuration in non-production environments (default true)
	SeedNonProd bool
	// MigrationsDir path to migration SQL scripts directory
	MigrationsDir string
	// DBDriver database driver
	DBDriver string
	// DSN database connection string
	DSN string
	// Models list of models to migrate
	Models []any
	// SeedFuncs list of seed functions to execute after migration
	SeedFuncs []SeedFunc
}

Options controls database initialization behavior

type SeedFunc

type SeedFunc func(db *gorm.DB) error

SeedFunc represents a seeding function

type SeedService

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

SeedService handles database seeding operations

func NewSeedService

func NewSeedService(db *gorm.DB) *SeedService

NewSeedService creates a new SeedService instance

func (*SeedService) SeedAll

func (s *SeedService) SeedAll(seedFuncs ...SeedFunc) error

SeedAll executes all registered seed functions

Jump to

Keyboard shortcuts

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