Database - Capsize-Games/airunner GitHub Wiki

Engine

By default, AI Runner uses an SQLite database, located at ~/local/share/.airunner on Linux.

To use a different database, set the AI_RUNNER_DATABASE_URL and ASYNC_AI_RUNNER_DATABASE_URL environment variables.

Example (PostgreSQL with psycopg2)

export AI_RUNNER_DATABASE_URL="postgresql+psycopg2://user:password@hostname/database_name"

These URLs follow SQLAlchemy's database URL format.

Advanced Database Features

Supported Engines

  • SQLite: Default database engine, located at ~/.local/share/.airunner on Linux.
  • PostgreSQL: Supported via AI_RUNNER_DATABASE_URL and ASYNC_AI_RUNNER_DATABASE_URL environment variables.

Environment Variables

  • AI_RUNNER_DATABASE_URL: SQLAlchemy connection string for the primary database.
  • ASYNC_AI_RUNNER_DATABASE_URL: Connection string for asynchronous database operations.

Migrations

  • AI Runner uses Alembic for database migrations.
  • To generate migrations, navigate to the src/airunner directory and run:
    alembic revision --autogenerate -m "Migration message"
    
  • Apply migrations manually with:
    alembic upgrade head
    

Models

Advanced ORM Features

  • Models are defined in src/airunner/data/models/ and inherit from the Base class.
  • Example:
    from airunner.data.models.base import Base
    class ExampleModel(Base):
        ...
    

Migrations

When modifying models, database migrations must be generated and applied.

AI Runner uses Alembic to manage migrations.

To generate migrations with the autogenerate flag, navigate to the src/airunner directory, where the alembic.ini file is located.

Example:

cd src/airunner
alembic revision --autogenerate -m "Add use_grid_image_as_input and lock_input_image to OutpaintSettings"

The generated migration will include upgrade and downgrade functions reflecting the changes in your models. However, manual edits may be required to add database inspections and exception handling. Refer to existing migrations for best practices.

Applying Migrations

When running airunner, migrations will be applied automatically. You can also run them manually:

alembic upgrade head

For more details on Alembic commands, see Alembic's documentation.