Skip to main content

Module sqlite

Module sqlite 

Source
Expand description

SQLite migrations (since 0.4.0): the same contract as the PostgreSQL ones, through a SqliteStore. migrations/sqlite/*.sql, embedded, applied in order with the same tracking table; check compares the live file’s schema with what the migrations produce in a scratch database in memory.

Constants§

MIGRATIONS
Every SQLite migration, in order. One so far: the schema of the PostgreSQL migrations 1-4 at once (there is no earlier SQLite schema to migrate from).

Functions§

apply
Applies the migrations not yet applied and returns their versions (empty when the schema is current). All of it is one write transaction (BEGIN IMMEDIATE; SQLite’s schema changes are transactional), so concurrent callers, in this process or others, are serialised by the database’s write lock, and a failure leaves nothing half applied. A migration whose recorded checksum differs from its SQL is an error.
catalog
The schema as sorted lines: each table, index and trigger with its SQL (whitespace collapsed), the indexes SQLite makes for keys, and the recorded migrations.
check
Compares the live file’s schema with what the migrations produce (a store from SqliteStore::open_existing checks without creating or changing anything; SqliteStore::open creates a missing file): applies every migration to a scratch database in memory, then diffs the two catalogs. Returns the differences, - <line> for what the live database lacks and + <line> for what it has in addition; empty when they agree.
check_file
check of the file at path, opened with SqliteStore::open_existing: a path with no file is an error (no such database file) and nothing is created. Since 0.4.0.