ecto-constraint-debug
/ecto-constraint-debug
Diagnozuje naruszenia ograniczeń Ecto: śledzi wyzwalacze i sprawdza migracje, gdy pojawia się błąd unique_constraint.
- Autor
- oliver-kriska ↗
- Repozytorium
- claude-elixir-phoenix ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 22.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 2
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Diagnozuje naruszenia ograniczeń Ecto: śledzi wyzwalacze i sprawdza migracje, gdy pojawia się błąd unique_constraint.
Oryginalny opis (EN)
Debug Ecto constraint violations - trace triggers, check migrations; Use when seeing unique_constraint…
Jak działa
- Iron Laws
- Step-by-Step Debugging
- Quick Fixes by Constraint Type
- References
Podgląd SKILL.md
--- name: ecto-constraint-debug description: Debug Ecto constraint violations - trace triggers, check migrations; Use when seeing unique_constraint… --- # Ecto Constraint Debugging > **Ash projects**: Ash surfaces DB constraints through its own error DSL. Use the `ash-framework` skill — `mix usage_rules.search_docs "constraint" -p ash_postgres`. Systematic approach to diagnosing constraint violations. Load when you see `Ecto.ConstraintError`, `unique_constraint`, `foreign_key_constraint`, or constraint-related changeset errors. ## Iron Laws 1. **READ THE CONSTRAINT NAME** — The constraint name (e.g., `links_url_index`) tells you exactly which index/constraint failed. Parse it from the error message first 2. **CHECK MIGRATION BEFORE CODE** — Verify the constraint definition in `priv/repo/migrations/` matches what the schema expects 3. **TRACE ALL INSERT PATHS** — Find every code path that inserts into the constrained table. The bug is often in a path you didn't consider 4. **RACE CONDITION UNTIL PROVEN OTHERWISE** — If validation passes but constraint fails, assume concurrent inserts until you prove a single-request cause ## Step-by-Step Debugging ### Step 1: Parse the Error Extract from the error message: - **Constraint name** (e.g., `users_email_index`) - **Table name** (e.g., `users`) - **Operation** (insert, update, or delete) - **Conflicting values** (if available in logs) ### Step 2: Find the Migration Use Grep to search for the constraint name in `priv/repo/migrations/`. Also check for `create unique_index`, `create index`, `add constraint`. Verify: Does the migration constraint match the schema's `unique_constraint/3` or `foreign_key_constraint/3` call? ### Step 3: Find the Schema Use Grep to find constraint handling in changesets (`unique_constraint`, `foreign_key_constraint`, `check_constraint`) in `lib/`. ### Step 4: Trace Insert Paths Find ALL callers that insert/update this schema: Use Grep to find all insert/update paths (`Repo.insert`, `Repo.update`, `Repo.insert_all`, `cast_assoc`) in `lib/`. ### Step 5: Identify the Cause | Symptom | Likely Cause | Fix Pattern | |---------|-------------|-------------| | Same user triggers twice | Race condition (double-click, retry) | Upsert with `on_conflict` | | Multiple parents share child | `cast_assoc` doesn't dedup across changesets | Dedup before building changesets | | Concurrent API requests | Missing transaction isolation | Wrap in `Repo.transaction` or use upsert | | Migration added constraint to existing data | Data violates new constraint | Backfill or clean data first | ### Step 6: Apply Fix See `references/constraint-patterns.md` for detailed fix patterns. ## Quick Fixes by Constraint Type **Unique violation** → Upsert: `Repo.insert(changeset, on_conflict: :replace_all, conflict_target: [:field])` **Foreign key violation** → Check: Does the referenced record exist? Was it deleted concurrently? **Check constraint** → Validate: Does the value satisfy the constraint condition? ## References - `references/constraint-patterns.md` - Detailed patterns for each constraint type
Pliki w paczce (2)
- SKILL.md 3 KB
- references/constraint-patterns.md 5 KB
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · oliver-kriska/claude-elixir-phoenix | 90 | MIT |
| oliver-kriska/claude-elixir-phoenix | 90 | MIT |
Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.
Migawka bazy z 13.11.2026 · wersja paczki c7cfa65978f1 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100ecto
Prowadzi przez schematy Ecto, changesety, zapytania, migracje i Ecto.Multi oraz pomaga wybrać między DSL zapytań Ecto a surowym SQL. - 100ecto
Pomaga projektować i debugować warstwę danych w Elixirze z Ecto: schematy, changesety, zapytania, preloady, transakcje, migracje, multi-tenancy oraz wydajność i pulę połączeń. - 100estack-ecto
Implementuje dostęp do danych w Ecto: schematy, zapytania, changesety, transakcje i bezpieczne migracje, w tym konteksty ograniczone do tenanta. - 100ecto-patterns
Podpowiada wzorce Ecto: schematy, changesety, walidacje, zapytania, preloady, Multi, migracje, ograniczenia i pola pieniężne, przed pisaniem kodu Ecto, z wyjątkiem projektów na Ash. - 100ecto-patterns
Podpowiada wzorce pracy z Ecto: schematy, changesety, walidacje, zapytania, preloady i Multi, ładowane przed pisaniem kodu Ecto. - 100elixir-ecto-patterns
Opisuje wzorce Ecto w Elixirze: schematy, changesety, zapytania i transakcje, przy budowie aplikacji opartych na bazie danych.