dbstrap

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 7 Imported by: 0

README

db-bootstrap

A CLI tool for bootstrapping PostgreSQL databases, users, schemas, and extensions from a YAML configuration. Powered by Golang and kong CLI library.

Features

  • Create users with login privileges
  • Set user roles and ownerships
  • Bootstrap databases with custom encoding, collation, and templates
  • Create schemas with specific grants
  • Install database extensions
  • Manage grants at both database and schema levels

Installation

Clone the repo and build the CLI:

go install github.com/tendant/dbstrap/cmd/dbstrap@latest

Run from binary

export DATABASE_URL=postgres://postgres:pwd@localhost:5432/postgres
export TEST_USER_PASSWORD=pass123
dbstrap run --config=samples/bootstrap.yaml

How to run from source

  1. Set environment variables:

    export DATABASE_URL=postgres://postgres:pwd@localhost:5432/postgres
    export TEST_USER_PASSWORD=pass123
    
    
  2. Create your config file (bootstrap.yaml):

See the Sample Config section for a working example.

  1. Run the CLI:

    go run ./cmd/dbstrap run --config=samples/bootstrap.yaml

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultYAML []byte

Functions

func BootstrapDatabase

func BootstrapDatabase(yamlData []byte) error

Types

type Config

type Config struct {
	Users     []User     `yaml:"users"`
	Databases []Database `yaml:"databases"`
}

type Database

type Database struct {
	Name       string          `yaml:"name"`
	Owner      string          `yaml:"owner"`
	Encoding   string          `yaml:"encoding"`
	LcCollate  string          `yaml:"lc_collate"`
	LcCtype    string          `yaml:"lc_ctype"`
	Template   string          `yaml:"template"`
	Extensions []string        `yaml:"extensions"`
	Grants     []DatabaseGrant `yaml:"grants"`
	Schemas    []Schema        `yaml:"schemas"`
}

type DatabaseGrant

type DatabaseGrant struct {
	User       string   `yaml:"user"`
	Privileges []string `yaml:"privileges"`
}

type Schema

type Schema struct {
	Name   string        `yaml:"name"`
	Owner  string        `yaml:"owner"`
	Grants []SchemaGrant `yaml:"grants"`
}

type SchemaGrant

type SchemaGrant struct {
	User       string   `yaml:"user"`
	Privileges []string `yaml:"privileges"`
}

type User

type User struct {
	Name        string   `yaml:"name"`
	PasswordEnv string   `yaml:"password_env"`
	Password    string   // populated at runtime
	CanLogin    bool     `yaml:"can_login"`
	OwnsSchemas []string `yaml:"owns_schemas"`
	Roles       []string `yaml:"roles"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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