migrations

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package migrations gathers the steps that aicoded dev and aicoded check apply to an app's database on the builder's computer: the migrations the app published, fetched from the platform and cached in .aicoded/migrations.json, then the statements of its draft, .aicoded/migration.sql, as steps of the publish "draft". It also clears the draft once a publish that carried it passed. The cache holds steps and the publish that carried the draft, never a token.

Index

Constants

View Source
const (
	// Cache is where an app keeps the migrations it published, relative to its folder.
	Cache = ".aicoded/migrations.json"
	// Draft is the publish of the steps of the draft.
	Draft = "draft"
)

Variables

View Source
var ErrUseCache = errors.New("use the cache")

ErrUseCache is the error of a Platform whose answer is the cache.

Functions

func Append

func Append(steps []migrate.Step, pub string, stmts []string) []migrate.Step

Append returns steps followed by stmts, as the steps of the publish pub, numbered on.

func Forget

func Forget(dir, id string) error

Forget makes the cache of the app in dir stop waiting for the publish id, which the platform does not know, and leaves the draft as it is.

func MarkSent

func MarkSent(dir, id string, text []byte) error

MarkSent keeps in the cache of the app in dir that the publish id carried text, the draft.

func Pending

func Pending(dir string) string

Pending returns the publish that carried the draft of the app in dir and has no outcome yet, as far as the cache knows, or "".

func Published

func Published(ctx context.Context, dir, app string, p Platform) (steps []migrate.Step, warning string)

Published returns the steps of the migrations that the app app in dir published, as Steps does. When the platform lists none but the cache holds some, or the answer is the cache and it cannot be read, warning says so. When p is not signed in, E-CLI-004, warning starts with that error rather than with the platform it could not ask.

func Settle

func Settle(ctx context.Context, dir, app, id, status string, p Platform) (string, error)

Settle ends the wait of the cache of the app app in dir for the publish id, which ended with status. When the publish carried the draft and passed, Settle deletes the draft, unless it changed since, and caches the published migrations from p. Whatever the outcome, the cache forgets the publish. It returns a line for the builder about the draft, or "" when the publish did not carry it.

func Steps

func Steps(ctx context.Context, dir string, m manifest.Manifest, p Platform) (steps []migrate.Step, warning string, err error)

Steps returns the steps to apply to a database of the app in dir whose permission list is m: those it published, then its draft's. The published ones come from p, and are cached; when p is nil, from the cache. When p cannot give them, they come from the cache, or there are none, and warning says so in one line. A draft that a publish carried, unchanged, adds no step once that publish's steps are among the published ones, before Settle clears it. Its error is that of draft.Check.

Types

type Platform

type Platform interface {
	Migrations(ctx context.Context, app string) ([]migrate.Step, error)
}

Platform returns the steps of the migrations that an app published, as the platform's client does. A Platform that has nothing newer than the cache to give returns ErrUseCache.

Jump to

Keyboard shortcuts

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