Data Models

Define your application's data structure with models

Data Models

Models are the foundation of your Appivo application. Each model represents a type of data in your application and automatically becomes a database table.

What is a Model?

A Model defines a type of business object in your application, such as:

  • Customer
  • Order
  • Product
  • Task
  • Invoice

When you create a model, Appivo automatically:

  • Creates the database table
  • Generates CRUD operations
  • Provides API endpoints
  • Handles data persistence

Creating a Model

  1. Navigate to the Models section in the Application Builder
  2. Click Add Model
  3. Enter a name for your model
  4. Add attributes (fields)
  5. Save your model

Example: Customer Model

Model: Customer
├── Attributes (Fields)
│   ├── name (Text, required)
│   ├── email (Email, unique)
│   ├── phone (Phone)
│   └── status (Selection: active/inactive)
├── Relationships
│   └── orders (one-to-many with Order model)
└── System Fields (Automatic)
    ├── id (unique identifier)
    ├── created_at (creation timestamp)
    ├── updated_at (last modification)
    └── ver (version for conflict resolution)

Attribute Types

When adding attributes to your model, choose from these data types:

Basic Types

TypeDescriptionExample
TextShort text, up to 255 charactersName, title
Long TextExtended text for descriptionsBio, notes
IntegerWhole numbersAge, quantity
DecimalNumbers with decimal placesPrice, rating
BooleanTrue/false valuesActive, completed
DateDate without timeBirth date
DateTimeDate with timeAppointment
TimeTime without dateStart time

Specialized Types

TypeDescriptionExample
EmailValidated email addressesContact email
PhonePhone numbers with formattingMobile number
URLWeb addressesWebsite link
CurrencyMonetary valuesPrice, total
PasswordEncrypted password storageUser password
FileFile attachmentsDocuments
ImageImage uploads with previewProfile photo
SelectionPredefined optionsStatus, priority

Validation Rules

Protect data integrity with validation:

ValidationDescription
RequiredField must have a value
UniqueNo duplicate values allowed
Min LengthMinimum text length
Max LengthMaximum text length
Min ValueMinimum numeric value
Max ValueMaximum numeric value
PatternRegular expression matching

Example: Validated Customer Model

Attribute: email
Type: Email
Validations:
  - Required: true
  - Unique: true
  - Pattern: Must be company domain

Attribute: name
Type: Text
Validations:
  - Required: true
  - Min Length: 2
  - Max Length: 100

Relationships

Connect models together to build complex data structures.

One-to-Many

One record in the parent model relates to many records in the child model.

Customer (1) ──────> (*) Orders
One customer can have many orders

Many-to-Many

Records in both models can relate to multiple records in the other.

Students (*) <────> (*) Courses
Students can enroll in multiple courses
Courses can have multiple students

One-to-One

Each record relates to exactly one record in another model.

User (1) ────── (1) Profile
Each user has exactly one profile

System Fields

Every model automatically includes these system fields:

FieldDescription
idUnique identifier for each record
created_atWhen the record was created
updated_atWhen the record was last modified
verVersion number for optimistic locking

These fields are managed automatically by Appivo and cannot be modified directly.

Indexes

Appivo automatically creates indexes for:

  • Primary keys (id field)
  • Foreign keys (relationship fields)
  • Unique constraints

You can add custom indexes for frequently searched fields to improve query performance.

Best Practices

Naming Conventions

  • Use clear, descriptive names
  • Use singular nouns (Customer, not Customers)
  • Avoid abbreviations unless widely understood

Design Principles

  • Normalize data: Avoid storing the same information in multiple places
  • Plan relationships: Think about how models connect before building
  • Set validations early: Define rules from the start
  • Index search fields: Add indexes for frequently queried fields

Common Patterns

Reference Data Create models for lookup values:

Model: Status
- name (Text)
- display_order (Integer)

Audit Trail Track changes with audit models:

Model: ActivityLog
- action (Selection: create/update/delete)
- model_name (Text)
- record_id (Text)
- user (Reference to User)
- timestamp (DateTime)

Next Steps