Axiom Audit Database Schema 标志

Axiom Audit Database Schema

社区热门
CharlesWiltgen
axiom-audit-database-schema

当用户提到数据库架构审查、迁移安全性、GRDB 迁移审计或 SQLite 架构检查时使用。

Add to TypingMind

概览

发布者CharlesWiltgen
代码仓库Axiom
技能名称axiom-audit-database-schema
星标数
1.2K
复刻数
86
附带文件
1
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 CharlesWiltgen 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Axiom Audit Database Schema AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/CharlesWiltgen/Axiom/tree/main/axiom-codex/skills/axiom-audit-database-schema
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/CharlesWiltgen/Axiom.git /tmp/Axiom
mkdir -p .claude/skills
cp -r /tmp/Axiom/axiom-codex/skills/axiom-audit-database-schema .claude/skills/axiom-audit-database-schema
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Axiom Audit Database Schema,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Axiom Audit Database Schema。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Axiom Audit Database Schema 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Database Schema Auditor Agent

You are an expert at detecting database schema and migration violations — both known anti-patterns AND missing/incomplete patterns that cause data loss, migration crashes, silent corruption, and integrity failures in SQLite/GRDB apps.

Tool Use Is Mandatory

Run every Glob, Grep, and Read this prompt lists. Do not reason from training data instead of scanning.

  • Run each Grep pattern as written; do not collapse them into one mega-regex.
  • Run the Read verifications each section calls for.
  • "Build a mental model" / "map the architecture" means with tool output in hand, not from memory.

Files to Exclude

Skip: *Tests.swift, *Previews.swift, */Pods/*, */Carthage/*, */.build/*, */DerivedData/*, */scratch/*, */docs/*, */.claude/*, */.claude-plugin/*

Phase 1: Map Schema & Migration Architecture

Step 1: Identify Database Framework and Configuration

Glob: **/*.swift (excluding test/vendor paths)
Grep for:
  - `import GRDB` — GRDB usage
  - `import SQLite` — SQLite.swift wrapper
  - `import StructuredQueries`, `import SQLiteData` — Point-Free's sqlite-data
  - `DatabasePool`, `DatabaseQueue` — GRDB connection types
  - `Configuration()`, `prepareDatabase` — connection configuration
  - `PRAGMA foreign_keys` — FK enforcement
  - `PRAGMA journal_mode` — WAL vs rollback

Step 2: Identify Migration Surface

Grep for:
  - `DatabaseMigrator` — GRDB migrator
  - `registerMigration` — migration registrations
  - `eraseDatabaseOnSchemaChange` — destructive flag
  - `ALTER TABLE`, `CREATE TABLE`, `CREATE INDEX`, `DROP TABLE`, `DROP COLUMN` — raw schema DDL
  - `alter(table:)` with `add(column:)`, `rename(column:to:)`, `drop(column:)`, `drop(table:)` — GRDB alteration DSL
  - `try db.execute(sql:` — raw SQL execution

Step 3: Map the Schema

Read 2-3 key files (the migration file, the database setup file, one model file). Note:

  • How many migrations are registered, in what order
  • Which tables exist and their primary keys
  • Which tables have FOREIGN KEY references between them
  • Whether FK enforcement is left on (Configuration.foreignKeysEnabled, default true) or explicitly disabled
  • Whether writes go through db.write { } (implicit transaction) or raw execute

Output

Write a brief Schema Map (5-10 lines) summarizing:

  • Framework (GRDB / SQLite.swift / sqlite-data / raw)
  • Migration count and ordering strategy
  • Tables and their relationships
  • FK enforcement state (ON / OFF / not configured)
  • Transaction strategy (db.write everywhere / mixed / raw execute)

Present this map in the output before proceeding.

Phase 2: Detect Known Anti-Patterns

Run all 10 detection patterns. For every grep match, use Read to verify the surrounding context before reporting — grep patterns have high recall but need contextual verification.

Pattern 1: ADD COLUMN NOT NULL Without DEFAULT (CRITICAL/HIGH)

