Skip to content

Migrations

Lucent automatically handles schema migrations for you based on your collection definitions.

Automatic Migrations

By default, when you run your server in development mode using lucent dev, Lucent will automatically:

  1. Compare your defineCollection models with the actual database schema.
  2. Generate and execute the necessary SQL or database commands to sync the two.
  3. Keep track of which fields were added, modified, or removed.

Manual Migrations

You can also trigger migrations manually using the CLI:

bash
lucent migrate

This is useful for production deployments or when you want to ensure the database is up-to-date before starting the application.

How it Works

Lucent's migration engine is adapter-specific. It uses the lucent_migrations table in your database to keep track of applied changes, ensuring that the same migration is never run twice.

Supported Operations

  • Collection creation: Automatically creates new tables or collections.
  • Field addition: Adds new columns or properties.
  • Index management: Automatically creates unique or common indexes based on field configuration (e.g., unique: true).
  • Default values: Applies default values to new and existing records when possible.

Released under the MIT License.