Documentation
¶
Overview ¶
Package ddl is SupaCraft's SQLite DDL engine. It deliberately only supports
- CREATE TABLE IF NOT EXISTS for new tables.
- ALTER TABLE ADD COLUMN for new columns on existing tables.
Column drops, renames, and type changes are not handled — they would require SQLite's "table rebuild" dance (rename → create new → INSERT … SELECT → drop old) which is non-trivial when foreign keys or triggers exist. Users running into a destructive schema change can delete the SQLite file and re-apply.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
UUID string
Name string
Type string
Params map[string]any
Nullable bool
Unique bool
Primary bool
Default *string
}
Column represents a schema column parsed from the config JSON.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor runs DDL on tenant SQLite databases.
func NewExecutor ¶
func (*Executor) ConnectTenant ¶
ConnectTenant returns a *sql.DB for the named tenant — used by PlanMigration to introspect existing tables. Caller is responsible for closing.
type Operation ¶
Operation is a single DDL operation produced by PlanMigration. Only Desc and the raw SQL matter to the executor.
func PlanMigration ¶
PlanMigration computes the additive DDL operations needed to bring the tenant DB schema in line with newTables. It introspects the live DB (sqlite_master + pragma_table_info) and emits CREATE TABLE for missing tables and ALTER TABLE ADD COLUMN for columns that aren't already there.
The live DB, not a previously applied config, is the source of truth: columns added by side channels — notably the auth migration in internal/sqlitedb/provision.go, which creates users(id, email, password, …) before this runs — must not be re-ADDed.
Drops, renames, and type changes are intentionally ignored — see the package doc.
type Table ¶
Table represents a schema table parsed from the config JSON.
func ParseSchema ¶
ParseSchema converts the config schema JSON shape into our Table list. The schema is expected as map[string]any with keys "tables" → []any.