# Schema generation command

{% hint style="success" %}
This is the official documentation of the `agent_ruby` Ruby agent.
{% endhint %}

## Schema generation command

The `.forestadmin-schema.json` file is normally generated when your Rails server starts. However, in some workflows (CI/CD pipelines, pre-deployment validation), you may need to generate it without starting the server.

#### Usage

```bash
rails forest_admin:schema:generate
```

This command will:

1. Load your Rails environment and models
2. Execute your `create_agent.rb` customizations
3. Write the `.forestadmin-schema.json` file
4. **Skip** sending the schema to the Forest Admin API

{% hint style="info" %}
The schema is written to the path configured in your initializer (`config.schema_path`), which defaults to `.forestadmin-schema.json`.
{% endhint %}

#### Options

| Option       | Description               |
| ------------ | ------------------------- |
| `debug=true` | Show stack trace on error |

```bash
rails forest_admin:schema:generate debug=true
```

#### CI/CD example

You can use this command in your CI pipeline to ensure the schema is always up to date in your pull requests.

{% hint style="warning" %}
This command requires a **database connection** to introspect your tables and columns. Your CI environment must have a running database with the schema migrated before generating.
{% endhint %}

```bash
# Setup the database
rails db:create db:migrate

# Generate the schema
rails forest_admin:schema:generate

# Fail if the schema has changed (meaning someone forgot to commit it)
git diff --exit-code .forestadmin-schema.json
```

#### When does the schema change?

The schema needs to be regenerated when:

* A **migration** is applied (new columns, tables, type changes)
* **ActiveRecord associations** are modified (`has_many`, `belongs_to`, `has_one`...)
* **Customizations** in `create_agent.rb` are modified (smart fields, smart actions, charts, segments, renamed fields...)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/developer-guide-agents-ruby/deploying-to-production/schema-generation-command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
