Introduction
An Open Mercato application keeps its business records in PostgreSQL. An entity describes one kind of thing the application remembers, such as a customer or an order. A record is one particular customer or order, with an identifier that stays the same as its details change.
In a standard deployment the enabled modules share a PostgreSQL database. Each module defines the structure of the records it owns. Customers maps its customer records to customer_entities. Sales maps orders to sales_orders and their lines to sales_order_lines. These tables can sit alongside each other in the same database. A module boundary describes who maintains the data and the rules for changing it.
A sales order can refer to a customer by ID and also hold a snapshot of the customer details used on the document. Those fields answer different questions. The ID leads to the current customer. The snapshot lets Sales display the information saved with that order. Sales data model
A tenant identifies a distinct customer environment of the application. Organizations divide work within that tenant. On records scoped to an organization, the application uses the tenant and organization IDs to select the right rows. A role governs what a person may do with those rows. Someone who can view a company's orders may still need another permission to edit them. Permissions and organization scope
A preferred delivery window can be a custom field on a company. A series of service visits deserves its own records. Each visit has a date, an assignee and a status, and rescheduling one should leave the others intact.
For an extra attribute on a supported record, use a custom field. The platform also supports custom entity types defined through its entity settings. For a record whose structure and behavior you intend to maintain in code, define a typed MikroORM entity inside your module and version its database changes with migrations. Entities and migrations
The classic starter includes example:todo. In src/modules/example/data/entities.ts, the Todo class maps to the todos table. In ce.ts, the module declares extra fields. The API under api/todos/route.ts chooses which data to return. Its screens live in backend/todos/. Open the files in that order to follow one record from storage to form. See the released example module
When you add your own typed entity, decide which fields are mandatory, whether the record belongs to a tenant or organization, and which IDs it refers to. Generate its migration, review the SQL, and apply it to a development database. Build the inventory data model
Previous: Welcome to Open Mercato · Next: What a module owns