agentleFS
RidhuanDEVRidhuanDEV/claude-skills/shadow-data/SKILL.md

shadow-data

Skill1 starsChanged yesterdayMITView on GitHub

Application Data Lifecycle & Migrations. Use when writing zero-downtime Expand-Contract database migrations, deterministic seeds, safe backfills, bulk import/export streaming, or ACID transaction locking. Do NOT use for live DB introspection or Pentaho/DW ETL (/shadow-db).

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never run destructive or table-locking DDL (DROP COLUMN, RENAME COLUMN, adding NOT NULL without default on huge tables) in a single …

    line 14
  2. Very specific:

    Never store currency or exact quantities as FLOAT / DOUBLE / JS number floats.

    line 35
  3. Very specific:

    When using soft deletes (deleted_at TIMESTAMPTZ), remember that unique constraints must use partial indexes (CREATE UNIQUE INDEX ...

    line 56

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Shadow Data (/shadow-data) — Data Lifecycle, Safe Migrations & Transaction Integrity

While /shadow-db handles live database introspection, ERDs, and Data Warehouse/Pentaho generation, use /shadow-data whenever managing how data changes, moves, and stays consistent throughout the application's lifecycle.


1. Zero-Downtime Schema Migration Pattern (Expand -> Migrate -> Contract)

Never run destructive or table-locking DDL (DROP COLUMN, RENAME COLUMN, adding NOT NULL without default on huge tables) in a single deployment while old application instances are still serving traffic.

PhaseActionCompatibility Guarantee
1. ExpandAdd new nullable column/table; add indexes concurrently (CREATE INDEX CONCURRENTLY in Postgres); deploy code that dual-writes to both old and new columns.Old and new code versions both run safely; instant code rollback is 100% safe.
2. BackfillRun a batched, throttled backfill script (LIMIT 1000 per transaction with short sleep) to populate historical rows without locking the table or blowing up WAL replication lag.Zero table lock; zero impact on live OLTP latency.
3. Switch & ValidateEnforce NOT NULL (using CHECK (...) NOT VALID then VALIDATE CONSTRAINT), switch reads to the new column.Verified 100% data completeness before switching.
4. ContractRemove dual-write code and drop the obsolete column in a subsequent release.Clean schema with zero downtime.
  • Ephemeral Migration Verification Container Cleanup: Whenever verifying migrations against an ephemeral Docker database (*-migration-verification / *-test-*), always launch with docker run --rm --label shadow.ephemeral=true and wrap the run in try / finally (trap EXIT) executing docker rm -f -v <container> (or docker compose -p <project>-migtest down -v --rmi local --remove-orphans) so zero stopped containers, volumes, or temporary images remain after verification passes.

2. Transaction Integrity & Concurrency Control

  1. Atomic Multi-Step Writes:
    • Wrap related writes (e.g., creating an order, decrementing inventory, and inserting an outbox event) inside a single database transaction (BEGIN ... COMMIT).
    • Never perform external network/HTTP/SMTP calls inside an open DB transaction, as slow external responses hold row locks and exhaust the DB connection pool.
  2. Preventing Lost Updates & Race Conditions:
    • For financial balances, stock counts, and quota deductions, use atomic SQL updates (UPDATE wallets SET balance = balance - $1 WHERE id = $2 AND balance >= $1), pessimistic row locks (SELECT ... FOR UPDATE), or optimistic concurrency (version = version + 1 WHERE id = $1 AND version = $2).
  3. Monetary & Numeric Precision:
    • Never store currency or exact quantities as FLOAT / DOUBLE / JS number floats. Use integer minor units (BIGINT cents/rupiah) or NUMERIC(18, 2).
  4. Isolation Anomalies, Lock Budgets & Outbox/CDC Boundary:
    • Explicitly match transaction isolation level (READ COMMITTED + atomic UPDATE ... WHERE or SERIALIZABLE with retry on 40001 / 40P01) against read-skew, write-skew, and phantom-read hazards.
    • Set explicit lock_timeout and statement_timeout on online DDL/backfill sessions so migrations never queue behind slow queries and block production traffic.
    • Coordinate durable outbox/CDC event inserts inside the same transaction with /shadow-concurrency.

3. Deterministic Seeding & Bulk Import/Export Rules

  1. Idempotent Seeding (db:seed):
    • Seed scripts must use UPSERT (ON CONFLICT DO UPDATE / ON DUPLICATE KEY UPDATE) so running db:seed multiple times never fails with duplicate key errors or creates duplicate master rows.
    • Separate System Reference Seeds (roles, permissions, regions, status codes — safe for production) from Demo/Dummy Seeds (fake users/orders — strictly blocked when NODE_ENV=production).
  2. Safe Bulk Import & Export:
    • Imports (CSV/Excel): Validate all rows against schema rules first, report exact row/column line errors to the user, and insert in bounded batches (500–1,000 rows per batch).
    • Exports: Stream large datasets via cursor/chunked queries rather than loading $100,000+$ ORM objects into RAM at once.

4. Data Retention, Archival & Soft-Delete Hygiene

  • When using soft deletes (deleted_at TIMESTAMPTZ), remember that unique constraints must use partial indexes (CREATE UNIQUE INDEX ... WHERE deleted_at IS NULL) so a deleted email/code can be reused later.
  • Define archival/retention policies for high-growth log/telemetry tables (e.g., monthly declarative partitioning PARTITION BY RANGE (created_at)).

5. Execution Approval & Migration Boundary (L1 vs L4)

  • Authoring additive Expand-only migrations locally is L1_SAFE_VERIFICATION. Running destructive DDL (DROP, TRUNCATE, RENAME, migrate reset) or executing migrations against staging/production/unknown databases is L4: HIGH_IMPACT and NEVER authorized by a bug fix without explicit Monarch approval and verified backup/rollback (shadow-monarch/scripts/execution_approval_gate.py).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.