Database Migration

While your pipeline logic is dynamically discovered by the code, the Admin Dashboard requires the pipeline to be registered in the database to display it in the user interface.

Quick Summary

After generating your pipeline with make new-pipeline, simply run:

make migrate

That's it! The migration automatically:

  • Registers your pipeline across all organizations

  • Creates necessary components and presets

  • Sets up default configuration fields

  • Prepares everything for the Admin Dashboard

No modification needed unless you want to add custom configuration fields (which also requires creating a PresetConfig class).


Overview

When you use the make new-pipeline CLI tool, a migration file is automatically created for you in migration/versions/ with fully functional upgrade() and downgrade() functions. In most cases, you don't need to modify the generated migration file - it's ready to use as-is.

The generated migration handles:

  • Pipeline registration across all organizations (multi-tenancy support)

  • Component creation and linking

  • Preset creation with default configuration

  • Configuration fields and values setup

  • Catalog creation for prompt builders and language models

  • Chatbot application creation (for non-global pipelines)

Migration File Structure

The CLI tool generates a migration file with the following structure:

The file includes:

  • Proper Alembic revision tracking with 12-character hex revision ID

  • Auto-detected down_revision from the latest migration

  • Fully implemented upgrade() and downgrade() functions - ready to use!

  • Comprehensive pipeline setup for all organizations

  • Built-in multi-tenancy support

  • Default configuration fields with customization examples

Applying the Migration

The generated migration file is ready to use. Simply apply it:

This will:

  1. Create the pipeline for all organizations in your system

  2. Set up all required components and presets

  3. Configure default settings

  4. Create catalogs and chatbot applications

The migration is ready to use as-is! You don't need to modify it unless you want to add custom configuration fields.

chevron-rightWhat does the generated migration look like?hashtag

The CLI tool generates a comprehensive migration file that handles all aspects of pipeline registration:

The migration uses utility functions from migration.pipeline_util to handle complex database operations consistently across all pipelines.

When to Modify the Migration

In most cases, you don't need to modify the migration! The generated migration handles all standard pipeline setup automatically.

You only need to modify it if you want to add custom configuration fields that appear in the Admin Dashboard UI.

📘 Note: Adding custom fields requires two steps:

  1. Add fields to the migration (this guide)

  2. Create a PresetConfig class (Advanced Configuration Guidearrow-up-right)

Adding Custom Configuration Fields

⚠️ Important: If you add custom configuration fields in the migration, you MUST also create a PresetConfig class in your pipeline. See the Advanced Configuration Guidearrow-up-right for complete instructions.

The generated migration includes commented examples showing how to add custom config fields. To add custom fields:

  1. Add fields to the migration file: Uncomment and modify the example code

  2. Create a PresetConfig class: Define a Pydantic model with matching fields (see Advanced Configurationarrow-up-right)

  3. Run the migration: make migrate

Both steps are required - the migration creates fields in the database, and PresetConfig provides type safety and validation in your code.

Example: Adding Custom Fields to Migration

After adding these fields to the migration, you must create a matching PresetConfig class. See the Advanced Configuration Guide - Preset Configurationarrow-up-right section for complete examples of creating and registering PresetConfig classes.

Configuration Field Options

Field
Description
Example Values

type

Data type of the field (must match PresetConfig type)

"string", "bool", "int", "float"

default_value

Default value as string (must match PresetConfig default)

"true", "0.7", "custom_value"

ui_type

UI component in Admin Dashboard

"text_field", "toggle", "number", "dropdown"

level

Configuration level

"PRESET_CHATBOT", "CHATBOT"

category_id

UI grouping category (optional)

Retrieved via get_config_category_id() or None

Important: Field names, types, and defaults in the migration must exactly match your PresetConfig class definition.

Configuration Categories (UI Grouping)

Configuration categories are used to group related fields in the Admin Dashboard UI. Fields with the same category_id will be displayed together in a collapsible section.

Available ConfigCategory options:

  • RETRIEVAL_KNOWLEDGE_CONFIGURATION: Groups retrieval and knowledge base settings

  • SEARCH_RETRIEVAL_BEHAVIOR: Groups search behavior and filtering options

  • RESPONSE_GENERATION: Groups response generation settings

  • LANGUAGE_SETTINGS: Groups language and localization settings

If category_id is None: The field will be placed in an "Others" group in the Admin Dashboard.

Example:

Note: Custom fields will appear in the Admin Dashboard UI grouped by their category, allowing users to configure them per chatbot or preset.

Accessing Custom Fields in Pipeline Code

Once you've defined custom configuration fields in the migration and created the corresponding PresetConfig class (see Advanced Configurationarrow-up-right), you can access them in your pipeline code through the pipeline_config parameter:

In the build() function:

In the build_initial_state() function:

The pipeline_config dictionary contains all configuration values set by users in the Admin Dashboard for the specific chatbot instance.

Troubleshooting

Multiple Heads Error

If you get a "Multiple heads" error when running migrations:

Solution: The CLI tool automatically detects the correct down_revision, but if you manually modified the migration, verify that the down_revision matches the latest migration's revision field in migration/versions/.

Migration Fails During Upgrade

If the migration fails during make migrate:

  1. Check the error message: It usually indicates which step failed

  2. Verify database state: Ensure your database is in a consistent state

  3. Check for existing data: If the pipeline already exists, the migration may fail

  4. Rollback if needed: Use make downgrade1 to rollback one migration step

Rollback command:

This will downgrade the most recent migration, executing its downgrade() function to remove the pipeline and related data.

Pipeline Not Visible in Admin Dashboard

If your pipeline doesn't appear after running the migration:

  1. Verify migration ran successfully: Check the output of make migrate

  2. Check organization: Ensure you're viewing the correct organization

  3. Restart the application: Sometimes a restart is needed to reload pipelines

  4. Check database: Verify the pipeline exists in the pipelines table

Custom Config Fields Not Appearing

If your custom configuration fields don't show up in the Admin Dashboard:

  1. Verify field definitions: Check that field types and UI types are valid

  2. Check category assignment: Ensure the category ID is correct

  3. Restart application: Config fields are cached on startup

  4. Check database: Verify fields exist in config_fields table

References

Last updated