ALTER ENTITY
ALTER ENTITY modifies an existing entity’s attributes, indexes, or documentation without recreating it. This is useful for incremental changes to entities that already contain data.
ADD Attributes
Add one or more new attributes:
ALTER ENTITY Sales.Customer
ADD (Phone: String(50), Notes: String(unlimited));
New attributes support the same constraints as in CREATE ENTITY:
ALTER ENTITY Sales.Customer
ADD (
LoyaltyPoints: Integer DEFAULT 0,
MemberSince: DateTime NOT NULL
);
DROP Attributes
Remove one or more attributes:
ALTER ENTITY Sales.Customer
DROP (Notes);
Multiple attributes can be dropped at once:
ALTER ENTITY Sales.Customer
DROP (Notes, TempField, OldStatus);
MODIFY Attributes
Change the type or constraints of existing attributes:
ALTER ENTITY Sales.Customer
MODIFY (Name: String(400) NOT NULL);
RENAME Attributes
Rename an attribute:
ALTER ENTITY Sales.Customer
RENAME Phone TO PhoneNumber;
ADD INDEX
Add an index to the entity:
ALTER ENTITY Sales.Customer
ADD INDEX (Email);
Composite indexes:
ALTER ENTITY Sales.Customer
ADD INDEX (Name, CreatedAt DESC);
DROP INDEX
Remove an index:
ALTER ENTITY Sales.Customer
DROP INDEX (Email);
SET DOCUMENTATION
Update the entity’s documentation text:
ALTER ENTITY Sales.Customer
SET DOCUMENTATION 'Customer master data for the Sales module';
ADD/DROP System Attributes
System attributes use the same ADD/DROP syntax as regular attributes:
-- Add system attributes
ALTER ENTITY Sales.Order ADD ATTRIBUTE Owner: AutoOwner;
ALTER ENTITY Sales.Order ADD ATTRIBUTE ChangedBy: AutoChangedBy;
ALTER ENTITY Sales.Order ADD ATTRIBUTE CreatedDate: AutoCreatedDate;
ALTER ENTITY Sales.Order ADD ATTRIBUTE ChangedDate: AutoChangedDate;
-- Drop system attributes (by name)
ALTER ENTITY Sales.Order DROP ATTRIBUTE Owner;
ALTER ENTITY Sales.Order DROP ATTRIBUTE ChangedDate;
ADD/DROP EVENT HANDLER
Register microflows to run before or after entity operations:
-- Before commit: validates and can abort (RAISE ERROR)
ALTER ENTITY Sales.Order
ADD EVENT HANDLER ON BEFORE COMMIT CALL Sales.ValidateOrder($currentObject) RAISE ERROR;
-- After commit: runs after successful commit (no RAISE ERROR)
ALTER ENTITY Sales.Order
ADD EVENT HANDLER ON AFTER COMMIT CALL Sales.LogOrderChange($currentObject);
-- Without passing the entity object
ALTER ENTITY Sales.Order
ADD EVENT HANDLER ON AFTER CREATE CALL Sales.NotifyNewOrder();
-- Remove an event handler
ALTER ENTITY Sales.Order
DROP EVENT HANDLER ON BEFORE COMMIT;
| Moment | Returns | RAISE ERROR | Use case |
|---|---|---|---|
BEFORE | Boolean | Yes — aborts on false | Validation, permission checks |
AFTER | Void | No | Logging, notifications, side effects |
Events: CREATE, COMMIT, DELETE, ROLLBACK
Parameter: ($currentObject) passes the entity to the microflow, () does not.
Syntax Summary
ALTER ENTITY <Module>.<Entity>
ADD (<attribute-definition> [, ...])
ALTER ENTITY <Module>.<Entity>
DROP (<attribute-name> [, ...])
ALTER ENTITY <Module>.<Entity>
MODIFY (<attribute-definition> [, ...])
ALTER ENTITY <Module>.<Entity>
RENAME <old-name> TO <new-name>
ALTER ENTITY <Module>.<Entity>
ADD INDEX (<column-list>)
ALTER ENTITY <Module>.<Entity>
DROP INDEX (<column-list>)
ALTER ENTITY <Module>.<Entity>
SET DOCUMENTATION '<text>'
ALTER ENTITY <Module>.<Entity>
SET POSITION (<x>, <y>)
See Also
- Entities – CREATE ENTITY syntax
- Attributes – attribute definition format
- Indexes – index creation and management
- Constraints – NOT NULL, UNIQUE, DEFAULT