Migrations
Loopar automatically manages database schema changes through its Entity system. When you create or modify an Entity, the database schema is automatically synchronized.Automatic Schema Management
Loopar uses Sequelize to automatically create and alter database tables based on your Entity definitions. This eliminates the need for manual migration files.How It Works
Table Creation
When a new Entity is created, Loopar automatically creates the corresponding database table:packages/db-env/database/core/sequelize/core.js
Creating Tables
packages/db-env/database/core/sequelize/core.js
Altering Tables
When you add new fields to an Entity, Loopar automatically adds the corresponding columns:packages/db-env/database/core/sequelize/core.js
Column SQL Generation
Loopar generates appropriate SQL for each field type:packages/db-env/database/core/sequelize/core.js
Type Mapping
Loopar maps field types to appropriate SQL types for each database:packages/db-env/database/core/sequelize/core.js
Index Management
Loopar automatically creates indexes for fields marked withindex: true or unique: true:
packages/db-env/database/core/sequelize/core.js
Database Schema Operations
Check if Table Exists
packages/db-env/database/core/sequelize/core.js
Get Table Description
packages/db-env/database/core/sequelize/core.js
Database Management
Create Database
packages/db-env/database/core/sequelize/core.js
Drop Database
packages/db-env/database/core/sequelize/core.js
Best Practices
Migration Workflow
- Define your Entity structure with the desired fields
- Save the Entity - Loopar automatically creates or alters the table
- Verify the schema by checking the database
- Test your changes with sample data
Handling Breaking Changes
Transaction Support
Use transactions for multiple related schema changes:Next Steps
Models
Learn about model definitions
Queries
Query data from your models