Documentation
¶
Overview ¶
Package config reads and writes the project registry used by wtm.
Index ¶
- Constants
- func BackupsDir() (string, error)
- func Dir() (string, error)
- func Expand(s, database string) string
- func Path() (string, error)
- type Backup
- type Config
- func (c *Config) BaseBranchFor(p Project) string
- func (c *Config) Get(name string) (Project, error)
- func (c *Config) Has(name string) bool
- func (c *Config) Names() []string
- func (c *Config) NextPortOffset() int
- func (c *Config) ResolveCurrent(repoRoot string) (string, Project, error)
- func (c *Config) Save(path string) error
- type Project
Constants ¶
const ( EnvConfigDir = "WTM_CONFIG_DIR" EnvBackupsDir = "WTM_BACKUPS_DIR" )
Environment overrides, mostly so tests never touch the real home directory.
const ( DefaultDBService = "db" DefaultDBUser = "postgres" // DefaultMigrationsPath covers Django's app/migrations, Prisma's // prisma/migrations and MikroORM's src/database/migrations. DefaultMigrationsPath = "*migrations/*" // DatabasePlaceholder is replaced by the throwaway database name in // migrate_command and in every env value. DatabasePlaceholder = "{{database}}" )
Defaults for the most common docker compose layout.
const FallbackBaseBranch = "develop"
FallbackBaseBranch applies when neither the project nor the config names one.
Variables ¶
This section is empty.
Functions ¶
func BackupsDir ¶
BackupsDir is the single place where dumps are stored, shared by every worktree through a symlink.
Types ¶
type Backup ¶
type Backup struct {
DBService string `json:"db_service,omitempty"` // default "db"
DBUser string `json:"db_user,omitempty"` // default "postgres"
AppService string `json:"app_service,omitempty"` // required
// DepsCommand runs before the migration in the disposable container, for
// projects that install their dependencies at container startup rather
// than baking them into the image (a fresh container has none).
DepsCommand string `json:"deps_command,omitempty"`
// MigrateCommand builds the schema, e.g. "python manage.py migrate",
// "npx prisma migrate deploy", "mikro-orm migration:up". Required.
MigrateCommand string `json:"migrate_command,omitempty"`
// MigrationsPath is the git pathspec of the migration files, used to tell
// whether a dump has fallen behind. The default matches the layout of
// Django, Prisma and MikroORM alike.
MigrationsPath string `json:"migrations_path,omitempty"`
// Env tells the app which database to target: {"DB_NAME": "{{database}}"}
// or {"DATABASE_URL": "postgresql://user:pass@db:5432/{{database}}"}.
Env map[string]string `json:"env,omitempty"`
}
Backup describes how to rebuild a schema. Everything here differs from one project to the next: a survey of four real projects found four different migration commands, three app service names, two database service names, two database users and two ways of telling the app which database to use.
type Config ¶
type Config struct {
DefaultBaseBranch string `json:"default_base_branch,omitempty"`
Projects map[string]Project `json:"projects"`
}
Config is the whole registry.
func (*Config) BaseBranchFor ¶
BaseBranchFor applies the project > config > fallback precedence.
func (*Config) Has ¶
Has reports whether a name is registered, which is how the CLI tells a project argument from a branch argument.
func (*Config) NextPortOffset ¶
NextPortOffset returns a free offset for a new project, in steps of 1000. The first project keeps 0 so its existing worktrees are untouched.
func (*Config) ResolveCurrent ¶
ResolveCurrent finds the project whose dir is the given repository root.
type Project ¶
type Project struct {
Dir string `json:"dir"`
BaseBranch string `json:"base_branch,omitempty"`
Dump bool `json:"dump,omitempty"`
// GitContainer creates the .git-container symlinks. Opt-in: it only helps
// projects whose compose bind-mounts the git directory into a container
// (macOS/VirtioFS cannot mount the pointer file a linked worktree uses).
GitContainer bool `json:"git_container,omitempty"`
// PortOffset shifts every rebased port of this project. The allocation
// formula only knows the default port, the worktree index and the stride,
// so without it two projects whose database listens on 5432 would fight
// over the same host port. Zero for the first project, which keeps the
// ports it already had.
PortOffset int `json:"port_offset,omitempty"`
Backup *Backup `json:"backup,omitempty"`
}
Project is one registered repository.
func (Project) BackupConfig ¶
BackupConfig returns the project's backup settings with defaults applied.