Skip to content
Hardcount
Run it locally
Pre-1.0 · one maintainer · Stripe and cards only · no SDKs (client libraries) yet · no production users yet. Docs describe v0.12.0 (30 Nov 2026) · What’s new →

Upgrade Hardcount

An upgrade moves Hardcount to a newer release. Its database changes (migrations) run as part of the upgrade. Take a backup first: it is the only way back.

  1. Read the notes for every release between yours and the new one. A release with steps to take lists them in the changelog under Before upgrading, and in its GitHub release under Before you upgrade. What a release may change: Versioning.
  2. Take a backup. On one VM, run sudo hardcount-backup (set it up) and wait for Verified: yes. With a managed Postgres, take a snapshot, or note the time if it has point-in-time restore.
  3. See the plan. Run hardcount migrate status with the new release. It only reads: it shows the database’s version, the migrations the new release would apply, and whether a migration is running now. If it says no migration record, stop: the upgrade will not run (why). An install older than v0.11.0 upgrades to v0.11.0 first, then onward (how).

Releases after v0.11.0 start from v0.11.0’s database schema. An install of an earlier release upgrades to v0.11.0 first, then onward: two upgrades, each one as this page says. The steps under Upgrade to v0.11.0 apply to the first one. A later release started on a database from before v0.11.0 changes nothing: hardcount migrate status says no migration record and where the database’s record stops, and hardcount migrate stops with a message that names v0.11.0.

Hardcount was called Velox before v0.9.0. v0.9.0 installs fresh only: it refuses a database made by Velox, a 0.8.x release or a build of Velox’s main (why). A Velox install on one VM does not get that far: its .env names VELOX_* settings, so docker compose pull (or build, from source) stops with required variable HARDCOUNT_APP_DB_PASSWORD is missing a value. A backup made by Velox cannot be restored into Hardcount either: hardcount migrate status reports no migration record for a Velox 0.8.x backup, and made by Velox for one from a later build.

Install Hardcount fresh, with an empty database: a new VM, or a new Compose data volume. Start from Install a pinned release.

These sections apply on the way to v0.12.0, to an install on v0.11.0.

Migration 00260: a subscription holds one plan

Section titled “Migration 00260: a subscription holds one plan”

v0.12.0, with migrations 00260_one_plan_per_subscription to 00263_idx_subscriptions_customer_active, gives each subscription one plan, in place of its items. A customer who needs two plans gets two subscriptions, which may not bill the same meter. A subscription that the demo, the tutorials or the dashboard’s default made has one item, and it bills exactly as before.

What the migration does:

  • One item: the subscription takes the item’s plan and its scheduled plan change. Its billing intervals (which plan covered which days) stay.
  • More than one item (POST /v1/subscriptions with several items, or Add item in the dashboard): the subscription keeps its oldest item’s plan. Each other item becomes a subscription of its own, named after its plan, with the item’s plan, scheduled change and billing intervals, and the original’s customer, status, billing time, period, next invoice date and scheduled cancel. It started when the item was added, if that is later. Its next invoice bills what the item would have billed, on an invoice of its own. No webhook is sent and no audit log entry is written.
  • A canceled subscription, split off or not, keeps no scheduled plan change.
  • An item an earlier release removed in the middle of a period: its billing interval is deleted when it overlaps an interval of the item the subscription keeps, or an interval of another removed item that ends later. So the kept item’s intervals stay, and of two overlapping intervals of removed items, the one that reaches further forward stays. An interval that overlaps neither stays, and the close bills it. Nothing bills the days of a deleted interval: see steps 2 and 3.
  • A canceled subscription with no item left takes the plan of the item removed last. One with no item at all keeps no plan.
  • The rest goes: the table subscription_items, with each item’s metadata, which no route writes.

A period in which an earlier release moved an item to another plan is still billed part by part at its close, each part at its own plan, for its own days.

Before you upgrade, on v0.11.0:

  1. List the subscriptions with more than one item, in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM). code_after is each subscription’s code after the upgrade: the row with place 1 stays on the subscription, and each other row becomes a new subscription with that code.

    SET app.bypass_rls = 'on';
    SELECT x.subscription_id, x.tenant_id, x.livemode, x.status, x.item_id, x.plan_id, x.place,
    CASE WHEN x.place = 1 THEN x.code
    WHEN EXISTS (SELECT 1 FROM subscriptions o
    WHERE o.tenant_id = x.tenant_id AND o.livemode = x.livemode
    AND o.code = x.code || '-' || x.place)
    THEN x.code || '-' || x.item_id
    ELSE x.code || '-' || x.place END AS code_after
    FROM (SELECT s.id AS subscription_id, s.tenant_id, s.livemode, s.status, s.code,
    i.id AS item_id, i.plan_id,
    row_number() OVER (PARTITION BY s.id ORDER BY i.created_at, i.id) AS place,
    count(*) OVER (PARTITION BY s.id) AS items
    FROM subscriptions s
    JOIN subscription_items i ON i.subscription_id = s.id AND i.deleted_at IS NULL) x
    WHERE x.items > 1
    ORDER BY x.tenant_id, x.subscription_id, x.place;

    You see: one row for each item of each such subscription, or (0 rows). The billing intervals of an item with place 2 or more move with it to its new subscription, which bills them. After the upgrade, an integration that stored the subscription’s id, to cancel it or to read its invoices, must learn the new subscriptions’ ids: find them by code with GET /v1/subscriptions?search=<code_after>. From its next invoice on, each item’s part is billed on its new subscription.

  2. List the billing intervals the upgrade deletes from open periods. The query applies the migration’s rule to each active subscription. It lists each interval the upgrade deletes that covered part of the open period. unbilled_from and unbilled_to are that part: the later of the interval’s start and the period’s start, and the earlier of its end and the period’s end. An interval deleted outside the open period changes no invoice, because the periods it lies in are already invoiced.

    SET app.bypass_rls = 'on';
    SELECT s.id AS subscription_id, s.tenant_id, s.livemode, s.code, s.customer_id,
    bi.subscription_item_id AS item_id, bi.plan_id,
    GREATEST(bi.starts_at, s.current_billing_period_start) AS unbilled_from,
    LEAST(COALESCE(bi.ends_at, 'infinity'), s.current_billing_period_end) AS unbilled_to
    FROM subscriptions s
    JOIN billing_intervals bi ON bi.subscription_id = s.id
    JOIN subscription_items i ON i.id = bi.subscription_item_id
    JOIN LATERAL (SELECT k.id FROM subscription_items k
    WHERE k.subscription_id = s.id AND k.deleted_at IS NULL
    ORDER BY k.created_at, k.id
    LIMIT 1) kept ON true
    WHERE s.status = 'active'
    AND i.deleted_at IS NOT NULL
    AND bi.starts_at < s.current_billing_period_end
    AND (bi.ends_at IS NULL OR bi.ends_at > s.current_billing_period_start)
    AND EXISTS (
    SELECT 1
    FROM billing_intervals o
    JOIN subscription_items oi ON oi.id = o.subscription_item_id
    WHERE o.subscription_id = s.id
    AND oi.id <> i.id
    AND tstzrange(o.starts_at, COALESCE(o.ends_at, 'infinity'))
    && tstzrange(bi.starts_at, COALESCE(bi.ends_at, 'infinity'))
    AND (oi.id = kept.id
    OR (oi.deleted_at IS NOT NULL
    AND (COALESCE(o.ends_at, 'infinity'), o.id)
    > (COALESCE(bi.ends_at, 'infinity'), bi.id))))
    ORDER BY s.tenant_id, s.id, unbilled_from;

    You see: one row for each such interval, with its plan and item, or (0 rows). Keep the output: after the upgrade, nothing bills these days.

  3. After the period of each listed subscription closes, bill each row of step 2 once on a one-off invoice (POST /v1/invoices), as Invoice timing and late usage bills usage that missed an invoice. Bill only the days from unbilled_from to unbilled_to:

    • the base fee of the row’s plan, if it bills in arrears, prorated as Hardcount does: the fee times the whole days from unbilled_from to unbilled_to, over the period’s days;
    • usage only for a meter that the row’s plan prices and the plan the subscription keeps (its plan_id after the upgrade) does not. Count only the events from unbilled_from to unbilled_to: total_units from GET /v1/usage-events/aggregate?customer_id=<customer_id>&meter_id=<meter>&from=<unbilled_from>&to=<unbilled_to>, with the labels of the price’s dimension_match, priced at the price’s rate.

    If the kept plan prices the meter, the subscription’s own close bills that usage at the kept plan’s price, so do not bill it again. Never bill from the interval’s own starts_at: it can lie in periods already invoiced.

  4. If this database ever ran Hardcount 0.9.2 or earlier, run the check of Base fees missed at a scheduled plan change now: it reads the items this upgrade removes.

  5. Stop every copy of v0.11.0 before the new release migrates: v0.11.0 reads subscription_items, which the migration drops (Upgrade two or more copies).

