CLI Commands#

Litestar CLI database group and plugin discovery utilities.

Database Command Group#

litestar database#

Manage SQLAlchemy database components.

Usage

litestar database [OPTIONS] COMMAND [ARGS]...

branches#

Show current branch points in the migration history

Usage

litestar database branches [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

check#

Check if the target database is up to date

Usage

litestar database check [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

downgrade#

Downgrade database to a specific revision.

Usage

litestar database downgrade [OPTIONS] [REVISION]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output for offline migrations.

--tag <tag>#

an arbitrary ‘tag’ that can be intercepted by custom env.py scripts via the .EnvironmentContext.get_tag_argument method.

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

REVISION#

Optional argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

drop-all#

Drop all tables from the database.

Usage

litestar database drop-all [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

dump-data#

Dump specified tables from the database to JSON files.

Usage

litestar database dump-data [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--table <table_names>#

Required Name of the table to dump. Multiple tables can be specified. Use ‘*’ to dump all tables.

--dir <dump_dir>#

Directory to save the JSON files. Defaults to WORKDIR/fixtures

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

edit#

Edit a revision file using $EDITOR

Usage

litestar database edit [OPTIONS] REVISION

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Arguments

REVISION#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

ensure-version#

Create the alembic version table if it doesn’t exist

Usage

litestar database ensure-version [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output instead of executing

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

heads#

Show current available heads in the script directory

Usage

litestar database heads [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

--resolve-dependencies#

Resolve dependencies between heads

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

history#

List changeset scripts in chronological order

Usage

litestar database history [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

--rev-range <rev_range>#

Revision range (e.g., ‘base:head’, ‘abc:def’)

--indicate-current#

Indicate the current revision

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

init#

Initialize migrations for the project.

Usage

litestar database init [OPTIONS] [DIRECTORY]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--multidb#

Support multiple databases

--package#

Create __init__.py for created folder

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

DIRECTORY#

Optional argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

list-templates#

List available Alembic migration templates

Usage

litestar database list-templates [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

make-migrations#

Create a new migration revision.

Usage

litestar database make-migrations [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

-m, --message <message>#

Revision message

--autogenerate, --no-autogenerate#

Automatically populate revision with detected changes

--sql#

Export to .sql instead of writing to the database.

--head <head>#

Specify head revision to use as base for new revision.

--splice#

Allow a non-head revision as the “head” to splice onto

--branch-label <branch_label>#

Specify a branch label to apply to the new revision

--version-path <version_path>#

Specify specific path from config for version file

--rev-id <rev_id>#

Specify a ID to use for revision.

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

merge#

Merge two revisions together, creating a new migration file

Usage

litestar database merge [OPTIONS] REVISIONS

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

-m, --message <message>#

Merge message

--branch-label <branch_label>#

Branch label for merge revision

--rev-id <rev_id>#

Specify custom revision ID

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

REVISIONS#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

show#

Show the revision denoted by the given symbol

Usage

litestar database show [OPTIONS] REVISION

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Arguments

REVISION#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

show-config#

Show all configurations with migrations enabled.

Usage

litestar database show-config [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

show-current-revision#

Shows the current revision for the database.

Usage

litestar database show-current-revision [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

stamp#

Stamp the revision table with the given revision; don’t run any migrations

Usage

litestar database stamp [OPTIONS] REVISION

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output for offline migrations

--tag <tag>#

Arbitrary ‘tag’ that can be intercepted by custom env.py scripts

--purge#

Delete all entries in version table before stamping

Arguments

REVISION#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

upgrade#

Upgrade database to a specific revision.

Usage

litestar database upgrade [OPTIONS] [REVISION]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output for offline migrations.

--tag <tag>#

an arbitrary ‘tag’ that can be intercepted by custom env.py scripts via the .EnvironmentContext.get_tag_argument method.

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

REVISION#

Optional argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

Plugin Discovery#

advanced_alchemy.extensions.litestar.cli.get_database_migration_plugin(app)[source]#

Retrieve a database migration plugin from the Litestar application’s plugins.

Parameters:

app (Litestar) – The Litestar application

Returns:

The database migration plugin

Raises:

ImproperConfigurationError – If the database migration plugin is not found

Return type:

SQLAlchemyInitPlugin