CtrlK
BlogDocsLog inGet started
Tessl Logo

igmarin/hanakai-yaku

Curated library of atomic skills and personas for Hanami, dry-rb, and ROM Ruby development. Covers actions, slices, repositories, relations, changesets, providers, DI, operations, TDD, CLI, views, routing, validation, and 10 orchestration personas. Shared Ruby process skills have moved to ruby-core-skills. Uses Markdown + Front-matter architecture.

95

1.20x
Quality

95%

Does it follow best practices?

Impact

96%

1.20x

Average score across 45 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

SKILL.mdskills/personas/add-table-column/

name:
add-table-column
license:
MIT
type:
persona
description:
Use when adding a column, field, or new attribute to an existing table in Hanami 2.x, or when performing a database schema change such as altering a table. Chains write-migration, define-relation, define-entity, create-repository, and write-request-spec.
metadata:
{"ecosystem_sources":["jeremyevans/sequel","rom-rb/rom","hanami/hanami"],"tags":["personas","migrations","schema-changes","database"],"version":"1.0.0"}

add-table-column

Use this workflow when adding a column to an existing table in Hanami 2.x.

Core principle: Schema changes cascade through the data layer. Update the database, then Relations, Entities, Repositories, and tests.


Core Process

StepSkillWhat to doHandoff Condition
1. Generate migrationwrite-migrationhanami generate migration add_bio_to_users; write the migration bodyMigration file exists and is valid
2. Run migrationmanage-databasehanami db migrate; verify schema change in databaseSchema updated in database
3. Update Relationdefine-relationIf explicit schema, add new column; if infer: true, auto-updated at bootRelation includes new column
4. Update Entitydefine-entityAdd attribute: attribute :bio, Types::String.optionalEntity includes new attribute
5. Update Repositorycreate-repositoryUpdate query/create/update methods if new column affects filtering or is requiredRepository methods handle new column
6. Write Testswrite-request-specUpdate request specs to assert on new column; test persistence and returnAll tests pass

Complete Migration File Example

# db/migrate/20240601120000_add_bio_to_users.rb
Rom::SQL::Migration do
  change do
    alter_table(:users) do
      add_column :bio, :text, null: true
    end
  end
end

For a NOT NULL column on a populated table, use a three-step approach:

# Step 1: Add as nullable with a default
alter_table(:users) do
  add_column :bio, :text, null: true, default: ''
end

# Step 2: Backfill existing rows (separate migration or script)
# Step 3: Add NOT NULL constraint after backfill
alter_table(:users) do
  set_column_not_null :bio
end

Pitfalls

Mistake / Red FlagCorrect Approach
Entity updated before migration appliedThe migration must be applied before the Entity can reference the new column.
Repository not updated for new columnIf the new column affects queries or required fields, the Repository must be updated.
Tests not updatedTests must assert on the new column. Update existing specs and add new ones.
NOT NULL column added without a default on a populated tableAdding NOT NULL without a default fails on existing rows. Add a default or make it nullable first, backfill, then add NOT NULL.
Missing backfill strategy for existing dataPlan a backfill step in a separate migration or script before enforcing constraints.

skills

personas

add-table-column

README.md

tile.json