What an API client loses, and gets:

  • Create: POST /v1/subscriptions takes plan_id. A body with items is refused with 422, param items, as any unknown field is.
  • A subscription carries plan_id, pending_plan_id and pending_plan_effective_at, and no items, in every answer and in every subscription.* webhook payload. A webhook stored or queued before the upgrade keeps the payload it was built with.
  • Plan changes: POST /v1/subscriptions/{id}/schedule-plan-change with {"plan_id": "hc_pln_…"} schedules one for the end of the period, and DELETE /v1/subscriptions/{id}/scheduled-plan-change cancels it. Both answer the subscription. PATCH /v1/subscriptions/{id}/items/{itemID} and DELETE /v1/subscriptions/{id}/items/{itemID}/pending-change answer 404.
  • Webhook events: subscription.pending_change.scheduled, subscription.pending_change.applied and subscription.pending_change.canceled keep their names and lose item_id. A subscription sends one applied event when its change takes effect.
  • The error code item_changed no longer occurs.
  • The subscriptions export names the plan in a plan_id column, where it had plan_ids.

What else changes for a customer whose subscription was split:

  • Previews: POST /v1/invoices/create_preview with customer_id alone previews one of the subscriptions. Pass subscription_id to preview each.
  • Invoices: each subscription gets its own invoice, so tax and credit are worked out per invoice.
  • Dunning: when the final action cancels, it cancels only the subscription of the failed invoice.
  • Names: the new subscription takes its plan’s name.

In a subscription’s activity, a plan change scheduled before the upgrade keeps its line. In the dashboard, the subscription’s page shows its plan, with Change plan, in place of the items card.

Run one version at a time for this upgrade. A copy of v0.11.0 that keeps running fails on every subscription it reads or writes: the migration drops subscription_items and billing_intervals.subscription_item_id.

These sections apply on the way to v0.11.0, to an install of an earlier release that upgrades to it.

Payment methods saved with no card details

Section titled “Payment methods saved with no card details”

Releases before v0.11.0 stored every payment method Stripe saved as a card. A method of another type, such as Link, sits as type card with no brand and no last 4 digits, and Hardcount can’t charge it. The upgrade leaves these rows as they are. A later Stripe event for the same method does not change its type either: Hardcount reads the method from Stripe again, but keeps the type it stored. After you upgrade:

  1. List them in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM):

    SET app.bypass_rls = 'on';
    SELECT pm.tenant_id, pm.livemode, pm.customer_id, c.external_id, pm.id, pm.is_default, pm.created_at
    FROM payment_methods pm
    JOIN customers c ON c.tenant_id = pm.tenant_id AND c.id = pm.customer_id
    WHERE pm.type = 'card' AND COALESCE(pm.card_last4, '') = '' AND pm.detached_at IS NULL
    ORDER BY pm.tenant_id, pm.customer_id;

    You see: one row for each such payment method, or (0 rows).

  2. Send each customer a setup link for a card: Add payment method on the customer’s page, or POST /v1/customers/{id}/payment-methods/send-setup-email with an API key of its account and mode.

    You see: once the customer saves a card, it is listed as the default.

  3. Then remove the blank one: the trash button beside it on the customer’s page, or DELETE /v1/customers/{id}/payment-methods/{pm_id}. Remove it only after the card is saved, so the customer always has a method to charge.

    You see: the method is gone from the customer’s list.

The release with migration 00225_charge_hold_token changes how a charge reaches Stripe: each charge puts its Stripe payment on the invoice before any money moves (ADR-137). The migration refuses to run while an open or written-off invoice has a charge in progress or a parked charge from the previous version. The new version cannot settle those, because the previous version put nothing on the invoice before its charge reached Stripe.

  1. With the previous version still running, count them in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM):

    SET app.bypass_rls = 'on';
    SELECT count(*) FROM invoices
    WHERE status IN ('finalized', 'uncollectible')
    AND (auto_charge_claimed_until IS NOT NULL
    OR (payment_status = 'unknown' AND COALESCE(stripe_payment_intent_id, '') = ''));

    You see: a count column with one number.

  2. Above 0: leave the previous version running and count again later. Its billing run finishes a charge in progress within about an hour, and a parked charge about 25 hours after the charge.

  3. At 0: stop every copy of the previous version, then take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says. A backup taken while the count was above 0 needs one more step when it is restored (A backup with a charge in progress). Run one version at a time for this upgrade. A copy of the previous version that keeps running puts nothing on the invoice before its charge reaches Stripe, so the new version can charge that invoice a second time.

