Skip to content

Releases

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 07 Nov 22:23
85eee01

Contract 25.32: enum columns, UNIQUE over several columns, table ownership

This release adopts provider contracts 25.31 and 25.32 (stokaro/ptah#5667).
It needs a Ptah of contract 25.32 or later that lists
planning.table-ownership:

ptah providers install duckdb

An older Ptah, or one that does not list table ownership, is refused when it
starts the provider. Table ownership is now the provider's only claim on
DuckDB's tables, so without it Ptah would hand the provider no table to plan.
Pre-v1, no compatibility with v0.1.0's hosts is kept.

Enum columns

An enum column is DuckDB's ENUM type, which lists its values in the column's
type. Ptah lowers a declared enum to it (schema.enum-columns), whether a
named type declares the values (CREATE TYPE mood AS ENUM (...), a Go enum
field) or the column writes them, so the column is ENUM('happy', 'sad') and
no named type is created. The table converges on the next plan.

A changed value list changes the column's type in place with ALTER COLUMN ... TYPE. Rows keep their values by text; a row that holds a value the new
list leaves out makes DuckDB refuse the statement, and the plan rolls back.

UNIQUE over several columns

A read reports every UNIQUE constraint with DuckDB's name and its columns in
order (schema.observed-unique-constraints). A table with a UNIQUE over
several columns no longer fails the read, and a declaration of one no longer
fails validation:

  • CREATE TABLE writes it as UNIQUE ("a", "b");
  • on a table that exists, ALTER TABLE ... ADD UNIQUE ("a", "b") adds it,
    after the statements that add its columns. DuckDB refuses it while two rows
    share its values, and the plan rolls back;
  • dropping one, or dropping a column it covers, is refused by name: DuckDB has
    no statement for either.

DuckDB names the constraint itself (m_a_b_key). The plan compares a UNIQUE
by its columns in order, never by name, so a declaration that names it
differently plans nothing, and the creation notes the declared name DuckDB will
not keep.

A Ptah that does not read UNIQUE constraints still receives a single-column
UNIQUE as the column's flag, and is refused a table with one over several
columns.

Collations

Ptah compares a column's collation as an aspect of its own
(schema.column-collations), and the provider refuses a changed collation by
name. The type comparison no longer carries the collation for such a Ptah.

Fixed

  • Adding a primary key to a table that exists failed with an internal error:
    the step named the table twice among its effects, which the SDK refuses. A
    key, and now a UNIQUE over several columns, alters its columns and runs after
    the statements that add them or make them NOT NULL.

Conformance

The SDK's conformance suite runs its lock check in process
(conformance.Live.InProcessLocks): a second session of the provider process
must find a held lock busy, and a second process must fail to open the
database. live.locks now passes.

One check fails by the contract rather than by the provider:
description.valid under a host that lists no two-way feature. Such a host
negotiates table ownership away, which leaves the provider's only planning
service planning nothing, and the SDK refuses the host at Describe. The
suite accepts that refusal from a host that leaves out one feature but not
from one that lists none. The test pins that exact failure, and the gap is
recorded for a later contract minor.

Upgrading

Upgrade Ptah first to a release of contract 25.32, then the provider. The
provider's own records, the revision table, run log and tags, keep their
layout; nothing in a database changes on upgrade.

Contract 25.33: view queries, render omissions, conformance

This release builds the provider with provider-sdk v0.31.0, which speaks
contract 25.33 (stokaro/ptah#5667). It still needs a Ptah of contract 25.32 or
later that lists planning.table-ownership:

ptah providers install duckdb

Both additions below are negotiated. A Ptah of contract 25.32 runs this
release as it ran v0.2.0, apart from the new plan notes, which come from the
provider.

View queries compared as DuckDB writes them

The provider answers whether a declared view's query and the one DuckDB holds
are one query (schema.view-query-equivalence). It writes both texts back
through DuckDB's parser in a private in-memory database and compares them
exactly.

DuckDB names a view's column after its alias and keeps the alias's case, so
SELECT id AS "ID" FROM t and SELECT id AS "Id" FROM t give the view
different columns. Ptah's own comparison of the texts folds case, so a
declaration that changed only the case of an alias planned nothing and the
view kept its old column. With a Ptah of contract 25.33 the view is replaced
and holds the declared column.

Measured on the embedded DuckDB 2.0.0, every one of 36 view shapes (literals,
casts, joins, IN, BETWEEN, LIKE, CASE, subqueries, UNION, SELECT *, * EXCLUDE, aliases) converges either way. DuckDB keeps * as written,
so the provider loses nothing the host's text comparison found: Ptah's
expansion of * into declared columns is not needed for DuckDB.

A change of case in a name other than an alias, such as SELECT ID FROM T
for SELECT id FROM t, now replaces the view once, since DuckDB stores the
query as written. The view converges on the next plan.

Types DuckDB keeps in part

DuckDB accepts these types and creates the column with a type of its own,
without an error. Measured on the embedded DuckDB 2.0.0:

Declared DuckDB holds
VARCHAR(255), CHAR(3), BPCHAR(4), CHARACTER VARYING(10) VARCHAR, any length (300 characters fit VARCHAR(255))
VARCHAR(5)[] VARCHAR[]
BIT(8), BIT VARYING(8) BIT, any length ('1010' fits BIT(1))
TIMESTAMP(1), TIMESTAMP(2) TIMESTAMP_MS
TIMESTAMP(4), TIMESTAMP(5) TIMESTAMP
TIMESTAMP(7), TIMESTAMP(8) TIMESTAMP_NS

TIMESTAMP(0), (3), (6) and (9) are kept. FLOAT(p) and DECIMAL(p,s)
lose nothing. DuckDB refuses TIME(p), TIMESTAMPTZ(p) and a DECIMAL
wider than 38.

A plan already noted a text length. It now also notes a bit length and a
timestamp precision:

-- DUCKDB: column "flags" of table "readings" is declared BIT(8); DuckDB keeps no length and holds it as BIT, which takes bits of any length.
-- DUCKDB: column "taken" of table "readings" is declared TIMESTAMP(1); DuckDB does not keep precision 1 and holds it as TIMESTAMP_MS, which keeps milliseconds.

For a Ptah that lists render.omissions (contract 25.33), a render also
reports each one as an omission of the column: reason unsupported, property
type modifier, detail such as VARCHAR(255): length 255, and a remedy where
one exists, such as a CHECK on the column's length. A program that renders
through Ptah's Go API and must not lose a declaration can refuse the
rendering. Ptah's commands print the notes, not the omissions.

The table operation model moves to schema version 3, which carries the
declared type beside the type DuckDB holds. A plan saved by v0.2.0 is refused
by this release; plan again. Pre-v1, no compatibility is kept.

Conformance

With contract 25.33 the SDK's conformance suite treats a host that lists no
two-way feature, and a contract 25.0 host, as it treats a host that leaves
out one feature (ADR 0114). The provider refuses such a host, since without
table ownership its only planning service plans nothing, and the suite counts
the refusal as the answer negotiation asks for. Every check passes, including
description.valid and handshake.contract-25.0-host, which v0.2.0's test
pinned as a known failure.

Upgrading

Upgrade the provider; Ptah v0.23.0 (contract 25.32) keeps working with it, and a
Ptah of contract 25.33 adds the view query comparison and the omissions. The
provider's own records, the revision table, run log and tags, keep their
layout; nothing in a database changes on upgrade.

DuckDB's text read by Ptah's PostgreSQL-family lexer

The provider splits migration bodies and analyzes SQL with pgsyntax from
github.com/stokaro/ptah/sqlsyntax v0.1.0, the lexer Ptah reads the
PostgreSQL family with (stokaro/ptah#5586, #8). A nested block comment is one
comment, so a migration whose comment holds a semicolon after its inner comment
runs, where the provider cut it there and DuckDB refused the first half. Dollar
quotes, escape strings and strings continued on the next line are read as
DuckDB reads them, including DuckDB's reading of an escape string continued by
a segment that ends in a backslash. A refusal names the construct that does not
close and its line. A stray $ or a backtick is left to DuckDB to refuse.

What's Changed

  • Adopt provider contracts 25.31 and 25.32 by @denisvmedia in #7
  • Adopt provider contract 25.33: view queries, render omissions by @denisvmedia in #9
  • Read DuckDB's text with the shared PostgreSQL-family lexer by @denisvmedia in #8
  • Test every refusal the limitations page advertises by @denisvmedia in #10
  • Say that a renamed index is dropped and created by @denisvmedia in #11
  • Install each published release fresh and start it by @denisvmedia in #12
  • Publish only a commit whose CI run passed by @denisvmedia in #13

Full Changelog: v0.1.0...v0.2.0

v0.1.0

Choose a tag to compare

@github-actions github-actions released this 07 Nov 11:28
2484931

The first release of the DuckDB provider

This is the first release of github.com/stokaro/ptah-duckdb-plugin, the
provider that gives Ptah a DuckDB engine (stokaro/ptah#5667). Ptah builds in
no DuckDB engine, so this provider is the only way to reach DuckDB, and Ptah
itself stays free of cgo and of any DuckDB dependency.

Install it on a Ptah of provider contract 25.30 or later:

ptah providers install duckdb

A command that names a duckdb:// address then selects it. An older Ptah
refuses to start the provider: contract 25.30 is the first that states the
host starts a provider in its own working directory, and a relative
duckdb://app.duckdb depends on it.

What runs on it

  • ptah schema apply, with its dry run, against a database file or an
    in-memory database.
  • ptah migrations generate, with --replay on a dev database.
  • ptah migrations up, down, status, tag and log, in the native and
    the Atlas revision formats, under --tx-mode file, none and all.
  • ptah migrations lint, with or without a dev database.

The embedded DuckDB

The provider links DuckDB 2.0.0 through the official Go driver,
github.com/duckdb/duckdb-go/v2 v2.20000.0, and every test runs that library.
It declares one release line, 2.0, certified by the linked library
(engine.linked-release-lines); a Ptah that does not read linked lines sees it
as best effort.

DuckDB lets one process write a file, or several read it, never both. A second
Ptah command, or any other program, that holds the file is refused with the
holder's process ID. Every database opens with external access and extension
auto-installation and auto-loading off: no statement downloads an extension,
attaches another database, or reads or writes a file but the database itself.

What DuckDB keeps differently

  • VARCHAR(n). DuckDB keeps no length. The plan compares the declaration
    as DuckDB holds it, so it converges, and carries a note naming the declared
    type and what DuckDB holds. The note is printed with the plan and written
    into a generated migration.
  • Constraint names. DuckDB names every constraint itself. CHECKs and
    foreign keys are compared by what they say, and a creation carries a note
    listing the declared names DuckDB will not keep.
  • Collations are compared as part of the column type, so a changed
    collation is refused by name instead of reported as synced.

What it refuses

DuckDB refuses many changes of a table that exists, and the provider refuses
each one by name before a statement is sent, never planning it as a drop and a
recreation:

  • type, nullability and UNIQUE changes and dropped columns while the table
    keeps an index or another table's foreign key references it;
  • a type change or a dropped column that an index dropped in the same
    transaction still covers;
  • type changes and drops of key, UNIQUE, CHECK and foreign key columns;
  • added or dropped CHECKs and foreign keys, a dropped UNIQUE, a changed or
    dropped primary key, generated columns, renamed indexes and changed
    sequences.

A read refuses what it does not describe rather than leave it out: macros,
types made with CREATE TYPE, UNIQUE constraints over several columns, views
that name their columns, compressed columns and non-ART indexes.

The migrator's records

The revision table, the run log and the tags live in DuckDB tables the
provider creates with a comment that marks them as its own. It reads and
writes a table of a store's name only when it carries the mark and exactly the
store's layout, and refuses a user's table of that name. A read reports the
marked tables as reserved, so a schema apply never plans to drop them.

Dev databases

--dev-url docker://duckdb provisions a database file in a temporary
directory, which the provider removes when the command ends; no container
starts. A database file the operator names must be empty, and
duckdb://:memory: is the process's in-memory database. The cleanup removes
everything in one transaction, and the replay guard refuses statements that
reach beyond the dev database or into the session.

Platforms

OS Architecture
Linux, glibc 2.34 or newer amd64, arm64
macOS 13 or newer arm64, amd64
Windows amd64

There is no Windows arm64, musl (Alpine) or FreeBSD build: the driver ships no
DuckDB library for them. Every archive is listed with its SHA-256 digest in
checksums.txt, and ptah providers install checks it before extracting.

Not supported yet

  • Declared rows and seed files (ptah seed, ptah migrations data), and
    provider lint rules.
  • Macros and named types in a read.
  • An opt-in to external access or to an extension DuckDB does not link.
  • duckdb://:memory:<name> as a --db-url or --dev-url: Ptah parses the
    address as a URL first and refuses it. duckdb://:memory: works.
  • Network, MotherDuck, DuckLake and Quack: the provider serves the embedded
    file and in-memory modes only.

What's Changed

New Contributors

Full Changelog: https://github.com/stokaro/ptah-duckdb-plugin/commits/v0.1.0