Migration · Works on: Cockroach Continuum, CockroachDB Cloud, self-hosted · Tested: weekly in CI against the latest CockroachDB · Stack: Go, lib/pq, MOLT · Code:
migrations/miniflux-port v1.0.0lib/pq, and
written for PostgreSQL. This project ports Miniflux 2.3.5 to CockroachDB as 13 patches, one change each, and
checks the result with Miniflux’s own tests: all 53 unit-test packages and all 106 API integration tests pass
on CockroachDB. It goes with the Cockroach University course Port a PostgreSQL App to CockroachDB: What Changes.
The port changes 10 files: 273 lines added and 131 removed, most of them in the migrations. The driver,
the HTTP API, the web UI and almost all of the SQL stay as they were. The patches modify Miniflux; Miniflux’s
own source isn’t in the Cookbook repository, and scripts/get-miniflux.sh downloads it.
Get the code
The code is in the Cockroach Cookbook repository. To fetch only this project at the version this page describes:Run it locally
You need Go 1.26 or later, git and thecockroach binary, v26.1 or later.
git log -p 2.3.5.. in miniflux/ shows each change with its reason.
Run it on CockroachDB Basic
These steps use a CockroachDB Basic cluster, which existing CockroachDB Cloud organizations can create. New organizations are on Cockroach Continuum: create a cluster with the Continuum quickstart and use its connection string in the same steps. Continuum pricing differs from the Basic prices on this page; see Continuum pricing.
- Create a Basic cluster and a SQL
user, then run
CREATE DATABASE miniflux;in a SQL shell on it. - Set
DATABASE_URLto that user’s connection string with/minifluxas the database andsslmode=verify-full. - Start Miniflux with
RUN_MIGRATIONS=1once, as above, to build the schema.
What it costs
CockroachDB Basic charges for Request Units (RUs) and storage: $0.20 per million RUs and $0.50 per GiB-month, with a $15 monthly allowance for pay-as-you-go organizations (Plan a CockroachDB Basic cluster, October 2026). Most of Miniflux’s database work is feed refreshes, so the RUs it uses grow with the number of feeds and how often they’re polled (POLLING_FREQUENCY, 60 minutes by default); the cluster’s Overview page shows the RUs yours use.
Run Miniflux’s tests on CockroachDB
go vet and gofmt, against cockroachdb/cockroach:latest on every change and weekly.
Assess Miniflux
The schema
schema/miniflux-2.3.5-schema.sql is Miniflux 2.3.5’s schema as pg_dump -s --no-owner --no-privileges (pg_dump 18.6) writes it, from a database built by Miniflux’s own migrations: 14 tables,
20 indexes, 7 sequences and 5 enum types. Upload it to the
Schema Conversion Tool (Schema Conversion
under Data on any CockroachDB Cloud cluster, then Add Schema, PostgreSQL) to see what it reports:
- 2 Required Fixes: the
\restrictand\unrestrictlines pg_dump 18 adds, which arepsqlcommands, not SQL. Delete them in the tool and click Retry Migration. - 17 Suggestions: the 7 sequences and the 7
idcolumns that use them,schema_versionwithout a primary key, and two indexed timestamp columns.
The application
The application finds the rest, starting with its migrations.scripts/assess.sh runs unpatched Miniflux 2.3.5’s
migrations on a fresh miniflux_assess database and prints where they stop; --replay does it again after each
commit on the cockroachdb branch until they run to the end, so each change shows the failure it fixes
(about 4 minutes):
What changes, and why
Patches 0001 to 0009 were found by running the migrations; 0010 and 0011 by Miniflux’s integration tests;
0012 by reading how the web UI and the APIs use IDs; and 0013 by running concurrent refreshes (below).
Why the migrations can change
The patches change what some historical migrations do. That’s safe here because, on CockroachDB, Miniflux’s migrations only ever run from version 0 on a new, empty database: an existing database moves in with MOLT (below) after the migrations have built the schema. A backfill with no rows to update, or a type conversion of an empty column, has nothing to do, so the patches create each column with its final type and skip the step. Migrations added after 2.3.5 will run on databases with data, so they need to follow the rules inAGENTS.md.
Patch 0001 keeps each migration in one transaction, as Miniflux’s runner expects. CockroachDB gives
CREATE TABLE and CREATE INDEX in a transaction the same atomicity as other statements, but most other
schema changes in a multi-statement transaction can fail at COMMIT after the transaction’s other
statements have committed, with error XXA00
(Schema changes within transactions).
On a new, empty database that’s unlikely (a unique index that finds duplicates is one cause), and the fix is
to start again on a new database. On a database with data, a migration that changes an existing table should
make one schema change, and an XXA00 means checking the schema by hand before running it again.
IDs
CockroachDB’s default forSERIAL, unique_rowid(), spreads inserts well, but it makes IDs such as
1224403685310201857. Miniflux’s web UI reads entry IDs with parseInt, and a JavaScript number can’t hold an
integer above 2^53 exactly, so marking an entry read would send a rounded ID. Patch 0012 sets
serial_normalization to sql_sequence_cached during
migrations, so SERIAL creates a sequence whose values each session caches, in blocks of
sql.defaults.serial_sequences_cache_size (256 by default):
- Most sequences cache 256 values per session. A sequence without a cache adds a write for every row; on a
single node it doubled the cost of an insert, and the feed tests timed out. With the cache, inserts cost
about what they do with
unique_rowid(), and IDs from different connections aren’t in insert order. entries_id_seqhas no cache (PER SESSION CACHE 1). Fever’ssince_idand the API’safter_entry_iduse entry IDs as a cursor (“give me entries after the newest one I have”), so they need to arrive in insert order. That costs time: the integration suite takes 56 seconds this way, 36 with every sequence cached and 32 withunique_rowid().
Search
Search matches the same words, andts_rank still orders the results, with two differences from 2.3.5:
- A match in an entry’s title no longer ranks above a match in its content, because
setweight()isn’t available. - The web-search syntax (quoted phrases,
OR,-word) isn’t parsed. Every word must match, and a word with punctuation, such as2.0.8, must match in order.
2.0.8 finds the one entry that has it, and a search for only stop words, such as the,
returns no entries instead of an error.
Retries
CockroachDB runs every transaction atSERIALIZABLE isolation and returns SQLSTATE 40001 when one conflicts
with a concurrent transaction, for the client to run it again (retry errors).
scripts/refresh-load.sh measures this. For 90 seconds, 16 threads (the size of Miniflux’s worker pool)
refresh 40 local feeds that gain items every 2 seconds, while 4 more mark entries read and flush history:
Every failure was in the per-entry transaction in
RefreshFeedEntries, which reads whether an entry exists
and then inserts or updates it. Mark-as-read and flush-history are single statements, and CockroachDB
retried those itself. Patch 0013 adds inRetryableTransaction (40001 only, up to 5 attempts, randomized
backoff) and uses it there. Numbers are from one run on a laptop single node; a cluster will differ.
Move an existing Miniflux database
An existing Miniflux 2.3.5 database on PostgreSQL moves with MOLT Fetch and is checked with MOLT Verify, following the Classic Bulk Load approach: Miniflux stops, the data loads, and Miniflux starts again on CockroachDB. With Miniflux stopped and themolt binary installed:
molt/move.sh drops and recreates DST_DB on the local node, then:
- Builds the schema with the ported migrations, so the target has the port’s sequences, indexes and types.
- Drops the target’s foreign keys, because MOLT loads tables in parallel and a child row can arrive before its parent.
- Copies the data with MOLT Fetch, leaving out
schema_version(no primary key; the migrations already set it to 135) andentries.document_vectors(molt/transforms.json). - Adds the foreign keys back, which checks every copied row against them.
- Rebuilds
entries.document_vectorswith the expression the port uses. MOLT doesn’t copytsvectorvalues, and they need rebuilding anyway: vectors built from2.0.8as one word wouldn’t match a search for its pieces. - Moves each sequence past the highest copied ID.
- Compares every row on both sides with MOLT Verify.
molt/seed.py fills one through the API of a running, unpatched
Miniflux 2.3.5 (2 users, 42 feeds, 1,095 entries, 364 enclosures), and molt/check.py checks the moved copy
through the ported app: the same counts per user, a search for 4.17.1 that finds its one entry, and a
refresh whose new entries get IDs after the copied ones. On that data every row matched in all 13 tables.
MOLT keeps its progress in _molt_* tables in the target; Miniflux ignores them, and they can be dropped after the move.
Start small, grow without switching
Miniflux is a small app: one process and a handful of tables, and a single node is plenty for it. Nothing in the patches depends on the size of the cluster: the same build connects to a laptop node or to a CockroachDB Basic cluster, through the same PostgreSQL driver. The ID and retry changes are the ones that matter once there’s more than one node, so they’re made for that from the start. The tests in this project run on a single node.License
The patches modify Miniflux (Copyright The Miniflux Authors) and, like Miniflux, are licensed under Apache-2.0. SeeNOTICE.
