dbinit

package
v0.0.0-...-ae8aaeb Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatedDatabase

func CreatedDatabase(log logging.Logger) (err error)

func CreatedDatabaseWithConfig

func CreatedDatabaseWithConfig(log logging.Logger, conf *Config) (err error)

func GenerateRandomPassword

func GenerateRandomPassword(length int) string

func RunMigrations

func RunMigrations(mode Mode) error

func RunMigrationsWithConfig

func RunMigrationsWithConfig(conf *DBConfig, mode Mode) error

Types

type BaseConfig

type BaseConfig struct {
	DBHost                string `envconfig:"PG_DB_HOST" required:"true"`
	DBPort                string `envconfig:"PG_DB_PORT" required:"true"`
	DBAdminCredIdentifier string `envconfig:"PG_DB_ADMIN_CRED_IDENTIFIER" default:"postgres-admin"`
	EntityName            string `envconfig:"PG_DB_ENTITY_NAME" default:"postgres"`
}

type Config

type Config struct {
	BaseConfig
	DBName            string `envconfig:"PG_DB_NAME" required:"false"`
	DBServiceUsername string `envconfig:"PG_DB_SERVICE_USERNAME" required:"false"`
	Password          string `envconfig:"PG_DB_SERVICE_USERPASSWORD" required:"false"`
	AdminPassword     string `envconfig:"PG_DB_ADMIN_PASSWORD" required:"false"`
}

type DBConfig

type DBConfig struct {
	DBHost     string `envconfig:"PG_DB_HOST" required:"true"`
	DBPort     string `envconfig:"PG_DB_PORT" default:"5432"`
	DBName     string `envconfig:"PG_DB_NAME" required:"true"`
	EntityName string `envconfig:"PG_DB_ENTITY_NAME" default:"postgres"`
	Username   string `envconfig:"PG_DB_SERVICE_USERNAME" required:"true"`
	Password   string `envconfig:"PG_DB_SERVICE_USERPASSWORD" required:"false"`
	SourceURI  string `envconfig:"PG_SOURCE_URI" default:"file:///postgres/migrations"`
}

type Mode

type Mode int
const (
	UP    Mode = Mode(1)
	DOWN  Mode = Mode(2)
	PURGE Mode = Mode(3)
)

type PostgresAdmin

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

func NewPostgresAdmin

func NewPostgresAdmin(logger logging.Logger, dbAddr, dbAdminUsername, dbAdminPassword string) (*PostgresAdmin, error)

func (*PostgresAdmin) CreateDb

func (p *PostgresAdmin) CreateDb(dbName string) (err error)

func (*PostgresAdmin) CreateDbUser

func (p *PostgresAdmin) CreateDbUser(serviceUsername string, servicePassword string) (err error)

func (*PostgresAdmin) GrantPermission

func (p *PostgresAdmin) GrantPermission(serviceUsername string, dbAddr, dbAdminUsername, dbAdminPassword, dbName string) error

func (*PostgresAdmin) Session

func (p *PostgresAdmin) Session() *gorm.DB

Jump to

Keyboard shortcuts

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