ash-postgres
БесплатноБез исполняемых скриптовНе проверенRules for working with AshPostgres
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
Rules for working with AshPostgres
Understanding AshPostgres
AshPostgres is the PostgreSQL data layer for Ash Framework. It's the most fully-featured Ash data layer and should be your default choice unless you have specific requirements for another data layer. Any PostgreSQL version higher than 13 is fully supported.
Basic Configuration
To use AshPostgres, add the data layer to your resource:
defmodule MyApp.Tweet do
use Ash.Resource,
data_layer: AshPostgres.DataLayer
attributes do
integer_primary_key :id
attribute :text, :string
end
relationships do
belongs_to :author, MyApp.User
end
postgres do
table "tweets"
repo MyApp.Repo
end
end
PostgreSQL Configuration
Table & Schema Configuration
postgres do
# Required: Define the table name for this resource
table "users"
# Optional: Define the PostgreSQL schema
schema "public"
# Required: Define the Ecto repo to use
repo MyApp.Repo
# Optional: Control whether migrations are generated for this resource
migrate? true
end
Foreign Key References
Use the references section to configure foreign key behavior:
postgres do
table "comments"
repo MyApp.Repo
references do
# Simple reference with defaults
reference :post
# Fully configured reference
reference :user,
on_delete: :delete, # What happens when referenced row is deleted
on_update: :update, # What happens when referenced row is updated
name: "comments_to_users_fkey", # Custom constraint name
deferrable: true, # Make constraint deferrable
initially_deferred: false # Defer constraint check to end of transaction
end
end
Foreign Key Actions
For on_delete and on_update options:
:nothingor:restrict- Prevent the change to the referenced row:delete- Delete the row when the referenced row is deleted (foron_deleteonly):update- Update the row according to changes in the referenced row (foron_updateonly):nilify- Set all foreign key columns to NULL{:nilify, columns}- Set specific columns to NULL (Postgres 15.0+ only)
Warning: These operations happen directly at the database level. No resource logic, authorization rules, validations, or notifications are triggered.
Check Constraints
Define database check constraints:
postgres do
check_constraints do
check_constraint :positive_amount,
check: "amount > 0",
name: "positive_amount_check",
message: "Amount must be positive"
check_constraint :status_valid,
check: "status IN ('pending', 'active', 'completed')"
end
end
Custom Indexes
Define custom indexes beyond those automatically created for identities and relationships:
postgres do
custom_indexes do
index [:first_name, :last_name]
index :email,
unique: true,
name: "users_email_index",
where: "email IS NOT NULL",
using: :gin
index [:status, :created_at],
concurrently: true,
include: [:user_id]
end
end
Custom SQL Statements
Include custom SQL in migrations:
postgres do
custom_statements do
statement "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\""
statement """
CREATE TRIGGER update_updated_at
BEFORE UPDATE ON posts
FOR EACH ROW
EXECUTE FUNCTION trigger_set_timestamp();
"""
statement "DROP INDEX IF EXISTS posts_title_index",
on_destroy: true # Only run when resource is destroyed/dropped
end
end
Migrations and Codegen
Development Migration Workflow (Recommended)
For development iterations, use the dev workflow to avoid naming migrations prematurely:
- Make resource changes
- Run
mix ash.codegen --devto generate and run dev migrations - Review the migrations and run
mix ash.migrateto run them - Continue making changes and running
mix ash.codegen --devas needed - When your feature is complete, run
mix ash.codegen add_feature_nameto generate final named migrations (this will rollback dev migrations and squash them) - Review the migrations and run
mix ash.migrateto run them
Traditional Migration Generation
For single-step changes or when you know the final feature name:
- Run
mix ash.codegen add_feature_nameto generate migrations - Review the generated migrations in
priv/repo/migrations - Run
mix ash.migrateto apply the migrations
Tip: The dev workflow (
--devflag) is preferred during development as it allows you to iterate without thinking of migration names and provides better development ergonomics.
Warning: Always review migrations before applying them to ensure they are correct and safe.
Multitenancy
AshPostgres supports schema-based multitenancy:
defmodule MyApp.Tenant do
use Ash.Resource,
data_layer: AshPostgres.DataLaye
Установить ash-postgres в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл ash-postgres?
Rules for working with AshPostgres
Как установить скилл ash-postgres?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ash-postgres запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic