Documentation
¶
Index ¶
- Constants
- func CreateMigrationFile(dir string, cfg Config, name string, format string) (string, error)
- func DefaultConfigYAML(env map[string]string) string
- func GenerateSQL(key string, intent TableIntent, driver string) ([]string, error)
- func InitProject(dir string) error
- func InstallDBScaffoldSkill(dir string, force bool) (written, skipped []string, err error)
- func ReadDotEnv(path string) (map[string]string, error)
- func StatementsFor(migration Migration, direction Direction, driver string) ([]string, error)
- type AppliedMigration
- type Column
- type Config
- type DBConfig
- type Direction
- type ForeignIntent
- type IndexIntent
- type Migration
- type MigrationConfig
- type MigrationFile
- type MigrationStatus
- type RollbackOptions
- type Runner
- func (r *Runner) Close() error
- func (r *Runner) Dump(prune bool) error
- func (r *Runner) EnsureRepository() error
- func (r *Runner) Migrate(pretend bool) error
- func (r *Runner) MigrateDryRun() error
- func (r *Runner) Reset(pretend bool) error
- func (r *Runner) Rollback(opts RollbackOptions) error
- func (r *Runner) Status() ([]MigrationStatus, error)
- type SkillFile
- type TableIntent
Constants ¶
const DefaultConfigFile = "camel.yaml"
Variables ¶
This section is empty.
Functions ¶
func CreateMigrationFile ¶
func DefaultConfigYAML ¶
func GenerateSQL ¶
func GenerateSQL(key string, intent TableIntent, driver string) ([]string, error)
func InitProject ¶
func InstallDBScaffoldSkill ¶
InstallDBScaffoldSkill writes the bundled db-scaffold skill into dir (a target project root). Files that already exist are left untouched and reported as skipped unless force is true.
Types ¶
type AppliedMigration ¶
AppliedMigration is one recorded row in the migration tracking table.
type Column ¶
type Config ¶
type Config struct {
DB DBConfig `json:"db" yaml:"db"`
Migration MigrationConfig `json:"migration" yaml:"migration"`
}
func DefaultConfig ¶
func DefaultConfig() Config
func LoadConfig ¶
type ForeignIntent ¶
type ForeignIntent struct {
Name string `json:"name" yaml:"name"`
Columns []string `json:"columns" yaml:"columns"`
RefTable string `json:"references_table" yaml:"references_table"`
RefColumns []string `json:"references_columns" yaml:"references_columns"`
OnDelete string `json:"on_delete,omitempty" yaml:"on_delete,omitempty"`
OnUpdate string `json:"on_update,omitempty" yaml:"on_update,omitempty"`
}
ForeignIntent describes a foreign-key constraint added via ALTER.
type IndexIntent ¶
type IndexIntent struct {
Name string `json:"name" yaml:"name"`
Columns []string `json:"columns" yaml:"columns"`
Unique bool `json:"unique,omitempty" yaml:"unique,omitempty"`
}
IndexIntent describes a CREATE INDEX.
type Migration ¶
type Migration struct {
Path string
Name string
File MigrationFile
}
func LoadMigration ¶
type MigrationConfig ¶
type MigrationFile ¶
type MigrationFile struct {
Up map[string]TableIntent `json:"up" yaml:"up"`
Down map[string]TableIntent `json:"down" yaml:"down"`
}
type MigrationStatus ¶
type RollbackOptions ¶
type RollbackOptions struct {
Steps int // reverse the last N migrations; 0 means "last batch"
All bool // reverse every applied migration; overrides Steps
Pretend bool // print SQL without executing
}
RollbackOptions controls how many applied migrations Rollback reverses.
With the zero value, Rollback reverses the most recent batch (every migration sharing the highest batch number), matching the grouping that a single `migrate` run records. Steps overrides that to reverse exactly the last N applied migrations regardless of batch. All reverses everything (reset).
type Runner ¶
func (*Runner) Dump ¶
Dump writes the SQL for all applied migrations to schema.sql at the project root. With prune=true it also squashes: applied migration files are deleted, a 00000000000000_schema_dump.sql is written into the migrations directory (so `camel migrate` on a fresh DB runs it automatically), and the tracking table is reset so only the dump is recorded as applied.
func (*Runner) EnsureRepository ¶
func (*Runner) MigrateDryRun ¶
MigrateDryRun runs every pending migration's up statements against the real, configured database — inside a single transaction that is always rolled back — to catch failures that depend on the database's actual current state (a column that already exists, a NOT NULL column added to a table that already has rows, a foreign key whose target isn't really there). camel plan can't see any of that: it only renders SQL from the DSL, it never touches a connection. Nothing is committed and nothing is recorded in the tracking table, regardless of outcome.
Pending migrations run in order on one shared transaction (not one transaction per migration) so a later migration sees the tables/columns earlier ones in the same batch would have created — matching what a real `migrate` run would leave in place, right up until the final rollback.
MySQL is refused unconditionally: its DDL statements auto-commit, so a transaction rollback would not undo them — a "dry run" there would apply the changes for real while leaving the tracking table (and therefore a later `camel migrate`) out of sync with what actually happened.
func (*Runner) Rollback ¶
func (r *Runner) Rollback(opts RollbackOptions) error
func (*Runner) Status ¶
func (r *Runner) Status() ([]MigrationStatus, error)
type SkillFile ¶
SkillFile is one file the db-scaffold skill installs into a target project, mapping an embedded source path to a destination relative to the project root.
func DBScaffoldFiles ¶
func DBScaffoldFiles() []SkillFile
DBScaffoldFiles lists every file InstallDBScaffoldSkill writes. The same SKILL.md is installed for both Claude Code and Cursor (Cursor supports the identical Agent Skill format); the .mdc is a thin Cursor rule pointing at it, kept as a fallback for Cursor setups that only honor rules.
type TableIntent ¶
type TableIntent struct {
Table string `json:"table,omitempty" yaml:"table,omitempty"`
Action string `json:"action,omitempty" yaml:"action,omitempty"`
// create
Columns map[string]string `json:"columns,omitempty" yaml:"columns,omitempty"`
Indexes []IndexIntent `json:"indexes,omitempty" yaml:"indexes,omitempty"`
Foreign []ForeignIntent `json:"foreign,omitempty" yaml:"foreign,omitempty"`
// raw: statements executed verbatim, in order (action: raw)
Statements []string `json:"statements,omitempty" yaml:"statements,omitempty"`
// alter
AddColumns map[string]string `json:"add_columns,omitempty" yaml:"add_columns,omitempty"`
DropColumns []string `json:"drop_columns,omitempty" yaml:"drop_columns,omitempty"`
ModifyColumns map[string]string `json:"modify_columns,omitempty" yaml:"modify_columns,omitempty"`
RenameColumns map[string]string `json:"rename_columns,omitempty" yaml:"rename_columns,omitempty"`
AddIndexes []IndexIntent `json:"add_indexes,omitempty" yaml:"add_indexes,omitempty"`
DropIndexes []string `json:"drop_indexes,omitempty" yaml:"drop_indexes,omitempty"`
AddForeign []ForeignIntent `json:"add_foreign,omitempty" yaml:"add_foreign,omitempty"`
DropForeign []string `json:"drop_foreign,omitempty" yaml:"drop_foreign,omitempty"`
}