Written-off invoices count: the previous version still settles a charge on one (it records a payment it finds at Stripe, and ends a parked charge), and the new version does not. Paid and voided invoices do not count: nothing is left to settle on them.

If the count stays above 0 for more than 26 hours, the previous version is keeping a charge it cannot finish. List the invoices (the query above with SELECT id, invoice_number, status, payment_status in place of count(*)), and read the previous version’s hardcount_stale_charge_hold_resolutions_total by its result label:

  • waiting: a payment is still processing at Stripe (a bank debit takes days). Wait for it. Do not write the invoice off.
  • cannot_ask: it cannot ask Stripe about the charge: the key was revoked, or the customer was deleted in Stripe. Fix the Stripe connection so its next billing run can ask. If that cannot be fixed, write the invoice off: its next run clears the charge hold of a written-off invoice.
  • failed: a database error, which the log line names.

A parked invoice (payment_status unknown, no stripe_payment_intent_id) that Stripe can never be asked about keeps its hold after a write-off too. Look at the customer’s payments in Stripe yourself. If one is for this invoice, send its payment_intent.succeeded event again from the Stripe dashboard, and the previous version marks the invoice paid. If there is none, stop the previous version and end the parked charge by hand, then count again:

SET app.bypass_rls = 'on';
UPDATE invoices
SET payment_status = 'pending', auto_charge_claimed_until = NULL,
charge_attempt_seq = charge_attempt_seq + 1
WHERE id = '<invoice id>'
AND payment_status = 'unknown' AND COALESCE(stripe_payment_intent_id, '') = '';

If the upgrade stops with Hardcount upgrade stopped: … open or written-off invoice(s) have a charge in progress or a parked charge from the previous version, that migration changed nothing. Start the previous version again (on one VM, the steps in Upgrade on one VM with its version number), then do steps 1 to 3. If the release’s other migrations ran, the previous version logs that the database is newer than it; that is expected here. On a database you restored from a backup, do not start the previous version: see A backup with a charge in progress.

Migration 00235: draft subscriptions are canceled

Section titled “Migration 00235: draft subscriptions are canceled”

The release with migration 00235_no_draft_subscriptions removes draft subscriptions: a subscription starts when it is created. The migration does three things:

  • It cancels every draft subscription. A draft has billed nothing, so there is no invoice. No subscription.canceled webhook is sent for these subscriptions, and no audit log entry is written.
  • It deletes a webhook endpoint that listened only to subscription.activated, the event an activation sent.
  • It removes subscription.activated from every other endpoint’s event list.

Before you upgrade, on the release you run now, activate the drafts that should bill:

  1. List them in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM). The dashboard shows the same rows on the Draft tab of the Subscriptions page, one account and mode at a time.

    SET app.bypass_rls = 'on';
    SELECT id, tenant_id, livemode, code, created_at FROM subscriptions WHERE status = 'draft';

    You see: one row for each draft subscription, or (0 rows).

  2. Activate each one that should bill: Activate on the subscription’s page, or POST /v1/subscriptions/{id}/activate with an API key of its account and mode.

    You see: the subscription’s status is active.

  3. Let the server run for one minute after the last activation, so that its subscription.activated webhook goes out. Then take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says.

The upgrade cancels a draft you did not activate. To bill it afterwards, create the subscription again: it starts billing when it is created, exactly as an activation would have. Give it a new code: the canceled subscription keeps its own.

Run one version at a time for this upgrade. A copy of the previous version that keeps running can no longer create a draft: the database refuses the row.

Migration 00249: trialing subscriptions are canceled

Section titled “Migration 00249: trialing subscriptions are canceled”

The release with migration 00249_remove_trials removes trials: a subscription is active from its creation, and bills from the start of that day. The migration does three things:

  • It cancels every trialing subscription. A trial has billed nothing, so there is no invoice and nothing is owed. No subscription.canceled webhook is sent for these subscriptions, and no audit log entry is written.
  • It deletes a webhook endpoint that listened only to subscription.trial_ended or subscription.trial_extended.
  • It removes those two events from every other endpoint’s event list.

Before you upgrade, on the release you run now, end the trial of each trialing subscription that should go on billing:

  1. List them in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM). The dashboard’s Subscriptions page marks the same rows with a Trial ends badge, one account and mode at a time.

    SET app.bypass_rls = 'on';
    SELECT id, tenant_id, livemode, code, trial_end_at, cancel_at_period_end, cancel_at FROM subscriptions WHERE status = 'trialing';

    You see: one row for each trialing subscription, or (0 rows).

  2. End the trial of each one that should bill: End trial now on the subscription’s page, or POST /v1/subscriptions/{id}/end-trial with an API key of its account and mode. This bills its first period now. A trial with a scheduled cancel cannot be ended: undo the scheduled cancel first, or let the upgrade cancel it.

    You see: the subscription’s status is active.

  3. Let the server run for one minute after the last one, so that its subscription.trial_ended webhook goes out. Then take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says.

The upgrade cancels a trial you did not end. To bill the customer afterwards, create the subscription again: it is active and bills from the start of the day it is created. Give it a new code: the canceled subscription keeps its own.

What changes for a billing period that is open when you upgrade:

  • A trial you ended before upgrading. Its first period started at midnight of the day the trial ended. Before the upgrade, usage on that day up to the trial’s end was free. After it, the period’s invoice bills that usage too. The same holds for a trial that converted by itself and is still in its first period.
  • A trial whose end has passed but that is still trialing. Its conversion had not run yet. The upgrade cancels it like any other trial and does not bill its first period. Before you stop the old version, wait until step 1’s list shows no row with trial_end_at in the past, or end those trials yourself.
  • A price changed on the day a trial ended, before it ended. For that first period, usage is billed at the price from before the change.
  • A canceled trial that you create again on the same day. The new subscription bills that day’s usage from midnight, including what the trial used. Create it the next day to leave that day free.

Run one version at a time for this upgrade. A copy of the previous version that keeps running fails on every subscription it reads: the migration drops trial_start_at, trial_end_at and activated_at, which it reads.

Migration 00251: paid prepaid-credit invoices become top-ups

Section titled “Migration 00251: paid prepaid-credit invoices become top-ups”

The release with migration 00251_dispute_loss_credit_note makes each paid invoice from v0.10.0 that sold prepaid credit and nothing else, with no tax and with its credit grant, a top-up (billing_reason topup). Refunding it then goes through commit relief (a commit_relief block on POST /v1/credit-notes), which takes the unused credit back; an ordinary credit note on it is refused. The others stay as they were, and an ordinary credit note on them is still accepted:

  • Taxed. A credit note on a taxed prepaid-commit invoice from v0.10.0 refunds the money and reverses its tax, but doesn’t take the credit back, so deduct that credit by hand (POST /v1/credits/adjust with a negative amount_cents).
  • With more than one line. The same: its credit note leaves the credit, so deduct it by hand.
  • Finalized and not paid. The earlier release’s note covers it: void it before you upgrade.
  • Voided. It takes no credit note.
  • With no grant. hardcount-doctor lists it (paid_commit_invoice_without_grant).

