TL-DP-02 · v2_reader reads v1's logins and its file list
Why: TL-DP-01 gave v2_reader v1's public tables and nothing else. Two later steps need a little more:
- The access step (data phase row 5) moves every v1 login with its id and password hash, so nobody resets a password (D50). It reads auth.users and auth.identities.
- The photo copy (row 6, D60, #218) needs to know which buckets exist, whether each is public, and which files they hold. It reads storage.buckets and storage.objects: the list, never the files.
How, after the first run (2026-10-21, #225). v1's auth schema belongs to supabase_admin, and the postgres role you use in the SQL editor may read auth.users but can't let another role into the auth schema. A direct grant gives only a warning, which the editor shows as Success. So this step makes a schema of its own, v2_export, owned by postgres. It holds two views of exactly the columns below, and v2_reader is granted that schema and nothing in auth. A view reads with its owner's rights, so v2_reader never enters auth. Storage's grants worked on the first run and are kept as they are. This writes to v1 production, so it is L0 for good and you run it by hand in v1's SQL editor (the automation ladder).
The tokens auth.users keeps for confirmation, recovery, email change and reauthentication are in no view: they are live secrets, and nothing in v2 needs them. The access step reads v2_export.auth_users and v2_export.auth_identities, never auth itself.
What this changes about v2_reader's password. Once this step runs, v2_reader can read v1's password hashes (bcrypt, not the passwords). Treat its password as you would a copy of v1's logins. It already lives only in your password manager, and later in the staging environment, which only main can use (D28, D36). Row 1's dump stays --schema=public and holds no auth data.
ID TL-DP-02 · Level L0 · Run order data phase row 8a · Issue #225
v2_reader reads these, and nothing else outside v1's public schema:
| What it reads | Columns |
|---|---|
| v2_export.auth_users, a view of auth.users | id, aud, role, email, encrypted_password, email_confirmed_at, invited_at, last_sign_in_at, raw_app_meta_data, raw_user_meta_data, created_at, updated_at, phone, phone_confirmed_at, banned_until, is_sso_user, deleted_at, is_anonymous |
| v2_export.auth_identities, a view of auth.identities | id, provider_id, user_id, identity_data, provider, last_sign_in_at, created_at, updated_at |
| storage.buckets | id, name, public, created_at |
| storage.objects | id, bucket_id, name, metadata, created_at, updated_at |
anon, authenticated and service_role can't use v2_export, and v1's API doesn't expose it.
Before
Section titled “Before”- TL-DP-01 is done: v2_reader exists, and its run is logged on #183.
- Owner access to v1's dashboard, and Docker running for the Check.
- The password manager entry "Opleet v1 · v2_reader", with the pooler host and the project ref.
- v1's exposed schemas: in the dashboard, Project Settings › Data API (or API) › Exposed schemas. Note what it lists. v2_export must never be added there.
1 · Check what postgres can do in auth
Section titled “1 · Check what postgres can do in auth”In v1's dashboard: SQL Editor › New query.
select has_schema_privilege('postgres', 'auth', 'usage') as pg_uses_auth, has_table_privilege('postgres', 'auth.users', 'select') as pg_reads_users, has_table_privilege('postgres', 'auth.identities', 'select') as pg_reads_identities, (select relrowsecurity from pg_class where oid = 'auth.users'::regclass) as users_rls, (select rolbypassrls from pg_roles where rolname = 'postgres') as pg_bypasses_rls, exists (select 1 from pg_namespace where nspname = 'v2_export') as v2_export_exists;The first three must read true and the last false. If users_rls is true, pg_bypasses_rls must be true too, or the view would hide rows. Anything else: stop and post the row on #225.
2 · Make v2_export and grant it
Section titled “2 · Make v2_export and grant it”In the same query tab, replace the text with this and select Run. The first line removes the column grants of the first run, which v2_reader can't use without the schema.
revoke select on auth.users, auth.identities from v2_reader;
create schema v2_export;revoke all on schema v2_export from public;comment on schema v2_export is 'Read-only views of v1 auth for the v2 migration (TL-DP-02). Never expose it in the API.';
create view v2_export.auth_users as select id, aud, role, email, encrypted_password, email_confirmed_at, invited_at, last_sign_in_at, raw_app_meta_data, raw_user_meta_data, created_at, updated_at, phone, phone_confirmed_at, banned_until, is_sso_user, deleted_at, is_anonymous from auth.users;
create view v2_export.auth_identities as select id, provider_id, user_id, identity_data, provider, last_sign_in_at, created_at, updated_at from auth.identities;
revoke all on v2_export.auth_users, v2_export.auth_identities from public, anon, authenticated, service_role;grant usage on schema v2_export to v2_reader;grant select on v2_export.auth_users, v2_export.auth_identities to v2_reader;
grant usage on schema storage to v2_reader;grant select (id, name, public, created_at) on storage.buckets to v2_reader;grant select (id, bucket_id, name, metadata, created_at, updated_at) on storage.objects to v2_reader;The storage lines repeat what the first run already granted; repeating them changes nothing. The editor runs the whole text as one transaction: if one line fails, none of it applies. Then delete the query from the editor's list, as in TL-DP-01's block 4.
Expect
Section titled “Expect”- Block 1:
true | true | true | <users_rls> | <pg_bypasses_rls> | false. - Block 2: "Success. No rows returned".
3 · As the owner, in a new SQL editor query
Section titled “3 · As the owner, in a new SQL editor query”select (select count(*) from auth.users) as users_in_auth, has_schema_privilege('v2_reader', 'v2_export', 'usage') as reader_uses_export, has_schema_privilege('v2_reader', 'auth', 'usage') as reader_uses_auth, has_schema_privilege('anon', 'v2_export', 'usage') as anon_uses_export, has_table_privilege('anon', 'v2_export.auth_users', 'select') as anon_reads_view, has_table_privilege('authenticated', 'v2_export.auth_users', 'select') as authenticated_reads_view;It should read <a number> | true | false | false | false | false. Note the number. Then look at the exposed schemas again: v2_export isn't listed.
4 · As v2_reader, through the session pooler
Section titled “4 · As v2_reader, through the session pooler”As in TL-DP-01's block 6. Replace the two placeholders; psql asks for the password.
docker run --rm -it postgres:17 psql "host=<V1_POOLER_HOST> port=5432 dbname=postgres user=v2_reader.<V1_PROJECT_REF> sslmode=require"At the postgres=> prompt, one line at a time. Every line prints counts or bucket names only, never a login or a file. The last two lines must fail: their errors prove that the tokens and the auth schema stay closed. Run every line, including those two, then \q.
select count(*) as logins, count(*) filter (where encrypted_password is not null) as with_password, count(*) filter (where deleted_at is not null) as deleted from v2_export.auth_users;select provider, count(*) from v2_export.auth_identities group by provider order by provider;select id as bucket, public from storage.buckets order by id;select bucket_id, count(*) as files from storage.objects group by bucket_id order by bucket_id;select confirmation_token from v2_export.auth_users limit 0;select count(*) from auth.users;\q| Line | It should print |
|---|---|
| logins | Three numbers; logins equals block 3's users_in_auth, so the view hides no row. Post them on #225: the access step's reconcile compares against them. |
| identities | One line per sign-in provider, likely only email. Post them. |
| buckets | Each bucket's name and true or false. Post them on #225 and #218: they say which way the photo copy reads the files (D68). |
| files | A count per bucket. Post them. |
| confirmation_token | ERROR: column "confirmation_token" does not exist: the tokens aren't in the view. |
| auth.users | ERROR: permission denied for schema auth: v2_reader still can't enter auth. |
If it fails
Section titled “If it fails”- Block 2 errors with "column … does not exist": v1's Auth is a version with different columns. Nothing was applied. Post the error on #225; the CTO changes the list.
- Block 2 errors with "permission denied for schema auth" or "for table users": postgres can't read auth after all. Nothing was applied. Post the error on #225.
- logins is lower than users_in_auth: RLS hides rows from the view. Post block 1's row and both numbers.
- anon or authenticated reads true in block 3, or v2_export appears in the exposed schemas: run the Undo at once, then post block 3's row on #225.
In v1's SQL editor, as the owner. It writes to v1 production, so only for this step's own objects and grants.
drop view v2_export.auth_users, v2_export.auth_identities;drop schema v2_export;revoke select on storage.buckets, storage.objects from v2_reader;revoke usage on schema storage from v2_reader;No cascade: the drops refuse if anything else came to depend on v2_export, so nothing in auth or public is touched. revoke select on a table also removes its column grants. TL-DP-01's Undo, drop owned by v2_reader, removes the grants too, but not v2_export, which postgres owns.
Log each run as a comment on #225: the date, blocks 1 to 3, and block 4's counts, buckets and errors. Never a password, a hash, an email or a file name.
2026-10-21, first run (zuki, on #225): the storage grants applied; the auth schema grant gave "no privileges were granted", because supabase_admin owns auth and postgres can't grant its usage. The step was changed to the v2_export views above.