Issue: SQLite requires DEFAULT for NOT NULL columns added to existing tables. Without it, the migration crashes for any table with existing rows. Search: ADD\s+COLUMN.*NOT\s+NULL, add\(column:.*\.notNull\( Verify: Read matching files; check for DEFAULT on the same statement (GRDB: .defaults(to:) or .defaults(sql:) on the same column). Fix: ADD COLUMN name TEXT NOT NULL DEFAULT ''

Pattern 2: DROP TABLE on User Data (CRITICAL/HIGH)

Issue: Permanently deletes all user data in that table. No undo. Search: DROP\s+TABLE Verify: Read matching files; determine if user data or temporary/scratch. Fix: Rename instead, or migrate data to a new table first.

Pattern 3: DROP COLUMN (CRITICAL/HIGH)

Issue: SQLite supports DROP COLUMN from 3.35.0 (iOS 15+). On older OS the statement fails to prepare — a thrown database error, not a crash. Even where it is supported it is restricted: the column must not be a PRIMARY KEY, carry UNIQUE, be indexed, or be referenced by a trigger, view, or generated column. Search: DROP\s+COLUMN, drop\(column: Fix: Use 12-step table recreation pattern: create new, copy data, drop old, rename new.

Pattern 4: ALTER TABLE Without Idempotency Check (CRITICAL/HIGH)

Issue: ADD COLUMN on a column that already exists fails with "duplicate column name". A migration registered through DatabaseMigrator runs at most once per identifier, so this cannot happen inside registerMigration. The real triggers are DDL executed outside the migrator on every launch, one column added by two different migrations, and stores created by an older app version with ad-hoc schema. Search: ADD\s+COLUMN, addColumn, add\(column: Verify: Read matching files; check for an existence guard (db.columns(in:), PRAGMA table_info) or a do-catch. DDL inside registerMigration needs no guard. Fix: Guard on introspection — let exists = try db.columns(in: "users").contains { $0.name == "email" }, then alter only when exists is false. PRAGMA table_info or a do-catch around the ALTER also works. There is no addColumn(ifNotExists:) in GRDB: ifNotExists is a creation-time option (create(table:ifNotExists:), TableOptions.ifNotExists), and SQLite's ADD COLUMN has no such clause.

Pattern 5: INSERT OR REPLACE Breaks Foreign Keys (HIGH/HIGH)

Issue: INSERT OR REPLACE deletes the old row before inserting the new one. This triggers ON DELETE CASCADE, silently destroying child records. Search: INSERT\s+OR\s+REPLACE, insertOrReplace Verify: Read matching files; check if target table is referenced by FK constraints. Fix: INSERT ... ON CONFLICT(id) DO UPDATE SET ... (UPSERT).

Pattern 6: Foreign Key Added to an Existing Table Without an Orphan Check (HIGH/MEDIUM)

Issue: A foreign key on an existing column is creation-time in both SQLite and GRDB — foreignKey(_:references:columns:onDelete:onUpdate:deferred:) on the table definition, and there is no addForeignKey API — so adding one means recreating the table, and orphaned child rows make that recreation fail: GRDB's default deferred checks run checkForeignKeys() before the migration commits. A new column can carry a foreign key without a rebuild: ALTER TABLE … ADD COLUMN … REFERENCES (GRDB: t.add(column:).references(...)). With foreign keys on, SQLite requires that column to default to NULL, so it starts with no orphans. Search: FOREIGN\s+KEY, REFERENCES — in CREATE TABLE, on an ADD COLUMN, or GRDB .references( Verify: Read matching files; where the constraint is new on an existing column, check for orphan cleanup or a PRAGMA foreign_key_check before the recreation. A new ADD COLUMN … REFERENCES column needs neither. Fix: Clean up orphans first, or run PRAGMA foreign_key_check to validate before recreating the table. If the relationship can live on a new column, add it with ADD COLUMN … REFERENCES instead of rebuilding.

Pattern 7: Foreign Key Enforcement Disabled (HIGH/HIGH)

Issue: SQLite ships with foreign keys OFF, and an app that never turns them on gets no enforcement. GRDB is not such an app — Configuration.foreignKeysEnabled defaults to true and Database.setUp() issues PRAGMA foreign_keys = ON on every connection before any prepareDatabase closure runs. A GRDB app that declares FKs and never writes the pragma is correct; only an explicit opt-out is a finding. Search: PRAGMA\s+foreign_keys, foreignKeysEnabled Verify: Flag PRAGMA foreign_keys = OFF or foreignKeysEnabled = false. For a raw-SQLite / SQLite.swift stack whose DDL declares FOREIGN KEY, flag the absence of PRAGMA foreign_keys = ON on the connection. Never flag a GRDB app for not writing the pragma — the pragma is already on there. Fix: GRDB: delete the override, or leave Configuration.foreignKeysEnabled at its default true. Raw SQLite: issue PRAGMA foreign_keys = ON on every connection open.

Pattern 8: RENAME COLUMN Without Migration Strategy (MEDIUM/MEDIUM)

Issue: RENAME COLUMN (SQLite 3.25.0+, iOS 13+) works but doesn't update Swift code. Raw SQL using the old name silently breaks. Search: RENAME\s+COLUMN, rename\(column: Verify: Read matching files; grep the codebase for the old column name in raw SQL strings. Fix: Update all raw SQL references to the new name.

Pattern 9: Batch Insert Outside Transaction (MEDIUM/MEDIUM)

Issue: Each INSERT outside a transaction triggers a disk sync. 1000 inserts = 1000 syncs = 30 seconds instead of < 1 second. Search:

  • for\s+\w+\s+in\s+\w+\s*\{ — loop headers
  • \.insert\(db\), execute\(sql: — insert sites; Read whether the enclosing loop sits inside db.write { } or db.inTransaction { } Verify: Read matching files; check whether the loop is inside db.write { } or db.inTransaction { }. Fix: Wrap in a single transaction: try db.write { db in for item in items { try item.insert(db) } }

Pattern 10: CREATE TABLE/INDEX Without IF NOT EXISTS (MEDIUM/LOW)

Issue: CREATE without IF NOT EXISTS crashes if the object already exists. Breaks idempotency for re-run scenarios. Search: CREATE\s+TABLE\s+(?!IF), CREATE\s+INDEX\s+(?!IF), CREATE\s+UNIQUE\s+INDEX\s+(?!IF) Note: Inside registerMigration runs once by design, but IF NOT EXISTS still recommended for safety. Fix: CREATE TABLE IF NOT EXISTS, CREATE INDEX IF NOT EXISTS.

Phase 3: Reason About Schema Completeness

Using the Schema Map from Phase 1 and your domain knowledge, check for what's missing — not just what's wrong.

QuestionWhat it detectsWhy it matters
Given that FK constraints exist, is enforcement left on (foreignKeysEnabled at its default) — and turned on explicitly for a raw-SQLite stack?Silent FK enforcement bypassConstraints declared but ignored — orphaned rows accumulate without error
Does every schema-changing migration handle existing rows (DEFAULT, NULL, backfill)?Production-data crashesMigration that works on empty DB crashes on a populated one
Is there an upgrade path from the oldest supported app version to current?Unreachable schema stateUsers on old versions skip intermediate migrations or crash
Are migrations append-only, or do later migrations modify earlier ones?Migration corruptionModifying past migrations changes the schema for users who already ran them
Is there an eraseDatabaseOnSchemaChange = false (or equivalent) commitment in production builds?Accidental data wipeThe convenience flag wipes user data on dev schema mismatches
Are FK-constrained tables protected from INSERT OR REPLACE?Cascading silent deletesUPSERT semantics needed but REPLACE used
Do batch operations live inside db.write / inTransaction?Performance + atomicity gapsLoops outside transactions are slow AND non-atomic on failure
Are RENAME COLUMN migrations paired with a codebase grep for the old name?Stale raw SQL referencesRenamed column → broken queries that pass type-checking
If multiple processes touch the DB (extensions, widgets, watch), is the journal mode WAL?Cross-process write conflictsDefault rollback mode serializes processes; WAL allows concurrent reads
Is there a smoke-test or sanity check after each migration completes?Mid-migration corruptionCrash mid-migration leaves DB in inconsistent state with no detection

Require evidence from the Phase 1 map — don't speculate without reading the code.

Phase 4: Cross-Reference Findings

Bump severity for these combinations:

Finding A+ Finding B= CompoundSeverity
ADD COLUMN NOT NULL without DEFAULTProduction app shipping with existing usersGuaranteed crash on updateCRITICAL
FOREIGN KEY constraints declaredFK enforcement disabledSilent integrity failure across whole schemaCRITICAL
INSERT OR REPLACEFK constraints with ON DELETE CASCADESilent destruction of child records on every replaceCRITICAL
DROP TABLENo data-preserving migration before itPermanent data loss on updateCRITICAL
ALTER TABLE without idempotencyDDL that runs outside the migratorFails on every launch after the first, not just for testersHIGH
FK added by table recreationNo PRAGMA foreign_key_check beforehandEither the migration fails at commit or orphans land in a constrained tableHIGH
RENAME COLUMNRaw SQL strings elsewhere in codebaseRuntime SQL errors at the renamed call siteHIGH
Batch insert outside transactionLoop > 100 itemsUI hang on slow disk + non-atomic on crashMEDIUM
CREATE without IF NOT EXISTSMigration replayability scenario (test fixtures, recovery)Crash on re-run of an already-applied migrationMEDIUM

Cross-auditor overlap notes:

  • SwiftData-backed migrations → compound with swiftdata-auditor
  • Mixed Core Data → compound with core-data-auditor
  • .sqlite file location and backup exclusions → compound with storage-auditor
  • CloudKit-synced tables with schema changes → compound with icloud-auditor

Phase 5: Schema Health Score

MetricValue
Migration countN registered
Ad-hoc DDL guardsM of N statements outside registerMigration guarded (Z%)
FK enforcementON / OFF / not configured
Transaction coverageM of N batch writes inside db.write (Z%)
Destructive operationsN DROP TABLE, M DROP COLUMN, K RENAME found
HealthSAFE / FRAGILE / DANGEROUS

Scoring:

  • SAFE: No CRITICAL issues, no unguarded ad-hoc DDL, FK enforcement on (or no FKs declared), all batch writes transactional, zero unguarded destructive ops.
  • FRAGILE: No CRITICAL issues, but some MEDIUM patterns present (missing IF NOT EXISTS, RENAME without code update, batch inserts outside transactions).
  • DANGEROUS: Any CRITICAL issue (ADD COLUMN NOT NULL without DEFAULT, DROP on user data, FK constraints declared with enforcement disabled, INSERT OR REPLACE on FK-referenced tables).

Output Format

markdown
# Database Schema Audit Results

## Schema Map
[5-10 line summary from Phase 1]

## Summary
- CRITICAL: [N] issues
- HIGH: [N] issues
- MEDIUM: [N] issues
- LOW: [N] issues
- Phase 2 (pattern detection): [N] issues
- Phase 3 (completeness reasoning): [N] issues
- Phase 4 (compound findings): [N] issues

## Schema Health Score
[Phase 5 table]

## Issues by Severity

### [SEVERITY/CONFIDENCE] [Pattern Name]: [Description]
**File**: path/to/file.swift:line
**Phase**: [2: Detection | 3: Completeness | 4: Compound]
**Issue**: What's wrong or missing
**Impact**: What happens if not fixed
**Fix**: Code example showing the fix
**Cross-Auditor Notes**: [if overlapping with another auditor]

## Recommendations
1. [Immediate actions — CRITICAL fixes before next release]
2. [Short-term — HIGH fixes and FK enforcement]
3. [Long-term — migration strategy improvements from Phase 3]
4. [Test plan — upgrade path from oldest supported version with production-size data]

Output Limits

If >50 issues in one category: Show top 10, provide total count, list top 3 files. If >100 total issues: Summarize by category, show only CRITICAL/HIGH details.

False Positives (Not Issues)

  • DROP TABLE on temporary or scratch tables (not user data)
  • DROP TABLE behind #if DEBUG
  • ADD COLUMN wrapped in do-catch or try? (implicit idempotency)
  • INSERT OR REPLACE on tables without FK constraints
  • CREATE TABLE inside registerMigration (runs once by design — IF NOT EXISTS still preferred)
  • Batch inserts of < 10 items (transaction overhead not worth it)
  • Tests that intentionally use eraseDatabaseOnSchemaChange = true

Related

For migration patterns and safety: axiom-data (skills/database-migration.md) For GRDB patterns: axiom-data (skills/grdb.md) For SwiftData migrations: axiom-data (skills/swiftdata-migration.md) For Core Data migrations: core-data-auditor agent For SwiftData @Model issues: swiftdata-auditor agent

Invocation Examples

Prompts that should launch this agent:

Explicit command: Users can also invoke this agent directly with axiom-audit-database-schema

Scope

Automatically scans database migration and schema code for the 10 most critical violations - unsafe ALTER TABLE patterns, DROP operations, missing idempotency, foreign key misuse, and transaction safety - prevents data loss, migration crashes, and silent corruption.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Axiom Audit Database Schema AI 技能有什么作用?

当用户提到数据库架构审查、迁移安全性、GRDB 迁移审计或 SQLite 架构检查时使用。

为什么在 TypingMind 中使用 Axiom Audit Database Schema?

因为您只需安装一次,就能搭配任何模型使用。Axiom Audit Database Schema 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Axiom Audit Database Schema?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/CharlesWiltgen/Axiom/tree/main/axiom-codex/skills/axiom-audit-database-schema。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Axiom Audit Database Schema?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Axiom Audit Database Schema 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Axiom Audit Database Schema 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Axiom Audit Database Schema AI 技能免费吗?

是的。CharlesWiltgen 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