To list the paid ones that stayed as they were, after the upgrade:

SET app.bypass_rls = 'on';
SELECT i.id, i.tenant_id, i.invoice_number, i.tax_amount_cents
FROM invoices i
WHERE i.status = 'paid' AND (i.billing_reason IS NULL OR i.billing_reason = 'manual')
AND EXISTS (SELECT 1 FROM invoice_line_items l
WHERE l.invoice_id = i.id AND l.commit_granted_cents IS NOT NULL);

You see: one row for each, or (0 rows).

Migration 00252: a cancel on a chosen date is removed

Section titled “Migration 00252: a cancel on a chosen date is removed”

The release with migration 00252_remove_cancel_at removes the cancel on a chosen date (cancel_at). A subscription is canceled now, or at the end of the period it is in. The migration does two things:

  • An active subscription whose cancel date is the end of its current period keeps its cancel, as a cancel at the period’s end. Nothing else about it changes.
  • Every other cancel date is removed, and its subscription goes on billing. The migration cannot cancel it: a cancel needs Hardcount to make the final invoice. No webhook is sent and no audit log entry is written.

Before you upgrade, on the release you run now, deal with each subscription whose cancel date is not the end of its current period:

  1. List them in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM).

    SET app.bypass_rls = 'on';
    SELECT id, tenant_id, livemode, code, cancel_at, current_billing_period_end
    FROM subscriptions
    WHERE status = 'active' AND cancel_at IS NOT NULL
    AND cancel_at IS DISTINCT FROM current_billing_period_end
    ORDER BY cancel_at;

    You see: one row for each such subscription, with its cancel date (cancel_at) and the end of its current period, or (0 rows).

  2. Cancel now each one whose cancel date has come: Cancel, then Immediately, on the subscription’s page, or POST /v1/subscriptions/{id}/cancel with an API key of its account and mode. This bills the part of the period used.

    You see: the subscription’s status is canceled.

  3. Note the id and the cancel date of each one left. After the upgrade, cancel it on that date (Immediately), or at the end of the period that holds the date: once that period is the current one, Cancel, then At period end, or POST /v1/subscriptions/{id}/schedule-cancel.

A subscription you leave keeps billing after the upgrade, period after period, until you cancel it. Hardcount no longer holds its cancel date: only your note does. This includes one whose date had come but that the previous version had not canceled yet.

Run one version at a time for this upgrade. A copy of the previous version that keeps running fails on every subscription it reads: the migration drops cancel_at, which it reads.

Migration 00254: item changes in the middle of a period are removed

Section titled “Migration 00254: item changes in the middle of a period are removed”

The release with migrations 00253_idx_invoices_billing_period_slot and 00254_remove_item_changes_at_once removes every change to a subscription’s items that takes effect at once: an immediate plan change, a quantity change, adding an item, removing an item, and the immediate switch between monthly and yearly. A subscription’s items are set when it is created, and a plan change applies at the end of the period. No money moves in the middle of a period because the items changed.

What an API client loses:

  • Routes: POST /v1/subscriptions/{id}/items (now 404) and DELETE /v1/subscriptions/{id}/items/{itemID} (now 405: the path still takes PATCH).
  • Request fields: quantity and immediate on PATCH /v1/subscriptions/{id}/items/{itemID}, which are refused with 422, param naming the field. The route takes new_plan_id only, and always schedules the change for the end of the current period.
  • Response fields: proration and new_period_invoice on that route’s answer, which is now item and effective_at.
  • Webhook events: subscription.item.added, subscription.item.removed and subscription.item.updated. A scheduled plan change still sends subscription.pending_change.scheduled, subscription.pending_change.applied and subscription.pending_change.canceled.
  • Invoice fields: source_plan_changed_at, source_subscription_item_id and source_change_type. An invoice that an earlier release made for a change keeps its billing_reason subscription_update, its period, its lines and its amounts.
  • Error codes that no longer occur: unpaid_invoice_blocks_change, subscription_period_moved, swap_requires_atomic_path, invoice_proration_source_taken and proration_unavailable.

The migrations do four things:

  • 00253 builds the index that allows one invoice per subscription and period again, and keeps an invoice made for a change out of it by its billing_reason. It builds the index without blocking writes. 00254 gives it the old index’s name.

  • 00254 drops the log of item changes (subscription_item_changes), the trigger that wrote it and the trigger’s function, and the three invoice columns with their index and foreign key.

  • 00254 deletes a webhook endpoint that listened only to the three removed events, and removes those events from every other endpoint’s event list.

  • 00254 cancels an active subscription that has no item left. Releases up to v0.9.3 let a subscription in a trial lose its last item; it then turned active with nothing to bill, and its billing failed at every period’s end. Adding an item was the way to mend one, and that route is gone. Nothing was owed for it, so the cancel writes no invoice, sends no webhook and adds no audit log entry. To see them before you upgrade:

    SET app.bypass_rls = 'on';
    SELECT s.id, s.tenant_id, s.livemode, s.code
    FROM subscriptions s
    WHERE s.status = 'active'
    AND NOT EXISTS (SELECT 1 FROM subscription_items i
    WHERE i.subscription_id = s.id AND i.deleted_at IS NULL);

    You see: one row for each, or (0 rows). To keep billing one of these customers, create a new subscription for them after the upgrade.

Two things read differently afterwards. In a subscription’s activity, an item change that an earlier release made (an item added or removed, a quantity change, a plan change at once) keeps its line and its date, without the plan, the quantity or the charge it made. An invoice that an earlier release made for a change is labelled “Subscription change”, whichever kind of change it was.

A change made before the upgrade, in a billing period that is still open, is billed at that period’s close as it would have been: each part of the period at its own plan, for its own days. From migration 00258 a quantity no longer counts, and touching parts on one plan bill as one line (items have no quantity). From migration 00260 an added item is billed on a subscription of its own, and the days of a removed item that overlap the item the subscription keeps are billed nowhere (a subscription holds one plan).

To move a customer to another plan in the middle of a period, do one of:

  • Schedule the change for the period’s end: Change plan on the subscription’s page, or PATCH /v1/subscriptions/{id}/items/{itemID} with {"new_plan_id": "hc_pln_…"}. The current period is billed on the old plan.
  • Cancel now and create a new subscription: Cancel, then Immediately, or POST /v1/subscriptions/{id}/cancel. The cancel bills the usage so far and keeps a fee billed in advance. Then create a subscription on the other plan.

