Liking cljdoc? Tell your friends :D

com.blockether.vis.internal.persistance.sqlite.migration

Flyway-backed schema migration runner.

Lives in the SQLite extension because:

  1. The dialect-specific Flyway driver (flyway-database-nc-sqlite) is required to recognize jdbc:sqlite: URLs - already declared in this extension's deps.edn.
  2. Flyway is the only backend-side concern using flyway-core; making it a per-backend dep keeps the root package free of the migration toolchain.
  3. The previous arrangement shipped a generic migrate! from com.blockether.vis.sdk, but it had exactly one caller
    • this extension. Other backends will ship their own migration entry point in their own jar.

Public API:

(migrate! datasource locations) - apply every Flyway migration found at the given classpath locations to the supplied DataSource. Returns the datasource for thread-style chaining.

:baseline-on-migrate true so existing databases without a flyway_schema_history table get one on first run. :mixed true so SQL files with mixed transactional + DDL statements work under SQLite.

GraalVM native-image note: Flyway discovers migrations by LISTING the classpath location directory, which native-image does not support (it can getResource a specific file but not enumerate a dir). So build.clj writes an _index.edn of filenames next to each migration dir, and here we feed Flyway an explicit ResourceProvider built from those exact paths, paired with an empty Java migration ClassProvider for our SQL-only schema. Both providers are required to bypass scanning. On the JVM (no index) we fall back to Flyway's normal location scanning.

Flyway-backed schema migration runner.

Lives in the SQLite extension because:

  1. The dialect-specific Flyway driver (`flyway-database-nc-sqlite`)
     is required to recognize `jdbc:sqlite:` URLs - already
     declared in this extension's deps.edn.
  2. Flyway is the only backend-side concern using
     `flyway-core`; making it a per-backend dep keeps the root
     package free of the migration toolchain.
  3. The previous arrangement shipped a generic `migrate!` from
     `com.blockether.vis.sdk`, but it had exactly one caller
     - this extension. Other backends will ship their own
     migration entry point in their own jar.

Public API:

  `(migrate! datasource locations)` - apply every Flyway
  migration found at the given classpath `locations` to the
  supplied `DataSource`. Returns the datasource for thread-style
  chaining.

`:baseline-on-migrate true` so existing databases without a
`flyway_schema_history` table get one on first run. `:mixed true`
so SQL files with mixed transactional + DDL statements work under
SQLite.

GraalVM native-image note: Flyway discovers migrations by LISTING the
classpath location directory, which native-image does not support (it can
`getResource` a specific file but not enumerate a dir). So `build.clj` writes
an `_index.edn` of filenames next to each migration dir, and here we feed
Flyway an explicit `ResourceProvider` built from those exact paths, paired
with an empty Java migration `ClassProvider` for our SQL-only schema. Both
providers are required to bypass scanning. On the JVM (no index) we fall
back to Flyway's normal location scanning.
raw docstring

column-fillclj

(column-fill table column)

The column-fills expression of column in table, or nil. An import of rows from before the column uses it too.

The `column-fills` expression of `column` in `table`, or nil. An import of rows from before the
column uses it too.
sourceraw docstring

drop-column!clj

(drop-column! ds locations table column)

Drop column from table in one transaction, and build again each schema object of the canonical SQL that names it. Answer true when the column was dropped, false when the table has no such column, and :low-disk when there is no space for the copy of the table that SQLite writes.

Drop `column` from `table` in one transaction, and build again each schema object
of the canonical SQL that names it. Answer true when the column was dropped, false
when the table has no such column, and `:low-disk` when there is no space for the
copy of the table that SQLite writes.
sourceraw docstring

migrate!clj

(migrate! ds locations)
(migrate! ds locations {:keys [shared?]})

Install the single canonical V1 schema.

Applied checksum drift and history left by migrations later consolidated into V1 self-heal through Flyway repair, then migration is retried. Repair changes only flyway_schema_history; persisted Vis rows and schema objects are preserved. Databases created by an older V1 are then topped up additively by reconcile-canonical-columns!, given every index the canonical file has gained since (install-missing-canonical-indexes!), realigned by realign-drifted-columns! wherever a column's own definition changed, and stripped of retired-columns, so one canonical migration keeps serving stores that already exist.

A store that a newer Vis migrated is refused with newer-store-error, and nothing in it changes. With :shared? true, another process has the store open, maybe an older Vis that still uses the retired columns and values. The retired values, rows, copies and columns then stay, and so does the recorded generation: a later open that has the store alone removes them (#455).

Install the single canonical V1 schema.

Applied checksum drift and history left by migrations later consolidated
into V1 self-heal through Flyway `repair`, then migration is retried. Repair
changes only `flyway_schema_history`; persisted Vis rows and schema objects
are preserved. Databases created by an older V1 are then topped up additively
by `reconcile-canonical-columns!`, given every index the canonical file has
gained since (`install-missing-canonical-indexes!`), realigned by
`realign-drifted-columns!` wherever a column's own definition changed, and
stripped of `retired-columns`, so one canonical migration keeps serving stores
that already exist.

A store that a newer Vis migrated is refused with `newer-store-error`, and
nothing in it changes. With `:shared? true`, another process has the store open,
maybe an older Vis that still uses the retired columns and values. The retired
values, rows, copies and columns then stay, and so does the recorded generation: a
later open that has the store alone removes them (#455).
sourceraw docstring

newer-store-errorclj

(newer-store-error connectable cause)

An error that names the cause when a newer Vis has migrated the store of connectable (a DataSource or an open Connection), else nil. cause is the failure that made the caller ask, or nil.

An error that names the cause when a newer Vis has migrated the store of
`connectable` (a `DataSource` or an open `Connection`), else nil. `cause` is the
failure that made the caller ask, or nil.
sourceraw docstring

reorder-table!clj

(reorder-table! ds locations table)

Give table the column order of the canonical SQL. Answer true when the table was built again, false when no change is needed or possible, and :low-disk when there is not enough space for the copy.

SQLite reads a column that comes after a large BLOB only through all the overflow pages of that BLOB, so the canonical SQL puts a large BLOB last. A store that got its columns in an older order keeps that order, because SQLite cannot move a column: only a new table can change it.

The new table gets each row, each index and each trigger of the old one. A column that the canonical SQL does not name keeps its stored definition and comes last. One transaction, so a stopped rebuild leaves the table as it was. A table that the copy cannot keep exactly stays as it is: a column without a definition that the parser reads, a generated column, or a constraint that only the old table has. Foreign-key checks are off on this connection during the copy: the rows are those that the store holds already, and a check would refuse an old row whose parent is gone.

Give `table` the column order of the canonical SQL. Answer true when the table was
built again, false when no change is needed or possible, and `:low-disk` when
there is not enough space for the copy.

SQLite reads a column that comes after a large BLOB only through all the overflow
pages of that BLOB, so the canonical SQL puts a large BLOB last. A store that got
its columns in an older order keeps that order, because SQLite cannot move a
column: only a new table can change it.

The new table gets each row, each index and each trigger of the old one. A column
that the canonical SQL does not name keeps its stored definition and comes last.
One transaction, so a stopped rebuild leaves the table as it was. A table that the
copy cannot keep exactly stays as it is: a column without a definition that the
parser reads, a generated column, or a constraint that only the old table has. Foreign-key
checks are off on this connection during the copy: the rows are those that the
store holds already, and a check would refuse an old row whose parent is gone.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close