Skip to content

BE-DP-29 · A night on the v1 copy with the access step, and one sign-in with a v1 password

ID BE-DP-29 · Level L0 · Pack Row 5 · The domain steps · Run order row 5, after the access step's pull request and BE-DP-25's rows are merged · Issue #278

v1's 64 logins are read live through v2_reader (TL-DP-02) and moved into your local stack with their ids and password hashes (D50, R-ACC-58), every one but the photo reader (R-ACC-73). Each becomes a member of the organization with its v1 role at every pool, its grants, denies and partners (R-ACC-71, R-ACC-75, R-ACC-76), and no session is ended (R-ACC-74). The reconcile then lists no unexplained row, and you sign in to the local stack with your own v1 password.

  • The access step's pull request (BE-DP-28) and the pull request with BE-DP-25's rows are merged, and you are on main after git pull, with pnpm supabase db reset run since.
  • The rows for v1's role names and partners are in the migration. If they aren't, block 3 lists them: post that table on #278, finish the run with block 6, and stop.
  • docker ps --filter name=v1copy lists the copy as Up, and BE-DP-07 has run since the reset, so v1_live exists.
  • The password manager entry "Opleet v1 · v2_reader", and your own v1 email and password for block 5.

1 · A run, its snapshot, and the organization

Section titled “1 · A run, its snapshot, and the organization”
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select migration.begin_run('BE-DP-29, local, on the v1 copy, with access') as run;
select migration.snapshot() as tables_copied;
select migration.run('master_data') as master_rows;
SQL

2 · v1's logins, through v2_reader, into the night

Section titled “2 · v1's logins, through v2_reader, into the night”

One password prompt: paste <V1_READONLY_PASSWORD>. The two files hold emails and password hashes: they stay in ../opleet-private and are never posted (D15).

Terminal window
docker run --rm -it -v "$PWD/tools/migration/v1-copy:/sql:ro" -v "$PWD/../opleet-private":/out postgres:17 psql "host=<V1_POOLER_HOST> port=5432 dbname=postgres user=v2_reader.<V1_PROJECT_REF> sslmode=require" -v ON_ERROR_STOP=1 -f /sql/logins-export.sql
chmod 600 ../opleet-private/v1-logins.csv ../opleet-private/v1-identities.csv
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 -c "truncate migration.v1_auth_users, migration.v1_auth_identities"
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 -c "\copy migration.v1_auth_users from pstdin with (format csv, header)" < ../opleet-private/v1-logins.csv
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 -c "\copy migration.v1_auth_identities from pstdin with (format csv, header)" < ../opleet-private/v1-identities.csv
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select (select count(*) from migration.v1_auth_users) as logins_loaded, (select count(*) from migration.v1_auth_identities) as identities_loaded;
select field, v1_value, rows from migration.unmapped_values() where domain = 'access' order by 1, 2;
SQL

If logins_loaded is 0, stop here: block 2 loaded nothing, so an empty list below proves nothing. Run block 2 again and check its two COPY lines.

If the second query lists any line, stop here: post it on #278 and go to block 6. It prints role names, permission names and partner names, never a person's. Otherwise:

Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select migration.run('access') as access_rows;
select table_name, (new_data ->> 'rows')::int as rows from public.audit_log
where action = 'migrated' and record_id = (select max(id) from migration.runs)::text and new_data ->> 'step' = 'access'
order by id;
select reason, count(*) as logins from migration.unmatched
where run_id = (select max(id) from migration.runs) and step = 'access' group by 1 order by 2 desc;
select count(*) filter (where access_changed_at is not null) as stamped, count(*) as profiles from public.profiles;
SQL

4 · The reconcile, counted, with its lines on your Mac only

Section titled “4 · The reconcile, counted, with its lines on your Mac only”
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 -c "select check_name, count(*) as lines from migration.reconcile() group by 1 order by 1"
mkdir -p ../opleet-private
docker exec supabase_db_opleet psql -qX -U postgres -d postgres -c "select * from migration.reconcile() where check_name like 'access%'" > ../opleet-private/reconcile-be-dp-29.txt

Run this block in a real terminal window, not in a tool that has no terminal: the script reads your answers from the terminal itself. The first line reads the local stack's URL and publishable key into this shell only. The script then asks for your v1 email and password; the password is not shown, and neither reaches your shell history.

