Migrator
removeRecord()
Signature
Section titled “Signature”removeRecord() — returns void
Available in: migration
Category: Migration Functions
Description
Section titled “Description”Removes existing records from a table Only available in a migration CFC
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
table | string | yes | — | The table name to remove the record from |
where | string | no | — | The where clause, i.e id = 123. Raw SQL — callers must supply a predicate or all=true. |
all | boolean | no | false | When true, an empty where deletes every row. Default false (fail-closed). |
Examples
Section titled “Examples”// 1. Remove all records from a table (use with caution)
removeRecord(table = "sessions");
// 2. Remove a specific record by primary key
removeRecord(table = "roles", where = "id = 1");
// 3. Remove multiple records matching a condition
removeRecord(table = "users", where = "active = 0");
// 4. Use removeRecord in a migration's down() function to reverse an addRecord call
component extends="wheels.migrator.Migration" {
function up() {
addRecord(
table = "settings",
name = "maintenanceMode",
value = "false"
);
}
function down() {
removeRecord(table = "settings", where = "name = 'maintenanceMode'");
}
}