persistence-drift

Governs Drift/SQLite schema design, transactions, and backups for Flutter on-device data layers.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/zakariaf/NearlyStop --skill persistence-drift-zakariaf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: persistence-drift
Source: https://github.com/zakariaf/NearlyStop/tree/main/.claude/skills/persistence-drift
Command: npx skills add https://github.com/zakariaf/NearlyStop --skill persistence-drift-zakariaf

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? On-device Flutter apps with no server must rebuild all state from a single local SQLite database, so schema mistakes, torn backups, leaked ORM types, and lost transactions cause silent data corruption. This Skill enforces a disciplined Drift/SQLite data layer where invariants live in the schema and every mutation is one durable transaction. ## Core Features & Use Cases - Layer confinement: Restricts package:drift and package:sqlite3 imports to lib/data/ behind DAOs and repositories that map rows to immutable value objects, verified by grep-based check scripts. - Schema invariants: Enforces STRICT tables, CHECK constraints, foreign keys, partial UNIQUE indexes, canonical integer storage (minor-unit money, UTC epoch millis, serial-day integers), and keyset pagination instead of OFFSET. - Safe backups and pragmas: Re-asserts foreign_keys/WAL/synchronous pragmas on every open and backs up via wal_checkpoint(TRUNCATE) + VACUUM INTO with verify-by-reopen, never File.copy of a live WAL database. - Use Case: When adding a new Drift table or reviewing a data-layer diff in a Flutter app, apply this Skill to define the table with audit columns and CHECK constraints, wire the repository transaction, and run the confinement and ban scripts before the PR. ## Quick Start Use the persistence-drift skill to review my new Drift table and repository transaction in lib/data/ for schema invariants and confinement violations.

Frequently Asked Questions about persistence-drift

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a Drift database layer in Flutter?

Confine package:drift and package:sqlite3 imports to lib/data/ with one @DriftDatabase, per-feature @DriftAccessor DAOs for single-table queries, and repositories owning cross-table transactions. DAOs map rows to immutable value objects so no Drift type crosses the boundary.

How do I back up a SQLite database in WAL mode safely?

Run PRAGMA wal_checkpoint(TRUNCATE), then VACUUM INTO a temp file, atomically rename it, and verify by reopening with an integrity check. Never File.copy a live WAL database, since the -wal and -shm sidecars produce a torn, unrestorable copy.

Should I use sqflite or Drift NativeDatabase for Flutter SQLite?

Use Drift's NativeDatabase FFI backend rather than sqflite. The FFI backend supports in-process WAL concurrency and the SQLCipher encryption path, while sqflite forfeits both.

Why is PRAGMA foreign_keys not working in SQLite?

PRAGMA foreign_keys is per-connection and defaults to OFF, so it must be re-asserted in setup or beforeOpen on every open. It is also a silent no-op inside a transaction, so toggle it outside transactions during migrations.

When should I use plain JSON files instead of Drift for persistence?

Use JSON files when data is a small set of independent records with no relational queries, such as settings or a simple roster. Apply the same discipline: injected base directory, atomic writes, debounced saves with lifecycle flush, and lenient per-field decoding.