Documentation
¶
Index ¶
- func DefaultPostgresCredentials() (user, password, database string)
- func FormatConnectionString(host, port, user, password, database string) string
- func HasSqlDatabaseResources(bp *schema.Blueprint) bool
- func ResourceType() string
- type Applier
- func (a *Applier) ApplyAll(ctx context.Context, schemaPath, migrationsPath, engine string) error
- func (a *Applier) ApplyMigrations(ctx context.Context, migrationsPath string) error
- func (a *Applier) ApplySchema(ctx context.Context, schemaPath string, engine string) error
- func (a *Applier) Close() error
- func (a *Applier) EnsureDatabase(ctx context.Context, dbName string) error
- func (a *Applier) ExecSQL(ctx context.Context, sqlContent string) error
- func (a *Applier) ForDatabase(dbName string) (*Applier, error)
- func (a *Applier) RollbackAll(ctx context.Context, schemaPath, migrationsPath, engine string) error
- func (a *Applier) RollbackMigrations(ctx context.Context, migrationsPath string) error
- func (a *Applier) RollbackSchema(ctx context.Context, schemaPath string, engine string) error
- type Column
- type Constraint
- type DDLResult
- type DatabaseResource
- type ForeignKey
- type Index
- type MigrationScript
- type Schema
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPostgresCredentials ¶
func DefaultPostgresCredentials() (user, password, database string)
DefaultPostgresCredentials returns the default local dev credentials for PostgreSQL containers.
func FormatConnectionString ¶
FormatConnectionString builds a PostgreSQL connection string from components.
func HasSqlDatabaseResources ¶
HasSqlDatabaseResources returns true if the blueprint contains any celerity/sqlDatabase resources.
func ResourceType ¶
func ResourceType() string
ResourceTypeSqlDatabase is the blueprint resource type for SQL databases. Exported for use by the compose generator.
Types ¶
type Applier ¶
type Applier struct {
// contains filtered or unexported fields
}
Applier applies SQL schemas and migration scripts to a database. It tracks applied migrations in a celerity_schema_migrations table. Engine-specific SQL is delegated to a dialect implementation.
func NewApplier ¶
NewApplier creates an Applier for the given engine and connection string.
func (*Applier) ApplyAll ¶
ApplyAll applies schema DDL (up) followed by pending migration up scripts.
func (*Applier) ApplyMigrations ¶
ApplyMigrations discovers and executes pending up migration scripts in version order.
func (*Applier) ApplySchema ¶
ApplySchema parses a schema YAML file and executes the up DDL statements.
func (*Applier) EnsureDatabase ¶
EnsureDatabase creates a database if it does not already exist. Must be called on an Applier connected to the admin database.
func (*Applier) ForDatabase ¶
ForDatabase returns a new Applier connected to a specific database, derived from the original connection string by replacing the database path.
func (*Applier) RollbackAll ¶
RollbackAll rolls back applied migrations (down, reverse order) then schema DDL (down).
func (*Applier) RollbackMigrations ¶
RollbackMigrations discovers and executes down migration scripts in reverse version order.
type Column ¶
type Column struct {
Type string `yaml:"type"`
PrimaryKey bool `yaml:"primaryKey"`
Nullable bool `yaml:"nullable"`
Unique bool `yaml:"unique"`
Default string `yaml:"default"`
Description string `yaml:"description"`
Classification string `yaml:"classification"`
References *ForeignKey `yaml:"references"`
}
Column describes a single table column with engine-native type.
type Constraint ¶
type Constraint struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Expression string `yaml:"expression"`
Columns []string `yaml:"columns"`
}
Constraint describes a table constraint (check, unique, composite foreign key).
type DDLResult ¶
DDLResult holds both up (create) and down (drop) DDL statements.
func GenerateDDL ¶
GenerateDDL produces ordered up and down DDL statements from a parsed schema. The engine parameter is validated (v0: "postgres" only).
Up statements are in dependency order: 1. Extensions 2. Tables (CREATE TABLE) 3. Foreign keys (ALTER TABLE ADD CONSTRAINT) 4. Indexes (CREATE INDEX) 5. Check constraints
Down statements are in reverse dependency order: 1. Check constraints (DROP) 2. Indexes (DROP) 3. Foreign keys (DROP) 4. Tables (DROP) — reverse alphabetical 5. Extensions (DROP)
type DatabaseResource ¶
type DatabaseResource struct {
ResourceName string
Name string
Engine string
SchemaPath string
MigrationsPath string
AuthMode string
}
DatabaseResource holds the resolved configuration for a celerity/sqlDatabase blueprint resource. Paths are resolved to absolute paths.
func CollectDatabaseResources ¶
func CollectDatabaseResources(bp *schema.Blueprint, projectRoot string) []DatabaseResource
CollectDatabaseResources extracts celerity/sqlDatabase resources from a blueprint and resolves schema/migration paths relative to the project root.
type ForeignKey ¶
type ForeignKey struct {
Table string `yaml:"table"`
Column string `yaml:"column"`
OnDelete string `yaml:"onDelete"`
}
ForeignKey describes a foreign key reference from a column.
type Index ¶
type Index struct {
Name string `yaml:"name"`
Columns []string `yaml:"columns"`
Unique bool `yaml:"unique"`
}
Index describes a table index.
type MigrationScript ¶
MigrationScript represents a versioned SQL migration with up/down files (V<number>__<description>.up.sql / V<number>__<description>.down.sql).
func DiscoverMigrationScripts ¶
func DiscoverMigrationScripts(migrationsPath string) ([]MigrationScript, error)
DiscoverMigrationScripts finds versioned SQL migration pairs (V<number>__<description>.up.sql / V<number>__<description>.down.sql) in the given directory, sorted by version number.
type Schema ¶
type Schema struct {
Tables map[string]Table `yaml:"tables"`
Extensions []string `yaml:"extensions"`
}
Schema represents a parsed SQL database schema YAML file. Column types are engine-native (e.g. "serial", "varchar(50)", "jsonb").
func ParseSchema ¶
ParseSchema parses a SQL schema YAML from a reader.
func ParseSchemaFile ¶
ParseSchemaFile reads and parses a SQL schema YAML file from disk.