Run one version at a time for this upgrade. A copy of the previous version that keeps running fails on every invoice it reads or makes, which name the three dropped columns, and on every upcoming-invoice preview, which reads the dropped log.

Migration 00256: a cancel keeps a fee billed in advance

Section titled “Migration 00256: a cancel keeps a fee billed in advance”

The release with migration 00256_remove_cancel_refund removes the credit a cancel gave for the unused part of a fee billed in advance. A cancel now keeps that fee, paid or not, and credits nothing. An unpaid invoice of the subscription stays owed in full, and its payment retries go on.

The earlier release wrote that credit as a credit note that issued by itself, after the cancel: at once, when the invoice’s charge settled, or when a draft invoice was finalized. The migration voids every such note still waiting to issue. A waiting note has moved no money, so voiding it changes no invoice and no credit balance. No webhook is sent and no audit log entry is written.

Before you upgrade, on the release you run now, let the waiting notes issue:

  1. List them in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM).

    SET app.bypass_rls = 'on';
    SELECT cn.id, cn.credit_note_number, cn.tenant_id, cn.livemode, cn.customer_id,
    cn.invoice_id, i.invoice_number, i.status AS invoice_status, i.payment_status,
    cn.total_cents, cn.currency, cn.reason, cn.created_at
    FROM credit_notes cn
    JOIN invoices i ON i.id = cn.invoice_id
    WHERE cn.status = 'draft' AND cn.issue_pending
    ORDER BY cn.created_at;

    You see: one row for each credit note still waiting to issue, or (0 rows).

  2. Most issue by themselves within minutes, at the next billing run. One whose invoice’s charge is still running (payment_status processing or unknown) issues when the charge settles. One on a draft invoice (invoice_status draft) issues when that invoice is finalized: finalize it (Finalize on its page, or POST /v1/invoices/{id}/finalize), or void it, which voids the note at the next billing run.

    You see: step 1’s query answers (0 rows).

  3. Take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says.

The upgrade voids each note still left. Note its customer, amount and currency from step 1 first: to give that credit after the upgrade, grant it by hand (POST /v1/credits/grant), or issue a credit note on its invoice.

What else changes:

  • A cancel that finds an ended period not billed yet bills it first, as before. With plans that bill a fee in advance, that bills the fee for the period the cancel lands in. The earlier release credited its unused part; now it is kept.
  • What an API client loses: issue_pending on credit notes; the error code funding_invoice_tax_pending; the recovery warning relief_not_reissued.
  • What an operator loses: the hardcount_creditnote_pending_issue_drafts gauge, the clawback_issue reconciler, and the doctor checks cn_issue_pending_cleared_on_transition and cn_deferred_draft_stale. In a subscription’s activity, a cancel from an earlier release that gave a credit keeps the line “Prorated credit”, without its amount: the credit note holds it.

Run one version at a time for this upgrade. A copy of the previous version that keeps running fails on every credit note it reads: the migration drops issue_pending, which it reads.

Migration 00257: paused collection is removed

Section titled “Migration 00257: paused collection is removed”

The release with migration 00257_remove_pause_collection removes pausing collection on a subscription. Every invoice Hardcount makes is finalized and charged when it is made, unless its tax is still being worked out. When a payment retry policy runs out of retries, it cancels the subscription or does nothing to it. The migration does four things:

  • It takes every invoice a pause in force holds out of the queue for the automatic charge: one that is finalized and owed, on a subscription whose collection is paused with no end date or an end date still to come. The upgrade charges none of these invoices. Each one waits for you, shown as awaiting payment: “This invoice hasn’t been charged yet; use Charge now, or email the customer a payment link.” A card the customer adds later does not charge it either.
  • It changes a retry policy whose final subscription action is pause to none.
  • It deletes a webhook endpoint that listened only to subscription.collection_paused or subscription.collection_resumed, and removes those two events from every other endpoint’s event list.
  • It drops the pause from every subscription. No webhook is sent and no audit log entry is written.

Before you upgrade, on the release you run now, decide what each paused subscription should do:

  1. List them in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM), each with the invoices its pause holds and its drafts. The dashboard’s Subscriptions page shows the same subscriptions on its Collection paused tab, one account and mode at a time.

    SET app.bypass_rls = 'on';
    SELECT s.id AS subscription_id, s.tenant_id, s.livemode, s.code, s.status,
    s.next_billing_at, s.pause_collection_resumes_at, i.id AS invoice_id, i.invoice_number,
    CASE WHEN i.status = 'draft' THEN 'draft' ELSE 'held' END AS kind,
    i.tax_status, i.amount_due_cents, i.currency
    FROM subscriptions s
    LEFT JOIN invoices i ON i.subscription_id = s.id
    AND (i.status = 'draft'
    OR (i.status = 'finalized' AND i.payment_status = 'pending' AND i.auto_charge_pending))
    WHERE s.pause_collection_behavior IS NOT NULL
    AND (s.pause_collection_resumes_at IS NULL OR s.pause_collection_resumes_at > now())
    ORDER BY s.tenant_id, s.id, i.created_at;

    You see: one row for each held invoice or draft of a paused subscription, one row with no invoice for a paused subscription that has neither, or (0 rows).

  2. Cancel each subscription that must not bill again: Cancel, then Immediately, on the subscription’s page, or POST /v1/subscriptions/{id}/cancel with an API key of its account and mode. From its next period, a subscription that was paused is invoiced and charged like any other.

    You see: the subscription’s status is canceled.

  3. Run step 1’s query again: a cancel writes a final invoice, and under a pause that invoice is a draft. Void each draft whose tax_status is pending and that must not be charged: Void on the invoice’s page, or POST /v1/invoices/{id}/void. After the upgrade, such a draft is finalized and charged as soon as its tax is worked out. Any other draft stays a draft until you finalize or void it.

  4. Wait until no active subscription in step 1’s list has a next_billing_at in the past. Such a subscription has a period that ended while paused and is not billed yet. The previous version bills it as a draft at its next billing run, within about an hour of the period’s end plus the invoice grace (INVOICE_GRACE_PERIOD). Billed by the new version, that invoice is finalized and charged.

  5. Take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says.

After the upgrade, deal with each held invoice (kind held in step 1): Charge now on its page (POST /v1/invoices/{id}/collect) to charge the saved card, or void it or write it off (Mark uncollectible) if it must not be charged. A payment recorded outside Hardcount still marks it paid. A payment retry run already open on a held invoice keeps its schedule, as it did while collection was paused. While a held invoice waits, the customer’s credit is not kept for it: credit that has expired, or expires before you charge the invoice, does not pay it. To pay a held invoice from credit that was live when it was issued, use Charge now on it before you upgrade; it works while collection is paused.

