Migrator
dropTable()
Signature
Section titled “Signature”dropTable() — returns void
Available in: migration
Category: Migration Functions
Description
Section titled “Description”Drops a table from the database Only available in a migration CFC
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | yes | — | Name of the table to drop |
Examples
Section titled “Examples”// 1. Drop a table in the down() migration (reversing a createTable in up())
component extends="wheels.migrator.Migration" hint="Add products table" {
function up() {
t = createTable(name="products");
t.string(columnNames="name", allowNull=false);
t.decimal(columnNames="price", precision=10, scale=2);
t.boolean(columnNames="active", default=1);
t.timestamps();
t.create();
}
function down() {
dropTable("products");
}
}
// 2. Drop multiple tables in a single down() migration
component extends="wheels.migrator.Migration" hint="Add orders and line items tables" {
function up() {
t = createTable(name="lineItems");
t.integer(columnNames="orderId");
t.integer(columnNames="productId");
t.integer(columnNames="quantity");
t.timestamps();
t.create();
t = createTable(name="orders");
t.integer(columnNames="userId");
t.string(columnNames="status");
t.timestamps();
t.create();
}
function down() {
dropTable("lineItems");
dropTable("orders");
}
}