# Sqldef on rails

> Sqldef on rails is an open-source agent skill for databases. Guides a Rails app to manage its PostgreSQL schema as SQL files with psqldef. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/sorah/config/tree/master/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails
- **Repository:** https://github.com/sorah/config
- **GitHub stars:** 31
- **License:** MIT
- **Skill name:** sqldef-on-rails
- **Collection:** https://github.com/sorah/config
- **Categories:** [databases](https://ai-powered.com/categories/databases), [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-03

## About

This skill sets up and maintains a Rails application whose PostgreSQL schema is described as declarative SQL files in db/schema instead of ActiveRecord migrations. The agent is shown the file layout, one file per table holding its create statement, indexes and grants, and how the rake tasks concatenate these files and hand them to psqldef to diff against the live database.

It covers the rake task setup that replaces the standard migration and schema dump tasks, including guarding drops behind an explicit flag, limiting grants to what is declared, and connection handling. It also explains how to express renames with psqldef annotations, when to run statements before the diff is applied, how to backfill data outside the schema files, and how to pin and install psqldef in mise and Docker builds.

The guidance also addresses deployment ordering and CI, such as applying the schema before new code serves traffic and posting dry-run plans on pull requests. It expects a Rails app on PostgreSQL, the psqldef command-line tool, and project conventions documented in the repository, which take priority over the skill's defaults.

## When your agent uses it

> This skill should be used when a Rails app manages its PostgreSQL schema declaratively with psqldef (sqldef) instead of ActiveRecord migrations, or when setting that up, changing a table, or replacing `db/migrate`. Signs include `db/schema/*.sql`, a `psqldef` call in a rake file, `BEFORE_APPLY_SQL`, `ENABLE_DROP`, no `db/migrate` directory or `schema.rb`, or the user mentioning "sqldef", "psqldef", "declarative schema", "schema as SQL", or "drop Rails migrations", even if they only say "add a column" in such an app. Provides the schema file layout, the rake tasks that replace migrations, psqldef configuration, non-declarative changes, and installation. Project-specific conventions always take priority.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/sorah/config/tree/HEAD/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails)
- [License: MIT](https://github.com/sorah/config/tree/HEAD/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails)

## Features

- **Declarative schema layout:** Organizes each table's definition, indexes and grants into its own SQL file under db/schema.
- **Replacement rake tasks:** Supplies a database rake file that swaps Rails migration and schema dump tasks for psqldef runs.
- **Guarded destructive changes:** Skips drops unless explicitly enabled, so reviewers can read the dry-run plan first.
- **Rename and pre-apply statements:** Shows psqldef rename annotations and how to run extra SQL before a diff is applied.
- **Deployment and CI ordering:** Describes backward-compatible rollouts, pre-deploy schema application and dry-run checks in CI.
- **psqldef installation pinning:** Covers pinning the psqldef version in mise and verifying release checksums in Docker builds.

## Good for

- Replace ActiveRecord migrations with declarative SQL schema files in a Rails app
- Add a column to a table defined in db/schema
- Rename a table or column without losing data using psqldef
- Set up psqldef in a Rails project's mise and Docker configuration
- Preview schema changes with a dry run before deploying

## Install

### Claude Code

This skill ships in the `sorah-guides` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add sorah/config
/plugin install sorah-guides@sorah-marketplace
```

Or copy only this skill to `~/.claude/skills/sqldef-on-rails`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/sorah/config.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/sqldef-on-rails &&
cp -R "$tmp/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails" ~/.claude/skills/sqldef-on-rails &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/sqldef-on-rails` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/sqldef-on-rails` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/sorah/config.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/sqldef-on-rails &&
cp -R "$tmp/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails" ~/.agents/skills/sqldef-on-rails &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/sqldef-on-rails` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/sqldef-on-rails` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/sorah/config.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/sqldef-on-rails &&
cp -R "$tmp/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails" ~/.cursor/skills/sqldef-on-rails &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/sqldef-on-rails` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/sorah/config.git --path claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails
```

Or copy the folder to `~/.gemini/skills/sqldef-on-rails` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/sqldef-on-rails`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/sorah/config.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/sqldef-on-rails &&
cp -R "$tmp/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails" ~/.copilot/skills/sqldef-on-rails &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/sqldef-on-rails` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/sorah/config.git
```

Then copy `config/claude/marketplace/plugins/sorah-guides/skills/sqldef-on-rails` into your agent's skills folder as `sqldef-on-rails`. Agents that support SKILL.md read one folder per skill.

## FAQ

### When does Sqldef on rails trigger?

It triggers when a Rails app manages its PostgreSQL schema with psqldef instead of migrations, such as when files appear under db/schema, when psqldef or sqldef is mentioned, or when a column is added in such an app.

### Does Sqldef on rails drop tables automatically?

No. Drops are skipped unless ENABLE_DROP=1 is passed, and the skill recommends reading the dry-run plan before applying.

### Does psqldef revoke permissions removed from the files?

No. Grants only widen, so narrowing a grant needs a manual REVOKE, which can be run through BEFORE_APPLY_SQL.

### Which project rules take precedence?

Project-specific conventions in files such as CLAUDE.md or docs always take priority over the skill's guidance.

### How do I install Sqldef on rails in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/sqldef-on-rails to use it in all your projects, or to .claude/skills/sqldef-on-rails in one project. Or install the sorah-guides plugin, which includes it: /plugin marketplace add sorah/config, then /plugin install sorah-guides@sorah-marketplace.

### Does Sqldef on rails run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Sqldef on rails?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to Sqldef on rails?

The closest alternatives to Sqldef on rails are Dsql on rails, Database migrations, Database migrations, Postgres database migration and Postgres.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Dsql on rails](https://ai-powered.com/skills/dsql-on-rails): Dsql on rails is an open-source agent skill for developer tools.
- [Database migrations](https://ai-powered.com/skills/database-migrations-nabwinsaud): Database migrations is an open-source agent skill for databases.
- [Database migrations](https://ai-powered.com/skills/database-migrations): Database migrations is an open-source agent skill for databases.
- [Postgres database migration](https://ai-powered.com/skills/postgres-database-migration): Postgres database migration is an open-source agent skill for databases.
- [Postgres](https://ai-powered.com/skills/postgres-timescale): Postgres is an open-source agent skill for databases.
- [Design postgres tables](https://ai-powered.com/skills/design-postgres-tables): Design postgres tables is an open-source agent skill for databases.
- [Schema exploration](https://ai-powered.com/skills/schema-exploration): Schema exploration is an open-source agent skill for developer tools.
- [Planning oracle to postgres migration integration testing](https://ai-powered.com/skills/planning-oracle-to-postgres-migration-integration-testing): Planning oracle to postgres migration integration testing is an open-source agent skill for databases.

---
Source: https://ai-powered.com/skills/sqldef-on-rails
