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.
Before you upgrade
Section titled “Before you upgrade”- 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.
- Take a backup. On one VM, run
sudo hardcount-backup(set it up) and wait forVerified: yes. With a managed Postgres, take a snapshot, or note the time if it has point-in-time restore. - See the plan. Run
hardcount migrate statuswith 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 saysno 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).
Coming from a release before v0.11.0
Section titled “Coming from a release before v0.11.0”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.
Coming from Velox
Section titled “Coming from Velox”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_.
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.
Upgrade to v0.12.0
Section titled “Upgrade to v0.12.0”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_ to
00263_, 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 /with severalv1/ subscriptions 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_, with each item’sitems 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:
-
List the subscriptions with more than one item, in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton one VM).code_is each subscription’s code after the upgrade: the row withafter place1 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.codeWHEN EXISTS (SELECT 1 FROM subscriptions oWHERE o.tenant_id = x.tenant_id AND o.livemode = x.livemodeAND o.code = x.code || '-' || x.place)THEN x.code || '-' || x.item_idELSE x.code || '-' || x.place END AS code_afterFROM (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 itemsFROM subscriptions sJOIN subscription_items i ON i.subscription_id = s.id AND i.deleted_at IS NULL) xWHERE x.items > 1ORDER 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 withplace2 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 withGET /. From its next invoice on, each item’s part is billed on its new subscription.v1/ subscriptions?search=<code_ after> -
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_andfrom unbilled_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.to 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_toFROM subscriptions sJOIN billing_intervals bi ON bi.subscription_id = s.idJOIN subscription_items i ON i.id = bi.subscription_item_idJOIN LATERAL (SELECT k.id FROM subscription_items kWHERE k.subscription_id = s.id AND k.deleted_at IS NULLORDER BY k.created_at, k.idLIMIT 1) kept ON trueWHERE s.status = 'active'AND i.deleted_at IS NOT NULLAND bi.starts_at < s.current_billing_period_endAND (bi.ends_at IS NULL OR bi.ends_at > s.current_billing_period_start)AND EXISTS (SELECT 1FROM billing_intervals oJOIN subscription_items oi ON oi.id = o.subscription_item_idWHERE o.subscription_id = s.idAND oi.id <> i.idAND tstzrange(o.starts_at, COALESCE(o.ends_at, 'infinity'))&& tstzrange(bi.starts_at, COALESCE(bi.ends_at, 'infinity'))AND (oi.id = kept.idOR (oi.deleted_at IS NOT NULLAND (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. -
After the period of each listed subscription closes, bill each row of step 2 once on a one-off invoice (
POST /), as Invoice timing and late usage bills usage that missed an invoice. Bill only the days fromv1/ invoices unbilled_tofrom 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_tofrom unbilled_, over the period’s days;to - usage only for a meter that the row’s plan prices and the plan the
subscription keeps (its
plan_idafter the upgrade) does not. Count only the events fromunbilled_tofrom unbilled_:to total_fromunits GET /, with the labels of the price’sv1/ usage-events/ aggregate?customer_ id=<customer_ id>&meter_ id=<meter>&from=<unbilled_ from>&to=<unbilled_ to> dimension_, priced at the price’s rate.match
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_: it can lie in periods already invoiced.at - the base fee of the row’s plan, if it bills in arrears, prorated as
Hardcount does: the fee times the whole days from
-
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.
-
Stop every copy of v0.11.0 before the new release migrates: v0.11.0 reads
subscription_, which the migration drops (Upgrade two or more copies).items
What an API client loses, and gets:
- Create:
POST /takesv1/ subscriptions plan_id. A body withitemsis refused with422,paramitems, as any unknown field is. - A subscription carries
plan_id,pending_andplan_ id pending_, and noplan_ effective_ at items, in every answer and in everysubscription.webhook payload. A webhook stored or queued before the upgrade keeps the payload it was built with.* - Plan changes:
POST /withv1/ subscriptions/ {id}/ schedule-plan-change {"plan_schedules one for the end of the period, andid": "hc_ pln_ …"} DELETE /cancels it. Both answer the subscription.v1/ subscriptions/ {id}/ scheduled-plan-change PATCH /andv1/ subscriptions/ {id}/ items/ {itemID} DELETE /answerv1/ subscriptions/ {id}/ items/ {itemID}/ pending-change 404. - Webhook events:
subscription.,pending_ change. scheduled subscription.andpending_ change. applied subscription.keep their names and losepending_ change. canceled item_id. A subscription sends oneappliedevent when its change takes effect. - The error code
item_no longer occurs.changed - The subscriptions export names the plan in a
plan_idcolumn, where it hadplan_.ids
What else changes for a customer whose subscription was split:
- Previews:
POST /withv1/ invoices/ create_ preview customer_alone previews one of the subscriptions. Passid subscription_to preview each.id - 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_ and billing_.
Upgrade to v0.11.0
Section titled “Upgrade to v0.11.0”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:
-
List them in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton 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_atFROM payment_methods pmJOIN customers c ON c.tenant_id = pm.tenant_id AND c.id = pm.customer_idWHERE pm.type = 'card' AND COALESCE(pm.card_last4, '') = '' AND pm.detached_at IS NULLORDER BY pm.tenant_id, pm.customer_id;You see: one row for each such payment method, or
(0 rows). -
Send each customer a setup link for a card: Add payment method on the customer’s page, or
POST /with an API key of its account and mode.v1/ customers/ {id}/ payment-methods/ send-setup-email You see: once the customer saves a card, it is listed as the default.
-
Then remove the blank one: the trash button beside it on the customer’s page, or
DELETE /. Remove it only after the card is saved, so the customer always has a method to charge.v1/ customers/ {id}/ payment-methods/ {pm_ id} You see: the method is gone from the customer’s list.
Migration 00225: finish charges first
Section titled “Migration 00225: finish charges first”The release with migration 00225_ 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.
-
With the previous version still running, count them in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton one VM):SET app.bypass_rls = 'on';SELECT count(*) FROM invoicesWHERE status IN ('finalized', 'uncollectible')AND (auto_charge_claimed_until IS NOT NULLOR (payment_status = 'unknown' AND COALESCE(stripe_payment_intent_id, '') = ''));You see: a
countcolumn with one number. -
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.
-
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_ in place of
count(*)), and read the previous version’s
hardcount_ 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_: 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.ask failed: a database error, which the log line names.
A parked invoice (payment_ unknown, no stripe_)
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_ 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 invoicesSET payment_status = 'pending', auto_charge_claimed_until = NULL, charge_attempt_seq = charge_attempt_seq + 1WHERE 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_ 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.webhook is sent for these subscriptions, and no audit log entry is written.canceled - It deletes a webhook endpoint that listened only to
subscription., the event an activation sent.activated - It removes
subscription.from every other endpoint’s event list.activated
Before you upgrade, on the release you run now, activate the drafts that should bill:
-
List them in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton 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). -
Activate each one that should bill: Activate on the subscription’s page, or
POST /with an API key of its account and mode.v1/ subscriptions/ {id}/ activate You see: the subscription’s status is
active. -
Let the server run for one minute after the last activation, so that its
subscription.webhook goes out. Then take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says.activated
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_ 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.webhook is sent for these subscriptions, and no audit log entry is written.canceled - It deletes a webhook endpoint that listened only to
subscription.ortrial_ ended 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:
-
List them in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton 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). -
End the trial of each one that should bill: End trial now on the subscription’s page, or
POST /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.v1/ subscriptions/ {id}/ end-trial You see: the subscription’s status is
active. -
Let the server run for one minute after the last one, so that its
subscription.webhook goes out. Then take the backup (step 2 of Before you upgrade) and upgrade as the rest of this page says.trial_ ended
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 withtrial_in the past, or end those trials yourself.end_ at - 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_, trial_ and activated_, 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_ 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_ topup). Refunding
it then goes through commit relief (a commit_ block on
POST /), 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 /with a negativev1/ credits/ adjust 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-doctorlists 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_centsFROM invoices iWHERE 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_ removes the cancel on a
chosen date (cancel_). 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:
-
List them in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton one VM).SET app.bypass_rls = 'on';SELECT id, tenant_id, livemode, code, cancel_at, current_billing_period_endFROM subscriptionsWHERE status = 'active' AND cancel_at IS NOT NULLAND cancel_at IS DISTINCT FROM current_billing_period_endORDER BY cancel_at;You see: one row for each such subscription, with its cancel date (
cancel_) and the end of its current period, orat (0 rows). -
Cancel now each one whose cancel date has come: Cancel, then Immediately, on the subscription’s page, or
POST /with an API key of its account and mode. This bills the part of the period used.v1/ subscriptions/ {id}/ cancel You see: the subscription’s status is
canceled. -
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_, 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_ and
00254_ 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 /(nowv1/ subscriptions/ {id}/ items 404) andDELETE /(nowv1/ subscriptions/ {id}/ items/ {itemID} 405: the path still takesPATCH). - Request fields:
quantityandimmediateonPATCH /, which are refused withv1/ subscriptions/ {id}/ items/ {itemID} 422,paramnaming the field. The route takesnew_only, and always schedules the change for the end of the current period.plan_ id - Response fields:
prorationandnew_on that route’s answer, which is nowperiod_ invoice itemandeffective_.at - Webhook events:
subscription.,item. added subscription.anditem. removed subscription.. A scheduled plan change still sendsitem. updated subscription.,pending_ change. scheduled subscription.andpending_ change. applied subscription..pending_ change. canceled - Invoice fields:
source_,plan_ changed_ at source_andsubscription_ item_ id source_. An invoice that an earlier release made for a change keeps itschange_ type billing_reason subscription_, its period, its lines and its amounts.update - Error codes that no longer occur:
unpaid_,invoice_ blocks_ change subscription_,period_ moved swap_,requires_ atomic_ path invoice_andproration_ source_ taken proration_.unavailable
The migrations do four things:
-
00253builds the index that allows one invoice per subscription and period again, and keeps an invoice made for a change out of it by itsbilling_. It builds the index without blocking writes.reason 00254gives it the old index’s name. -
00254drops the log of item changes (subscription_), the trigger that wrote it and the trigger’s function, and the three invoice columns with their index and foreign key.item_ changes -
00254deletes a webhook endpoint that listened only to the three removed events, and removes those events from every other endpoint’s event list. -
00254cancels 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.codeFROM subscriptions sWHERE s.status = 'active'AND NOT EXISTS (SELECT 1 FROM subscription_items iWHERE 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 /withv1/ subscriptions/ {id}/ items/ {itemID} {"new_. The current period is billed on the old plan.plan_ id": "hc_ pln_ …"} - Cancel now and create a new subscription: Cancel, then
Immediately, or
POST /. The cancel bills the usage so far and keeps a fee billed in advance. Then create a subscription on the other plan.v1/ subscriptions/ {id}/ cancel
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_ 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:
-
List them in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton 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_atFROM credit_notes cnJOIN invoices i ON i.id = cn.invoice_idWHERE cn.status = 'draft' AND cn.issue_pendingORDER BY cn.created_at;You see: one row for each credit note still waiting to issue, or
(0 rows). -
Most issue by themselves within minutes, at the next billing run. One whose invoice’s charge is still running (
payment_status processingorunknown) 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, orPOST /), or void it, which voids the note at the next billing run.v1/ invoices/ {id}/ finalize You see: step 1’s query answers
(0 rows). -
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 /), 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_on credit notes; the error codepending funding_; the recovery warninginvoice_ tax_ pending relief_.not_ reissued - What an operator loses: the
hardcount_gauge, thecreditnote_ pending_ issue_ drafts clawback_reconciler, and the doctor checksissue cn_andissue_ pending_ cleared_ on_ transition cn_. 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.deferred_ draft_ stale
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_, which it reads.
Migration 00257: paused collection is removed
Section titled “Migration 00257: paused collection is removed”The release with migration 00257_ 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
pausetonone. - It deletes a webhook endpoint that listened only to
subscription.orcollection_ paused subscription., and removes those two events from every other endpoint’s event list.collection_ resumed - 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:
-
List them in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton 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.currencyFROM subscriptions sLEFT JOIN invoices i ON i.subscription_id = s.idAND (i.status = 'draft'OR (i.status = 'finalized' AND i.payment_status = 'pending' AND i.auto_charge_pending))WHERE s.pause_collection_behavior IS NOT NULLAND (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). -
Cancel each subscription that must not bill again: Cancel, then Immediately, on the subscription’s page, or
POST /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.v1/ subscriptions/ {id}/ cancel You see: the subscription’s status is
canceled. -
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_isstatus pendingand that must not be charged: Void on the invoice’s page, orPOST /. 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.v1/ invoices/ {id}/ void -
Wait until no active subscription in step 1’s list has a
next_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 (billing_ at INVOICE_). Billed by the new version, that invoice is finalized and charged.GRACE_ PERIOD -
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 /) 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
pausenow does nothing to the subscription when retries run out. To cancel the subscription instead, set its final subscription action tocancelon the Payment retries page’s Policy tab, or withPUT /.v1/ dunning/ policy - What an API client loses:
PUTandDELETE /(nowv1/ subscriptions/ {id}/ pause-collection 404);pause_on a subscription and in its webhook payloads; the list filtercollection ?collection=paused(now422,paramnaming it); thesubscription.andcollection_ paused subscription.events; thecollection_ resumed pausefinal subscription action (now422); the invoice attention reasoncollection_(codepaused 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_, pause_ and
pause_, which it reads.
Migration 00258: items have no quantity
Section titled “Migration 00258: items have no quantity”The release with migration 00258_ 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/, 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:
-
List the items stored with a quantity above 1, in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton one VM).drop_is what each full period’s base fee loses.per_ period_ cents 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_centsFROM subscription_items siJOIN subscriptions s ON s.id = si.subscription_idJOIN customers c ON c.id = s.customer_idJOIN plans p ON p.id = si.plan_idWHERE 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). -
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_endFROM billing_intervals biJOIN subscriptions s ON s.id = bi.subscription_idJOIN plans p ON p.id = bi.plan_idWHERE bi.quantity > 1 AND s.status <> 'canceled'AND bi.starts_at < s.current_billing_period_endAND (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). -
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 /) before the item moves. Then schedule the item onto the plan: Change plan on the subscription’s page, orv1/ price-overrides PATCH /withv1/ subscriptions/ {id}/ items/ {itemID} {"new_. Leave the change scheduled: do not choose Immediately, and send noplan_ id": "hc_ pln_ …"} 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[].onquantity POST /. A request that sends it is refused withv1/ subscriptions 422,paramnaming it, whatever its value. A client that sends"quantity": 1, as the previous release’s tutorials did, breaks until it stops sending it.quantityon a subscription’s items, in every answer that carries a subscription or an item and in everysubscription.webhook payload.* - The count in a base-fee line’s description:
Pro - base fee, where it wasPro - 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_ and billing_, which it
reads.
Migration 00259: billing thresholds are removed
Section titled “Migration 00259: billing thresholds are removed”The release with migration 00259_ 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., and removes that event from every other endpoint’s event list.threshold_ crossed - It drops the index that allowed one spend-threshold invoice per
subscription and period. It changes no invoice: an invoice with
billing_reason thresholdkeeps 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_). 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_.
Before you upgrade, on the release you run now:
-
List the subscriptions with a spend threshold, in the database shell (
docker compose exec postgres psql -U hardcount -d hardcounton one VM).amount_is the amount threshold, in the currency’s minor unit;gte_ cents item_counts the item thresholds.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 tJOIN subscription_items si ON si.id = t.subscription_item_idWHERE t.subscription_id = s.id AND si.deleted_at IS NULL) AS item_thresholdsFROM subscriptions sWHERE s.status <> 'canceled'AND (s.billing_threshold_amount_gte IS NOT NULLOR EXISTS (SELECT 1 FROM subscription_item_thresholds tJOIN subscription_items si ON si.id = t.subscription_item_idWHERE 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). -
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.currencyFROM subscriptions sJOIN invoices i ON i.subscription_id = s.idWHERE s.status = 'active'AND i.billing_reason = 'threshold'AND i.status <> 'voided'AND i.billing_period_start >= s.current_billing_period_startAND i.billing_period_start < s.current_billing_period_endORDER 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. -
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 /. No new spend-threshold invoice is then made. Run step 2 again after each billing run, and upgrade once it showsv1/ subscriptions/ {id}/ billing-thresholds (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 /). 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.v1/ credit-notes - 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).
- 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
-
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. 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_. Before the upgrade, usage stamped before the end of a paid spend-threshold invoice was flaggedclose after_(a held-usage release counted itclose outside_), 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.open_ period - 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:
PUTandDELETE /(nowv1/ subscriptions/ {id}/ billing-thresholds 404).billing_on a subscription, in every answer that carries one and in everythresholds subscription.webhook payload.* - The
subscription.event.threshold_ crossed pending_in the held-usage release answer (threshold_ invoice POST /).v1/ usage-events/ held/ release - The error code
invoice_, which no longer occurs.threshold_ cycle_ taken
What else changes:
- Usage stamped before the end of a paid spend-threshold invoice of the
open period is no longer flagged
after_, and a held-usage release counts itclose in_: the period’s close bills it.open_ period - 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., which it reads.
Upgrade on one VM
Section titled “Upgrade on one VM”These steps follow Production on one VM, with
Hardcount in /. Database changes run by themselves as the new
release starts. This example moves to v0.12.0.
-
Do the three steps in Before you upgrade.
-
Get the new release’s files and point
.envat its images.Terminal window HARDCOUNT_VERSION=v0.12.0cd /opt/hardcountgit fetch --tagsgit checkout "$HARDCOUNT_VERSION"cd deploy/composesed -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}|" .envYou 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, oftendocker-compose.. Copy your edits intoyml docker-compose.(how), undo them withoverride. yml git -C /, and run this step again.opt/ hardcount checkout -- <each file git named> -
Pull the new images and see what the upgrade will change.
Terminal window docker compose pulldocker compose run --rm hardcount-api migrate statusYou see: a few
Container … Runninglines, then the plan. It lists the migrations to apply, or saysup to date, nothing to apply. -
Start the new images.
Terminal window docker compose up -ddocker compose exec hardcount-api /usr/local/bin/hardcount versionYou see:
hardcount v0., and12. 0 curl -fsS http://answerslocalhost:8080/ health/ ready "status":"ok"again.
Upgrade two or more copies
Section titled “Upgrade two or more copies”With RUN_, 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 migrateonce (or start one new copy withRUN_), then start the other new copies.MIGRATIONS_ ON_ BOOT=true - A release with no migrations: upgrade one copy at a time.
With RUN_, 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.
If the upgrade stops
Section titled “If the upgrade stops”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:
docker compose stop hardcount-apiThen 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:
docker compose up -d hardcount-apiGoing back
Section titled “Going back”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_, 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:
-
Stop the API, so nothing more is written.
Terminal window cd /opt/hardcount/deploy/composedocker compose stop hardcount-apiYou see: a
Container … Stoppedline. -
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_, a backup started at 14:30:00 UTC on 19 October 2026.20261019_ 143000. dump -
Empty the database and restore the backup into it.
dropdbdeletes 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 +adocker compose exec -T postgres dropdb -U hardcount hardcountdocker compose exec -T postgres createdb -U hardcount hardcountdocker 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.dumpYou see:
All critical tables present., a “Restore Summary” block whoseMigration:line is the old release’s version, andRestore complete.The limited database user keeps its access. The backup carries its access rights, including the rights to tables that a later upgrade creates. -
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.0cd /opt/hardcountgit checkout "$HARDCOUNT_VERSION"cd deploy/composesed -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}|" .envdocker compose run --rm hardcount-api migrate statusYou 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) withDROP TABLE restore_. Then match Hardcount with Stripe as that release’s owncatchup; /says, from the step after its restore, instead of the rest of this page.opt/ hardcount/ docs/ ops/ restore. md -
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 -ddocker compose exec hardcount-api /usr/local/bin/hardcount versionYou see:
hardcount v0., and11. 0 curl -fsS http://answerslocalhost:8080/ health/ ready "status":"ok".
-
-
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