Skip to content

BeechCMS


BeechCMS / @beechcms/core / ISchemaMutator

Interface: ISchemaMutator ​

Executes additive schema DDL against the live database and introspects columns. Implemented by D1SchemaMutator in apps/api/src/shared/schema-mutator.d1.ts. This is the ONLY sanctioned channel for runtime DDL — handlers never touch env.DB.

Methods ​

dropColumn() ​

dropColumn(table, column): Promise<void>

ALTER TABLE {table} DROP COLUMN {column}.

Parameters ​

table ​

string

column ​

string

Returns ​

Promise<void>


dropTable() ​

dropTable(table): Promise<void>

DROP TABLE IF EXISTS {table}.

Parameters ​

table ​

string

Returns ​

Promise<void>


execDdl() ​

execDdl(statements): Promise<void>

Runs the given DDL statements in order as a single D1 batch. All statements must be additive (CREATE … IF NOT EXISTS / ALTER … ADD COLUMN / CREATE INDEX IF NOT EXISTS). Throws on the first failing statement.

Parameters ​

statements ​

string[]

Returns ​

Promise<void>


execDestructive() ​

execDestructive(statements): Promise<void>

Runs a multi-statement destructive batch atomically (FTS rebuild, type-change column rebuild, full type drop). The caller assembles the statements; the impl validates identifiers and runs them as one D1 batch.

Parameters ​

statements ​

string[]

Returns ​

Promise<void>


fetchRows() ​

fetchRows(table, columns): Promise<Record<string, unknown>[]>

Reads all rows from a table for the specified columns only. Used before DROP TABLE to collect R2 keys for media cleanup. All identifiers are validated against ^[A-Za-z0-9_]+$.

Parameters ​

table ​

string

columns ​

string[]

Returns ​

Promise<Record<string, unknown>[]>


getColumns() ​

getColumns(table): Promise<Set<string> | null>

Column names currently on a table, or null if the table does not exist.

Parameters ​

table ​

string

Returns ​

Promise<Set<string> | null>


renameColumn() ​

renameColumn(table, from, to): Promise<void>

ALTER TABLE {table} RENAME COLUMN {from} TO {to}.

Parameters ​

table ​

string

from ​

string

to ​

string

Returns ​

Promise<void>


sumCounts() ​

sumCounts(statements): Promise<number>

Runs read-only SELECT COUNT(*) AS count statements as one batch and returns the summed count. Used to pre-check data compatibility before a lossy destructive operation.

Parameters ​

statements ​

string[]

Returns ​

Promise<number>