What else changes:

  • A policy whose final action was pause now does nothing to the subscription when retries run out. To cancel the subscription instead, set its final subscription action to cancel on the Payment retries page’s Policy tab, or with PUT /v1/dunning/policy.
  • What an API client loses: PUT and DELETE /v1/subscriptions/{id}/pause-collection (now 404); pause_collection on a subscription and in its webhook payloads; the list filter ?collection=paused (now 422, param naming it); the subscription.collection_paused and subscription.collection_resumed events; the pause final subscription action (now 422); the invoice attention reason collection_paused (code payment.collection_paused).
  • In a subscription’s activity, a pause or a resume from an earlier release keeps its line, “Collection paused” or “Collection resumed”, without its details. A payment recovery that paused collection keeps “Collection paused” in its line.

Run one version at a time for this upgrade. A copy of the previous version that keeps running fails on every subscription it reads: the migration drops pause_collection_behavior, pause_collection_resumes_at and pause_collection_invoice_id, which it reads.

The release with migration 00258_remove_item_quantity removes a subscription item’s quantity. Each item is charged its plan’s base fee once. Items made with the dashboard’s default, the demo or the tutorials have quantity 1. The release before this one could set a higher one, in the dashboard’s Change quantity or with quantity on the API, so run step 1 whether or not you remember using it.

After the upgrade, an item stored with a quantity above 1 bills a lower base fee on its next invoice:

  • Billed in arrears: the whole period in progress bills one base fee, the days before the upgrade included.
  • Billed in advance: the period in progress keeps the fee paid for it. The next period’s fee is one base fee.

Usage, credit and issued invoices do not change. A new base-fee line reads Pro - base fee, or Pro - base fee (prorated 12/31 days), with quantity 1 and a unit amount equal to its amount. A line already issued keeps its text.

Before you upgrade, on the release you run now:

  1. List the items stored with a quantity above 1, in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM). drop_per_period_cents is what each full period’s base fee loses.

    SET app.bypass_rls = 'on';
    SELECT s.id AS subscription_id, s.tenant_id, s.livemode, s.code,
    c.id AS customer_id, c.display_name AS customer,
    p.id AS plan_id, p.name AS plan, p.base_bill_timing, p.currency,
    p.base_amount_cents, si.id AS item_id, si.quantity,
    p.base_amount_cents * (si.quantity - 1) AS drop_per_period_cents
    FROM subscription_items si
    JOIN subscriptions s ON s.id = si.subscription_id
    JOIN customers c ON c.id = s.customer_id
    JOIN plans p ON p.id = si.plan_id
    WHERE si.deleted_at IS NULL AND si.quantity > 1 AND s.status <> 'canceled'
    ORDER BY s.tenant_id, s.id;

    You see: one row for each such item, or (0 rows).

  2. List the billing intervals of each period in progress with a quantity above 1. A release before 00254 could change a quantity in the middle of a period, so an item stored at 1 can still have one. A row on a plan billed in arrears is billed at the period’s close, for its days, at one base fee. A row on a plan billed in advance was paid when its period started.

    SET app.bypass_rls = 'on';
    SELECT bi.subscription_id, s.tenant_id, s.livemode, bi.subscription_item_id,
    p.name AS plan, p.base_bill_timing, p.base_amount_cents, bi.quantity,
    bi.starts_at, bi.ends_at, s.current_billing_period_end
    FROM billing_intervals bi
    JOIN subscriptions s ON s.id = bi.subscription_id
    JOIN plans p ON p.id = bi.plan_id
    WHERE bi.quantity > 1 AND s.status <> 'canceled'
    AND bi.starts_at < s.current_billing_period_end
    AND (bi.ends_at IS NULL OR bi.ends_at > s.current_billing_period_start)
    ORDER BY s.tenant_id, bi.subscription_id, bi.starts_at;

    You see: one row for each such interval, or (0 rows).

  3. To keep charging an item’s amount, create a plan whose base fee is the multiplied amount, with the same currency, interval, base-fee timing and prices. A customer’s price overrides belong to a price, so they do not carry to the new plan’s prices: create them again on the new prices (POST /v1/price-overrides) before the item moves. Then schedule the item onto the plan: Change plan on the subscription’s page, or PATCH /v1/subscriptions/{id}/items/{itemID} with {"new_plan_id": "hc_pln_…"}. Leave the change scheduled: do not choose Immediately, and send no immediate. It then applies at the end of the current period, and the version that closes that period decides what is billed:

    • Billed in advance: that close bills the next period’s fee on the new plan. The release you run now multiplies it by the stored quantity again, so schedule the change and upgrade before the period ends.
    • Billed in arrears: that close bills the period that ended, on the old plan. The release you run now bills it at the multiplied fee, so schedule the change, let that period close, and upgrade before the next period ends.

    If the period ends too soon for that, upgrade first and schedule the change right after. An item billed in arrears then bills one base fee for the period in progress: invoice the difference once with a one-off invoice (POST /v1/invoices).

What an API client loses:

  • items[].quantity on POST /v1/subscriptions. A request that sends it is refused with 422, param naming it, whatever its value. A client that sends "quantity": 1, as the previous release’s tutorials did, breaks until it stops sending it.
  • quantity on a subscription’s items, in every answer that carries a subscription or an item and in every subscription.* webhook payload.
  • The count in a base-fee line’s description: Pro - base fee, where it was Pro - base fee (qty 1).

In a subscription’s activity, a quantity change from an earlier release keeps its line, “Quantity changed”, and a failed proration of one keeps “Proration not applied”, without the quantities.

Run one version at a time for this upgrade. A copy of the previous version that keeps running fails on every subscription it reads: the migration drops subscription_items.quantity and billing_intervals.quantity, which it reads.

Migration 00259: billing thresholds are removed

Section titled “Migration 00259: billing thresholds are removed”

The release with migration 00259_remove_billing_thresholds removes spend thresholds: the amount, or an item’s usage, at which Hardcount invoiced a period’s usage before the period ended. A period’s usage is billed once, at its close or at an immediate cancel. The migration does three things:

  • It drops every subscription’s spend thresholds, the amount and the item thresholds. No webhook is sent and no audit log entry is written.
  • It deletes a webhook endpoint that listened only to subscription.threshold_crossed, and removes that event from every other endpoint’s event list.
  • It drops the index that allowed one spend-threshold invoice per subscription and period. It changes no invoice: an invoice with billing_reason threshold keeps its lines, its amounts and its status.

