Skip to main content

SQLite

DeepDiff DB supports SQLite 3 as both production and development database targets. The SQLite driver is a pure Go implementation — no native libraries or system packages are required.

Requirements

  • SQLite 3 database file (.db, .sqlite, or any extension)
  • Read access to both database files from the host running deepdiffdb

Connection Configuration

For SQLite, the host, port, user, and password fields are not used. Set database to the file path of the SQLite database.

prod:
driver: "sqlite"
database: "/var/data/prod.db"

dev:
driver: "sqlite"
database: "/var/data/dev.db"

Relative paths are resolved from the working directory where deepdiffdb is invoked.

Go Driver

DeepDiff DB uses modernc.org/sqlite — a pure Go port of SQLite with no CGo dependency. This means the binary works on any platform without requiring libsqlite3 to be installed.

Identifier Quoting

SQLite identifiers are quoted with double-quotes, consistent with the SQL standard:

ALTER TABLE "orders" ADD COLUMN "shipped_at" TEXT;
CREATE INDEX "idx_orders_status" ON "orders" ("status");

Limitations

SQLite has significantly more limited DDL support than other databases. The following operations are not natively supported by SQLite and cannot be generated by schema-migrate or gen-pack:

OperationSupport
ALTER TABLE ... ADD COLUMNSupported
ALTER TABLE ... MODIFY COLUMNNot supported — SQLite cannot modify existing column types or constraints
ALTER TABLE ... DROP COLUMNSupported only in SQLite 3.35.0+
ADD FOREIGN KEY after table creationNot supported — FKs must be declared at CREATE TABLE time
DROP FOREIGN KEYNot supported

When DeepDiff DB detects a column modification on a SQLite database, it logs a warning and skips the statement. The recommended approach for column modifications in SQLite is to recreate the table (create new → copy data → drop old → rename), which schema-migrate does not currently automate.

Foreign Key Handling

SQLite foreign key enforcement is opt-in and must be enabled per-connection with PRAGMA foreign_keys = ON. DeepDiff DB enables this pragma automatically when connecting to SQLite databases. During pack apply, FKs are temporarily disabled:

PRAGMA foreign_keys = OFF;
-- ... data changes ...
PRAGMA foreign_keys = ON;

Use Cases

SQLite is most useful for:

  • Local development environments
  • Embedded applications that use SQLite as their primary store
  • Testing and sample projects (all DeepDiff DB samples 03–14 use SQLite)