Skip to Content
Your Data Is Portable

Your Data Is Portable

You can leave Foir, whenever you like, and take a working database with you.

Not a JSON dump. Not a CSV you’d have to reverse-engineer. One command gives you an ordinary Postgres database: a typed table per model, your content in real columns, references as real foreign keys — and the access rules that protected it, still protecting it.

foir export postgres --target "postgresql://localhost/myproject"

That restores the tables, the data and the foreign keys, switches your access rules on, and fetches your media into a folder beside the archive. Point your app at it, and it works. See Export to Postgres.

Why we build it this way

Every platform says you own your data. Most mean you can download it.

The difference matters the moment you actually try to leave. A dump of JSON blobs is your data in the way a pile of bricks is your house. You still have to work out the schema, rebuild the relationships, and — the part that quietly takes the longest — reimplement every access rule you were relying on, correctly, from memory, before you can safely let a single user log in.

That last part is the real lock-in, and it’s the part nobody advertises.

So we treat the exit door as a feature and keep it working. A backend you can’t leave isn’t a backend you chose; it’s one you’re stuck with. We’d rather you stayed because it’s good.

Your row-level security comes with you

This is the part that has no equivalent elsewhere.

Foir enforces who-can-see-what in the database, not in an API layer above it. Which means it’s expressible as ordinary Postgres row-level security — and so it can travel. The bundle includes a policies.sql that recreates it: a user sees a row when they own it, when it’s public, when they’ve been granted it, or when it hangs off something they can already see. The same rules, enforced by your database, with no application in front of it.

The whole contract is one session variable:

SET request.jwt.claims = '{"user_id": "<the user id>"}';

Set nothing and the caller is anonymous, and sees exactly the public rows.

If you restore onto Supabase — or anything else in front of Postgres, like PostgREST — you don’t have to do anything at all. Both already set request.jwt.claims from the bearer token, and the bundle creates the anon, authenticated and service_role roles those stacks expect. Your access model is live on the first day, on a stack you now control.

It’s worth comparing this with the usual “it’s just Postgres” promise. It is just Postgres — but “just Postgres” hands you tables and wishes you luck with the security. The rules are the hard part, and the rules are what we hand over.

What the bundle actually contains

schema.sqlA typed table per model. Real columns, real types, real constraints.
data/*.csvYour content, published channel.
constraints.sqlThe foreign keys. If they all validate, no reference was lost.
policies.sqlYour access model, as row-level security.
assets/Your media — a manifest of download links and a script that fetches them.
validate.sqlThe export checking its own work against your restored database.
README.mdHow to restore it, and what didn’t come with it.

The full walkthrough is in the Export to Postgres guide.

We tell you what didn’t come across

An export that quietly loses something is worse than one that fails, because you find out months later, when it matters.

So every export ends by checking itself, and the bundle says plainly what it couldn’t carry: a reference pointing at something already deleted, a value that wouldn’t fit its column, a field that came out empty. And it ships validate.sql, which re-checks every row count and every column checksum against the database you restored into — so “it worked” is something you verify on your own machine, not something we assure you of.

The guide has a frank list of what doesn’t transfer. The short version: your rows and your row-level security come across; the GraphQL API, per-field permissions, and API scopes are things Foir did for you and that you’d now do yourself.

A user’s own copy

A subject access request asks for one person’s data. exportMyData answers it from your app, signed in as that person, with one JSON document in the foir.my-data.v1 format. It holds their account (profile, addresses, memberships with the roles held at each, the providers they sign in with, the apps they authorised, their sessions and tokens, their notification preferences) and everything deleting the account would erase: the records they own, each with what it holds now, and their files, each with the address its bytes are at. No password, code or token value is in it.

query { exportMyData }

The same call through the data client, with the user’s token on the client:

const copy = (await foir.ns.auth.exportMyData()) as { format: 'foir.my-data.v1'; exportedAt: string; };

The console’s account page offers your team the same, as Download a copy. The Users guide has the rest of what a person can do with their own account.

The other half: deleting your data

Portability isn’t only about taking data out. It’s also about being able to destroy it — the half that regulators, and your users, actually ask about.

A user can delete their own account, from your app, with the deleteMyAccount mutation. It’s self-serve and irreversible. It re-authenticates first: an account with a password gives it, and one with none sets confirm on a sign-in made in the last ten minutes. Then it signs them out everywhere, ends every way back in, erases who they were (their name, their address, their picture) and destroys everything they own: their records, their files and the stored bytes behind them, and the access they’d been granted. Data that was shared to them is left alone; only their own access to it goes. The account’s id stays, as a deleted user with no name or address, so what they wrote for others still says who wrote it, and the address is free to sign up again.

mutation { deleteMyAccount(password: "…", confirm: true) { success } }

The same call through the data client, with the user’s token on the client rather than in the query:

const result = (await foir.ns.auth.deleteMyAccount({ password, confirm: true })) as { success: boolean; };

The two halves happen at different times, and the response only covers the first. The account is deleted before the call returns: logged out everywhere, its credentials dead, who they were erased. What they own is destroyed by a worker afterwards.

So success means “the account is deleted”, not “the bytes are gone”. recordsDeleted and filesDeleted count the user’s own records and files as the deletion was asked: those are what the worker destroys just after. An account deleted already answers success with both at 0.

In an app that holds a session, deleteMyAccountAndSignOut(adapter, env, { confirm, password }) from @foir/sdk/auth makes the same call with the session’s token and then clears the session, which the deletion ended. A refused deletion, such as a wrong password, leaves the session as it was. deleteMyAccount(env, vars, { bearerToken }) makes the call alone.

You can delete a user from your side too, from the dashboard or the API, with the same cascade.

Together with export, that’s a complete offboarding story: your users can get their data out and have it erased, and so can you. A subject access request is exportMyData, a right-to-erasure request is deleteMyAccount, and neither of them requires asking us.

See also

Last updated on