Terminal window
set -a; eval "$(pnpm supabase status -o env | grep -E '^(API_URL|ANON_KEY|PUBLISHABLE_KEY)=')"; set +a
python3 - <<'PY'
import getpass, json, os, sys, urllib.request
key = os.environ.get("PUBLISHABLE_KEY") or os.environ["ANON_KEY"]
sys.stdout.write("v1 email: "); sys.stdout.flush()
email = open("/dev/tty").readline().strip() # stdin is this script, so input() would read EOF
body = json.dumps({"email": email, "password": getpass.getpass("v1 password: ")}).encode()
req = urllib.request.Request(os.environ["API_URL"] + "/auth/v1/token?grant_type=password", body,
{"apikey": key, "Content-Type": "application/json"})
try:
print("signed in" if "access_token" in json.load(urllib.request.urlopen(req)) else "no token")
except urllib.error.HTTPError as e:
print("refused:", json.load(e).get("error_code", e.code))
PY

6 · The end of the run, and the logins out of the night

Section titled “6 · The end of the run, and the logins out of the night”
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select migration.finish_run('succeeded');
SQL

finish_run empties migration.v1_auth_users and v1_auth_identities itself, whatever the status (R-MIG-09), so no hash stays behind after a stopped night.

If you stopped at block 3, run select migration.finish_run('failed'); instead of the first line.

  • Block 1: tables_copied 35 or so, and master_rows above zero.
  • Block 2: one line, logins | identities | photo_reader: 64 or so, the same number of identities, and 1. Then TRUNCATE TABLE and two COPY lines with the same counts.
  • Block 3: logins_loaded and identities_loaded as block 2's COPY lines, and no unmapped line; then access_rows, and six lines: auth.users and auth.identities 63 or so (64 less the photo reader and any unmatched login), memberships the same, member_roles that times the number of pools, and the overrides and rental-company rows. Unmatched: most likely none. stamped is 0.
  • Block 4: access logins, access hashes and access menus absent. access modules absent too: each page in a login's v1 allowed_modules opens in v2, through its role or a grant the step makes (R-ACC-81). A line there is a page v1 also denied the login; post its count and path on #278. Lines from other checks belong to their steps.
  • Block 5: signed in.
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -c "select count(*) as logins_held from migration.v1_auth_users"

It reads 0: v1's emails and hashes are out of the night's tables.

  • Block 5 EOFError: the block ran without a terminal; open a terminal window.
  • Block 5 KeyError: ANON_KEY or API_URL: the status variables were not exported, so the python3 child could not read them. Use the set -a line.
  • Block 1 tables_copied is 0: v1_live is missing, because BE-DP-07 hasn't run since the last pnpm supabase db reset. Run select migration.finish_run('failed');, then BE-DP-07, then block 1 again.
  • Block 1 migration.target is empty: the pull request with BE-DP-25's rows hasn't merged, so the night has no organization to load into. Run select migration.finish_run('failed'); and stop. Run this step again once BE-DP-25 is posted on #280 and its rows are on main.
  • Block 2 permission denied for schema v2_export: TL-DP-02 was undone on v1. Post the line on #225.
  • Block 2 COPY errors on a column: v1's Auth changed its columns. Post the line on #278; it names a column.
  • Block 3 no v1 logins are loaded tonight: migration.v1_auth_users is empty. Block 2's \copy didn't run, loaded 0 rows, or ran before a pnpm supabase db reset or block 6. Check wc -l ../opleet-private/v1-logins.csv (65 or so, with the header), then run block 2's last three commands again and block 3 from its start. The run stays open, so block 1 needn't run again.
  • Block 3 migration.unmapped_values: a value has no row; the first query of block 3 lists it. Post that table on #278.
  • Block 3 column "…" of relation "users" does not exist: the local Auth's columns differ from what the step writes. Post the line on #278.
  • Block 3 stamped above 0, or block 4 lists access logins, access hashes or access menus: post the counts on #278, and the lines' check names and detail column from ../opleet-private/reconcile-be-dp-29.txt (ids and permission codes only).
  • Block 5 refused: invalid_credentials: first sign in to v1 with the same password to rule out a typo. If v1 accepts it, post refused: invalid_credentials on #278.

pnpm supabase db reset removes everything the night loaded, and BE-DP-07 makes v1_live again. rm ../opleet-private/v1-logins.csv ../opleet-private/v1-identities.csv removes the export; keep it while the data phase still needs it, like the dump. Nothing here touches staging or production; v1 is only read.

Log each run as a comment on #278: date · who · result, with blocks 2 to 5's counts and lines. Never an email, a name or a hash.