A period open at the upgrade that holds a spend-threshold invoice is billed in whole at its close, or at an immediate cancel. The release you run now bills such a period’s sum and count meters only from the end of that invoice (billing_period_end). The new release reads no spend-threshold invoice: its close, or the final invoice of an immediate cancel, bills the whole period so far. So the usage that invoice billed is billed again, and so is a base fee if that invoice carries one (only one made before v0.9.0 does). After the close, hardcount-doctor reports each such period as usage_billed_once_per_customer_meter_window.

Before you upgrade, on the release you run now:

  1. List the subscriptions with a spend threshold, in the database shell (docker compose exec postgres psql -U hardcount -d hardcount on one VM). amount_gte_cents is the amount threshold, in the currency’s minor unit; item_thresholds counts the item thresholds.

    SET app.bypass_rls = 'on';
    SELECT s.id AS subscription_id, s.tenant_id, s.livemode, s.code,
    s.billing_threshold_amount_gte AS amount_gte_cents,
    (SELECT count(*) FROM subscription_item_thresholds t
    JOIN subscription_items si ON si.id = t.subscription_item_id
    WHERE t.subscription_id = s.id AND si.deleted_at IS NULL) AS item_thresholds
    FROM subscriptions s
    WHERE s.status <> 'canceled'
    AND (s.billing_threshold_amount_gte IS NOT NULL
    OR EXISTS (SELECT 1 FROM subscription_item_thresholds t
    JOIN subscription_items si ON si.id = t.subscription_item_id
    WHERE t.subscription_id = s.id AND si.deleted_at IS NULL))
    ORDER BY s.tenant_id, s.id;

    You see: one row for each such subscription, or (0 rows).

  2. List the open periods that hold a spend-threshold invoice that is not voided:

    SET app.bypass_rls = 'on';
    SELECT s.id AS subscription_id, s.tenant_id, s.livemode, s.code,
    s.current_billing_period_start, s.current_billing_period_end,
    i.id AS invoice_id, i.invoice_number, i.status,
    i.billing_period_end, i.subtotal_cents, i.currency
    FROM subscriptions s
    JOIN invoices i ON i.subscription_id = s.id
    WHERE s.status = 'active'
    AND i.billing_reason = 'threshold'
    AND i.status <> 'voided'
    AND i.billing_period_start >= s.current_billing_period_start
    AND i.billing_period_start < s.current_billing_period_end
    ORDER BY s.tenant_id, s.id, i.billing_period_end;

    You see: one row for each such invoice, or (0 rows). With (0 rows), nothing is billed twice: go to step 4.

  3. For each row of step 2, do one of:

    • Remove the thresholds and upgrade after those periods close. Remove each subscription’s thresholds: Edit, then Clear thresholds, on the Spend thresholds card of its page, or DELETE /v1/subscriptions/{id}/billing-thresholds. No new spend-threshold invoice is then made. Run step 2 again after each billing run, and upgrade once it shows (0 rows).
    • Upgrade, and give the double charge back. After the period closes, issue a credit note on the period’s own invoice for what the spend-threshold invoice billed (POST /v1/credit-notes). If the spend-threshold invoice is not paid, you can void it instead, before or after the upgrade: the period’s own invoice then bills its usage once. With this choice the thresholds stay set until the upgrade, so one can still be crossed: run step 2 again right after the upgrade (the query works on the new release too) and treat each new row the same way.
    • A subscription of a customer on a test clock needs neither: the upgrade from v0.10.0 deletes every test clock and every customer on one (migration 00241).
  4. Just before you upgrade, run step 2 again: a threshold crossed in the meantime adds a row. Then take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says.

A subscription in step 1 that has no spend-threshold invoice in its open period is billed as before: the period’s usage on the period’s own invoice. When its spend reaches the amount, no early invoice is made and no subscription.threshold_crossed is sent.

Three more things to check for the periods of step 2, and for spend-threshold invoices of periods already closed:

  • One-off invoices you made for usage flagged after_close. Before the upgrade, usage stamped before the end of a paid spend-threshold invoice was flagged after_close (a held-usage release counted it outside_open_period), and the docs said to bill it with a one-off invoice. After the upgrade the close of such a period bills that usage itself. If you made a one-off invoice for it, void it or issue a credit note, or the usage is billed twice.
  • Do not void a spend-threshold invoice of a period that closed before the upgrade unless you mean to give that usage away. That period’s own invoice billed only from the spend-threshold invoice’s end, so voiding it leaves its usage on no invoice. To bill that usage again, make a one-off invoice (late usage).
  • A spend-threshold invoice still unpaid at the upgrade uses credit as any one-off invoice does: a credit grant must be valid on the day the invoice is collected, not the day it was issued. A grant that expires in between no longer waits for that invoice, and a refund of unused credit no longer waits for it either.

What an API client loses:

  • PUT and DELETE /v1/subscriptions/{id}/billing-thresholds (now 404).
  • billing_thresholds on a subscription, in every answer that carries one and in every subscription.* webhook payload.
  • The subscription.threshold_crossed event.
  • pending_threshold_invoice in the held-usage release answer (POST /v1/usage-events/held/release).
  • The error code invoice_threshold_cycle_taken, which no longer occurs.

What else changes:

  • Usage stamped before the end of a paid spend-threshold invoice of the open period is no longer flagged after_close, and a held-usage release counts it in_open_period: the period’s close bills it.
  • In the dashboard, the Spend thresholds card is gone from a subscription’s page.
  • In a subscription’s activity, a threshold set, removed, crossed or deferred by an earlier release keeps its line. “Spend threshold crossed” names the invoice by the number its row recorded, without a link.

Run one version at a time for this upgrade. A copy of the previous version that keeps running fails on every subscription it reads: the migration drops subscriptions.billing_threshold_amount_gte, which it reads.

These steps follow Production on one VM, with Hardcount in /opt/hardcount. Database changes run by themselves as the new release starts. This example moves to v0.12.0.

  1. Do the three steps in Before you upgrade.

  2. Get the new release’s files and point .env at its images.

    Terminal window
    HARDCOUNT_VERSION=v0.12.0
    cd /opt/hardcount
    git fetch --tags
    git checkout "$HARDCOUNT_VERSION"
    cd deploy/compose
    sed -i "s|^HARDCOUNT_IMAGE=.*|HARDCOUNT_IMAGE=ghcr.io/gethardcount/hardcount:${HARDCOUNT_VERSION}|; s|^HARDCOUNT_DASHBOARD_IMAGE=.*|HARDCOUNT_DASHBOARD_IMAGE=ghcr.io/gethardcount/hardcount-dashboard:${HARDCOUNT_VERSION}|" .env

    You see: HEAD is now at … from git.

    If git instead says Your local changes to the following files would be overwritten by checkout, it did not check out the release. You edited a file the release changes, often docker-compose.yml. Copy your edits into docker-compose.override.yml (how), undo them with git -C /opt/hardcount checkout -- <each file git named>, and run this step again.

  3. Pull the new images and see what the upgrade will change.

    Terminal window
    docker compose pull
    docker compose run --rm hardcount-api migrate status

    You see: a few Container … Running lines, then the plan. It lists the migrations to apply, or says up to date, nothing to apply.

  4. Start the new images.

    Terminal window
    docker compose up -d
    docker compose exec hardcount-api /usr/local/bin/hardcount version

    You see: hardcount v0.12.0, and curl -fsS http://localhost:8080/health/ready answers "status":"ok" again.

