Skip to content

Command-Line Interface (CLI) Reference

castlecraft-engineer provides a command-line interface (CLI) for various development and operational tasks. This document outlines how to use the available CLI commands.

1. Invoking the CLI

The castlecraft-engineer CLI is invoked using the engineer command, which is made available when the package is installed. You can invoke the CLI from the root of your project as follows:

engineer <command> [options]

Replace <command> with one of the available commands detailed below and [options] with any command-specific arguments.

2. Available Commands

The CLI is structured with sub-commands. Currently, the primary command available is bootstrap.

bootstrap Command

The bootstrap command is used to initialize the database schema.

  • Purpose: This command creates all necessary database tables based on the SQLModel metadata defined in your application. It's typically run once during the initial setup of your application or when new models are added and you need to update the schema in a development environment. For production environments, proper migration tools are usually recommended for schema changes after the initial setup.
  • Definition: The logic for this command is primarily located in castlecraft_engineer.database.commands.bootstrap_schema and it's made available to the CLI via castlecraft_engineer.commands.argparser.add_bootstrap_schema_parser.
  • Usage:
    engineer bootstrap
    
  • Details: When executed, this command will:

    1. Establish a database connection using the SQL_ASYNC_CONNECTION_STRING (or SQL_CONNECTION_STRING if a synchronous version is targeted by the bootstrap logic) environment variable.
    2. Collect all table metadata from SQLModel classes that have been imported and registered with SQLModel.metadata.
    3. Execute SQLModel.metadata.create_all(engine) to create these tables in the database if they don't already exist.

    Ensure your .env file is correctly configured with the database connection string before running this command.

    Example Output (Conceptual):

    INFO:castlecraft_engineer.database.commands:Bootstrapping database schema...
    INFO:castlecraft_engineer.database.commands:Database schema bootstrapped successfully.