ddl

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ddl is SupaCraft's SQLite DDL engine. It deliberately only supports

  1. CREATE TABLE IF NOT EXISTS for new tables.
  2. 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 NewExecutor(cfg *config.Config) *Executor

func (*Executor) ConnectTenant

func (e *Executor) ConnectTenant(ctx context.Context, dbName string) (*sql.DB, error)

ConnectTenant returns a *sql.DB for the named tenant — used by PlanMigration to introspect existing tables. Caller is responsible for closing.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, dbName string, stmts []string) error

Execute runs a list of raw SQL statements in a single transaction.

func (*Executor) ExecuteOperations

func (e *Executor) ExecuteOperations(ctx context.Context, dbName string, ops []Operation) error

ExecuteOperations runs a list of Operations (just the SQL field) inside one transaction.

type Operation

type Operation struct {
	Desc string
	SQL  string
}

Operation is a single DDL operation produced by PlanMigration. Only Desc and the raw SQL matter to the executor.

func PlanMigration

func PlanMigration(ctx context.Context, db *sql.DB, newTables []Table) ([]Operation, error)

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

type Table struct {
	UUID    string
	Name    string
	Columns []Column
}

Table represents a schema table parsed from the config JSON.

func ParseSchema

func ParseSchema(raw any) ([]Table, error)

ParseSchema converts the config schema JSON shape into our Table list. The schema is expected as map[string]any with keys "tables" → []any.

Jump to

Keyboard shortcuts

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