With RUN_MIGRATIONS_ON_BOOT=true, several copies can start at once: they take turns through a Postgres lock, and each one applies only what is still missing. A waiting copy gives up after 30 minutes and is restarted. Taking turns does not protect old copies that are still running against the upgraded database. So the release notes decide the order:

  • A release whose notes say it has migrations: stop every old copy, run hardcount migrate once (or start one new copy with RUN_MIGRATIONS_ON_BOOT=true), then start the other new copies.
  • A release with no migrations: upgrade one copy at a time.

With RUN_MIGRATIONS_ON_BOOT=false, the default outside Compose, run hardcount migrate before you start a new release: Hardcount refuses to start while a migration is missing. The setup for several copies is in Run two or more copies.

A migration that fails is undone, so nothing needs repair by hand. An index build is not undone: it runs without a transaction and can leave the index INVALID. Running the upgrade again drops it and builds it again. Hardcount does not start, and the error names the cause.

On one VM, docker compose logs --tail 20 hardcount-api shows the error. Compose keeps starting the API again, and each start tries the upgrade again, so stop it while you find the cause:

Terminal window
docker compose stop hardcount-api

Then follow A database upgrade stopped. If the error says waited 5s for a table lock, something held a lock on a table the upgrade changes, often a long-running query: see It waited 5s for a table lock. When the cause is fixed, start the API again:

Terminal window
docker compose up -d hardcount-api

To go back, restore the backup you took before the upgrade. Never roll the database back with hardcount migrate rollback: it runs only with APP_ENV=local, because it loses data the newer release wrote. Without a backup, a database upgrade cannot be undone.

A restore loses everything written after the backup. The old release kept running after the backup, and the new one ran after the upgrade. The restore removes what both wrote: usage events your app sent, invoices Hardcount built and charged, payments and refunds, and changes made in the dashboard or through the API. The longer the new release runs, the more a restore loses.

On one VM:

  1. Stop the API, so nothing more is written.

    Terminal window
    cd /opt/hardcount/deploy/compose
    docker compose stop hardcount-api

    You see: a Container … Stopped line.

  2. Find the backup you took before the upgrade. Its name holds the time it started, in UTC. Use that file, not a newer nightly backup: a backup taken after the upgrade already holds the new release’s changes.

    Terminal window
    ls -l /var/backups/hardcount/

    You see: files such as hardcount_20261019_143000.dump, a backup started at 14:30:00 UTC on 19 October 2026.

  3. Empty the database and restore the backup into it. dropdb deletes the database Hardcount runs on, so check first that step 2 found the right file. Use your backup’s file name in the last line.

    Terminal window
    set -a; . ./.env; set +a
    docker compose exec -T postgres dropdb -U hardcount hardcount
    docker compose exec -T postgres createdb -U hardcount hardcount
    docker run --rm \
    --network "container:$(docker compose ps -q postgres)" \
    -v /opt/hardcount/scripts:/scripts:ro \
    -v /var/backups/hardcount:/var/backups/hardcount:ro \
    -e DATABASE_URL="postgres://hardcount:${POSTGRES_PASSWORD}@localhost:5432/hardcount?sslmode=disable" \
    -e HARDCOUNT_RESTORE_CONFIRM=yes \
    postgres:16 bash /scripts/restore.sh /var/backups/hardcount/hardcount_20261019_143000.dump

    You see: All critical tables present., a “Restore Summary” block whose Migration: line is the old release’s version, and Restore complete. The limited database user keeps its access. The backup carries its access rights, including the rights to tables that a later upgrade creates.

  4. Put back the old release, catch the database up with Stripe, and start the release. The restore marked the database as restored and paused billing and dunning, so the old release will not start until the catch-up has run.

    • Put back the old release’s files and images, and see its plan. This example goes back to v0.11.0.

      Terminal window
      HARDCOUNT_VERSION=v0.11.0
      cd /opt/hardcount
      git checkout "$HARDCOUNT_VERSION"
      cd deploy/compose
      sed -i "s|^HARDCOUNT_IMAGE=.*|HARDCOUNT_IMAGE=ghcr.io/gethardcount/hardcount:${HARDCOUNT_VERSION}|; s|^HARDCOUNT_DASHBOARD_IMAGE=.*|HARDCOUNT_DASHBOARD_IMAGE=ghcr.io/gethardcount/hardcount-dashboard:${HARDCOUNT_VERSION}|" .env
      docker compose run --rm hardcount-api migrate status

      You see: state: up to date, nothing to apply.

    • Run the checks of Check the restored database before the catch-up: they catch a wrong backup before anything writes to Stripe.

    • Run the catch-up with the old release, as in Run the catch-up, which also lists its exit codes: docker compose run --rm hardcount-api restore catch-up. You see: catch-up complete; billing and dunning are still paused.

      A release from before the catch-up answers unknown command: restore, and it does not wait for the marker. For it, remove the marker table in the database shell (docker compose exec postgres psql -U hardcount -d hardcount) with DROP TABLE restore_catchup;. Then match Hardcount with Stripe as that release’s own /opt/hardcount/docs/ops/restore.md says, from the step after its restore, instead of the rest of this page.

    • Decide on the queued emails and webhooks, and set the holds of item 3 of Start Hardcount: block the payment pages, and hold the calls that charge. Then start the release.

      Terminal window
      docker compose up -d
      docker compose exec hardcount-api /usr/local/bin/hardcount version

      You see: hardcount v0.11.0, and curl -fsS http://localhost:8080/health/ready answers "status":"ok".

  5. Put back what the restore removed, and resume billing and dunning. Follow Redo the changes made after the backup and the sections after it, to the end of that page.

With a managed Postgres, stop every copy. Restore the snapshot or the point in time you noted into the database, and mark it as restored with the old release’s hardcount restore begin. A release from before the catch-up has no such command: follow its own restore page, as step 4 says. Put the old release’s image or binary in place on every copy. Then run that release’s migrate status, which says up to date, the checks of the restored database, and its hardcount restore catch-up. Set the holds of Start Hardcount, start the old release on every copy, and do step 5. How a restore works, and what to check before you start: Restore Hardcount.

Next: Versioning: what a release may change, and where it says so.

Stuck, or found a bug? Ask in Discussions · Open an issue