User data a buyer will accept
Acquisition-ready user-data schema (consent + metrics + export)
For when the answer to “I might sell this business one day” is yes.
Structures user data so it is a SELLABLE asset, not a liability: the retention/conversion metrics a buyer's due diligence asks for, AND the consent-to-transfer + deletion layer that makes the data legally sellable at all.
Skip the rebuild
You do not write this one. It arrives in your project as ordinary source you can read, change and keep, with its audit record and its caveats beside it.
- Download the Playground. It is free and runs on your own machine.
- Start a new app and tick “I might sell this business one day”.
- This block is written in, along with anything else you ticked.
The mistake it removes
The half that's usually missing is the expensive one: without a record that each user consented to their data transferring on acquisition, the user base can't legally be included in a sale, and dirty, non-deletable data gets a deal discounted or killed. This block ships that half. It also ships the Supabase Row Level Security most schemas forget, without it, the auto-generated API lets any logged-in user read everyone's data.
What is already handled
Some are checked by running the block’s own tests every time its checks run and some only by reading the shipped source. Each item’s label says which. An item tested only in part says so in its label. Tested means the block’s own test suite runs that code. It does not mean a live run against an outside service such as a payment provider.
- all 5 SQL files parse against the real PostgreSQL grammar (pglast / libpg_query) Read in the source, not run
- sql/rls.supabase.sql is READ on every run and must still say it: every per-user table gets FORCE ROW LEVEL SECURITY and owner-only policies (auth.uid() = user_id), one per command and never FOR ALL, applied via guarded loops that skip tables an app doesn't have. A user's own content (user_profiles, projects, deployments, manuscripts, publications) can be read, added, edited and removed by its owner. The users row can be read, inserted and updated but not deleted, because a raw DELETE cascades the consent trail away and erasure is anonymize_user's job. Not every column is open: the server-owned columns (users.current_tier, is_active, deleted_at, created_at and password_hash, and deployments.monthly_bandwidth_bytes) are left out of the INSERT and UPDATE grants authenticated holds, so a signed-in user cannot set their own plan tier or zero their own usage bill. TRUNCATE, which RLS does not govern, is revoked from anon and authenticated on every per-user table, so a signed-in user with a direct database connection cannot empty one for everybody. The evidence tables (consent_records and daily_usage_summaries) and the revenue tables (subscriptions and subscription_mrr_history) are read-only to their owner, with no write policy and the write grants revoked, so only the service role writes them and a signed-in user cannot back-date a consent, inflate their own usage or forge their own MRR (test/rls-policy.test.mjs). The two tables with no user in them, acquisition_spend and products (the COGS that acq_margin reads), get RLS forced with NO policy and every grant revoked from anon and authenticated, so only the service role reads or writes them and a client cannot read the COGS or rewrite it to move the margin. That is a property of the SQL TEXT this block ships. Outside that test's initdb leg nothing here applies it to a database, so whether your Postgres enforces it depends on your running the migration. Tested in part
- sql/core.sql is READ on every run and must still declare anonymize_user SECURITY DEFINER with a LOCKED search_path (public, pg_temp), so a deletion works under RLS without opening the search_path privilege-escalation hole. Again a property of the shipped SQL text, and not of a database this repository ran it against. Read in the source, not run
- 81 node assertions (counted here: test/data-asset-kit.test.mjs, +30 with initdb) on the runtime helpers, the function grants, the columns and apply order this file describes and, with initdb, two cases of the retention views: a subscription hard-deleted from subscriptions stays in the acq_nrr and acq_logo_churn base and counts as churn, and a history row for a subscription that never existed is refused, all passing Tested
- anonymize_user, record_mrr_change and acq_required_spend_categories are REVOKED from PUBLIC, anon and authenticated right after each CREATE, and only service_role is granted anonymize_user and acq_required_spend_categories. Read from the SQL text on every run. The same read refuses a written GRANT that hands one of those functions back to PUBLIC, anon or authenticated, whether it sits at the top level of a file, inside a function or DO body quoted with dollar signs or with single quotes, or in a string passed straight to EXECUTE: ON FUNCTION or ON ROUTINE with or without an argument list, ON ALL FUNCTIONS or ALL ROUTINES IN SCHEMA public, a grantee spelled TO GROUP, a trailing GRANTED BY, and a role membership that makes one of them a member of service_role, postgres, supabase_admin or any role this SQL grants a guarded function to. A string used as a value (after IS, a RAISE level, SELECT, RETURN, THEN, ELSE, an opening bracket, a comma or an operator) is text, so a GRANT written inside one is not refused. Any other single-quoted string is treated as text too, and any other dollar-quoted string is read as SQL to be safe. A GRANT assembled at run time with format(), || or a variable is not read. With initdb on PATH the files are also applied to a throwaway PostgreSQL where anon and a signed-in user calling anonymize_user get permission denied and service_role still erases. Tested in part
- recordConsent validates the consent type, the boolean, and policy_version, and every decision is a NEW row: a withdrawal or a re-grant never overwrites the earlier decision's time and IP, and consent_records refuses an UPDATE from any role (the append and the refusal are executed against a throwaway PostgreSQL when initdb is on PATH) Tested in part
- hasTransferConsent returns true ONLY for the user's most-recent GRANTED data_transfer_on_acquisition. Withdrawn and never-given both correctly exclude the user from a sale. It and transferableCounts read ONE definition of most-recent, the latest_transfer_consent view in sql/core.sql, so the count and the gate cannot disagree; on a recorded_at tie the withdrawal wins (executed against a throwaway PostgreSQL when initdb is on PATH) Tested
- exportUserData bundles the user row + every per-user table, skips a value table the app doesn't have without crashing and names it in `skipped`, and is timestamped. Only a missing table (PostgreSQL code 42P01) is skipped: any other error on a table, such as a timeout, a lost connection or a permission denial, makes the export throw rather than hand back a bundle with that table silently absent. The user row is read by named columns (user_id, email, current_tier, created_at, updated_at, is_active, deleted_at), so password_hash never reaches a portability bundle or a data room: asserted against a store double on every run, and against the real schema when initdb is on PATH. Tested
- deleteUser exports the user's data FIRST, then calls anonymize_user rather than deleting the rows, and if that export throws it refuses: it rejects and anonymize_user is never called, so the user is left as they were. All three asserted by name in test/data-asset-kit.test.mjs against a store double. That the anonymized aggregates then SURVIVE for cohort metrics is a property of anonymize_user inside sql/core.sql, and nothing here applies that SQL to a database: deleteUser is only as good as anonymize_user, which is a gap and not a pass. Tested in part
- a malicious perUserTables entry ("users; DROP TABLE users --") is rejected by an identifier guard, never interpolated into a query Tested
What the audit found
Named rather than summarized. The reasoning behind each one ships inside the block, so it travels with the code instead of living on a page you have to trust. A finding marked fixed was fixed after the audit ran; the verdict above is still the one the audit gave.
- Any caller, including the unauthenticated anon role, can erase any user by calling anonymize_user() over PostgREST critical · Security Fixed after the audit in
1de91b243 - The owner-only policy is FOR ALL, so a signed-in user writes their own revenue rows and the MRR the buyer reads is forgeable major · Security Fixed after the audit in
177c1b911 - products is on no RLS list at all: any signed-in or anonymous caller can read COGS and rewrite unit_cost_cents, moving acq_margin to 100% major · Security Fixed after the audit in
33b24012b - The SQL-injection guard test is decorative: deleting quoteIdent's identifier check leaves the suite green major · Verification integrity Fixed after the audit in
ce3d50231 - exportUserData ships the raw users row, password_hash included, into the portability bundle and the data room major · Privacy & data Fixed after the audit in
45b0b8b24 - deleteUser anonymises irreversibly after an export whose failures were silently swallowed, outside any transaction major · Data durability Fixed after the audit in
120ae6c85 - acq_nrr's comment says a hard-deleted subscription still counts as churn; the history table cascades on that delete so the row leaves the base instead minor · Claims match behavior Fixed after the audit in
43bbd6443 - block.json describes a display-name column the schema does not have and carries a garbled apply-order note minor · Claims match behavior Fixed after the audit in
42387c5a6 - transferableCounts re-derives 'most recent decision' with different arithmetic from hasTransferConsent, so ties on recorded_at can make the two disagree minor · Correctness Fixed after the audit in
d1e1493db - log_date defaults to the server's local calendar date while every other timestamp is UTC-aware minor · Correctness Fixed after the audit in
40f4a4c12
What you still have to do
A copied file cannot own your secrets, your host or your legal obligations. This is the part the block deliberately does not claim.
- On raw Postgres you must enforce per-user access in your own server code: rls.supabase.sql uses auth.uid() and only applies to Supabase. Keep the analytics views behind the service role: they read across all users and must never be granted to the client.
- List YOUR value tables in perUserTables and stamp every consent with policy_version. Export and erasure walk the tables you name; a table you forget is silently absent from both.
- The database URL or Supabase service-role key must come from your host's secret store. This block takes an injected query() and never reads an environment variable itself, so credential custody is entirely yours.
- Your database's own backup and point-in-time-recovery settings. The block structures the data and ships the export path; keeping the bytes is the host's job, and anonymize_user is not reversible.
- Publish the privacy and terms documents the recorded consents point at, and have a lawyer confirm they actually grant transfer on acquisition in your jurisdiction. The block records that the user agreed to a version; it cannot tell you the version said what you needed it to say.
- NOT LEGAL ADVICE. This encodes the mechanics due diligence checks (consent records, transfer consent, erasure, export): a real sale still needs a lawyer to confirm your terms actually grant transfer and your jurisdiction's rules (GDPR/CCPA/etc.) are met.
- The SQL parses, and the function grants and the latest_transfer_consent view were run against a throwaway local PostgreSQL (when initdb is on PATH). Nothing else in it was, apart from two retention cases (a hard-deleted subscription counting as churn in acq_nrr and acq_logo_churn, and a history row for a subscription that never existed being refused): the RLS policies and the rest of the views' numbers were not exercised. Apply it to a scratch database once before production; cross-file order matters (core.sql before any value-tables file).
- Collecting behavioral telemetry to prove value to a buyer is only clean if users consented to analytics: record that consent (the block's `analytics` type) or you're building the liability you're trying to avoid.
- anonymize_user rewrites the email to a placeholder and keeps aggregate rows; if your jurisdiction requires hard deletion of a specific field, extend it.
- exportUserData copies every table in perUserTables whole, every column included. Only the users row is trimmed to a named column list. Keep tokens, API keys and session ids out of any table you add to perUserTables, or they will ship in the user's export and in the data room.
- With Supabase Auth, leave password_hash NULL and reference auth.users: do not run a second credential store. RLS depends on this: `auth.uid() = user_id` only means 'my row' if user_id IS the auth id.
- Export and erasure are not one transaction: query() is the pool.query shape, so a row the user writes between the export and anonymize_user is anonymised without being in the bundle. A Supabase adapter must pass the PostgreSQL error code through, or a missing table reads as a failed export and deleteUser refuses.
What lands in your project
sql
- sql/core.sql
- sql/acquisition.sql
- sql/value_tables.vibecoder.sql
- sql/value_tables.authorge.sql
- sql/rls.supabase.sql
Postgres/Supabase migrations, applied IN ORDER: (1) core.sql: the users, consent_records, user_profiles and daily_usage_summaries tables, the anonymize_user deletion function, the latest_transfer_consent view (each user's newest transfer decision) and the cohort_retention view. (1b) acquisition.sql: the revenue layer the Acquisition Standard reads, which is the subscriptions, subscription_mrr_history, products and acquisition_spend tables plus the acq_* views (MRR, NRR, logo churn, margin, CAC, concentration). (2) ONE value-tables file for your domain: value_tables.vibecoder.sql (projects, deployments) or value_tables.authorge.sql (manuscripts, publications). (3) rls.supabase.sql LAST, and only on Supabase: it turns on Row Level Security so the auto-generated API cannot leak every user's data. On raw Postgres there is no auth.uid(), so skip step 3 and enforce ownership in your own server code.
node
- node/data-asset.js
createDataAsset({ query }) returns { recordConsent, hasTransferConsent, transferableCounts, exportUserData, deleteUser }. DB-agnostic: pass a query(text, params) fn (pg pool.query shape).
What you supply
- query: a (text, params) => Promise<{ rows }>: node-postgres pool.query, or a thin Supabase adapter
- policy_version: stamp every consent with the version of the terms/privacy doc the user saw
- perUserTables: override if your value tables differ from the vibecoder/authorge defaults, so export + deletion cover them
Licensed MIT. It is a starting point, not a finished product.
Get it
Download the Playground See the other blocks
Nothing here is locked. The files are yours, in your folder, under a permissive license.
Questions
- Is User data a buyer will accept audited?
- It was audited on 2026-09-29, and the verdict was not a clean pass. 10 findings have been fixed since then, and the verdict stands until the block is audited again.
- What do I still have to do myself?
- On raw Postgres you must enforce per-user access in your own server code: rls.supabase.sql uses auth.uid() and only applies to Supabase. Keep the analytics views behind the service role: they read across all users and must never be granted to the client.
- How do I get this code?
- Download the Playground, start a new app, and tick “I might sell this business one day”. The block is written into your project as ordinary source you can read and edit.
All pre-built code blocks · Learn to build from zero · The coding guide