Skip to content

Migrator

up()

up() — returns void

Available in: migration Category: Migration Functions

Defines the actions to migrate your database schema forward. It is called when applying a migration and is typically paired with the down() function, which rolls back the migration. All schema changes, such as creating tables, adding columns, or setting up indexes, should be placed inside up(). Wrapping your migration code in a transaction block ensures that changes are either fully applied or rolled back in case of errors. Only available in a migration CFC.

function up() {
	transaction {
		try {
			// your code goes here
			t = createTable(name='myTable');
			t.timestamps();
			t.create();
		} catch (any e) {
			local.exception = e;
		}

		if (StructKeyExists(local, "exception")) {
			transaction action="rollback";
			throw(errorCode="1", detail=local.exception.detail, message=local.exception.message, type="any");
		} else {
			transaction action="commit";
		}
	}
}