BE-DP-06 · Restore the dump into the v1copy container, every table
ID BE-DP-06 · Level L0 · Pack Pack R1 · The v1 copy · Run order row 1, after BE-DP-05 · Issue #184
A throwaway Postgres 17 container, v1copy, holds every table of the dump, on the local stack's Docker network and on no port of your Mac. It also holds v1_export, one view per v1 table, and one for v1's view v_rental_fee_audit (the rate history the rentals step reads, #302), which BE-DP-07 reads from local v2.
Two things make this safer than restoring the dump as it is, as Part C of the database workflow guide once said:
- Every table arrives. v1's tables lean on parts of Supabase: column defaults call
extensions.uuid_generate_v4()orauth.uid(), and policies nameauthenticated. In a bare Postgres those tables fail to create, and pg_restore only warns ("errors ignored on restore") and carries on without them.prep.sqlgives the copy stand-ins for them first, and block 4 proves no table is missing. - v1's own types don't reach local v2. If v1 has enums or domains, local v2 doesn't have them, and may have different types under the same names, such as
public.driver_stage.export.sqlgives each table a view in which those columns are text.
The scripts are in tools/migration/v1-copy/. Each says what it does at its top.
Before
Section titled “Before”- BE-DP-05 is done:
../opleet-private/v1_public.dumpexists. - The local stack is running (
pnpm supabase start), so its networksupabase_network_opleetexists. - You are at the root of your clone of the repository, on main or on this pack's branch.
- No container is named
v1copyyet:docker ps -a --filter name=v1copylists none. If one is left from an earlier run, remove it first (Undo).
1 · The container, with the dump folder mounted read-only and no port published
Section titled “1 · The container, with the dump folder mounted read-only and no port published”docker run -d --name v1copy --network supabase_network_opleet -v "$PWD/../opleet-private":/in:ro -e POSTGRES_PASSWORD=postgres postgres:17until docker logs v1copy 2>&1 | grep -q "init process complete"; do sleep 1; doneuntil docker exec v1copy pg_isready -U postgres -q; do sleep 1; doneecho readypostgres is a throwaway value for this container only. Nothing outside Docker's local network can reach it.
2 · What a Supabase dump expects
Section titled “2 · What a Supabase dump expects”docker exec -i v1copy psql -U postgres -d postgres -v ON_ERROR_STOP=1 < tools/migration/v1-copy/prep.sql3 · The restore
Section titled “3 · The restore”docker exec v1copy pg_restore -U postgres -d postgres --no-owner --no-privileges /in/v1_public.dump4 · Every table in the dump is in the copy
Section titled “4 · Every table in the dump is in the copy”docker exec -i -e DUMP=/in/v1_public.dump v1copy sh -s < tools/migration/v1-copy/tables.sh5 · The views local v2 will read
Section titled “5 · The views local v2 will read”docker exec -i v1copy psql -U postgres -d postgres -v ON_ERROR_STOP=1 < tools/migration/v1-copy/export.sqlExpect
Section titled “Expect”- Block 1: a container id, then
readywithin a minute. - Block 2:
CREATE ROLEthree times,CREATE SCHEMA,CREATE FUNCTIONfour times,CREATE SCHEMAandCREATE EXTENSIONthree times. - Block 3: a minute or two, then
pg_restore: error: could not execute query: ERROR: schema "public" already exists, which is harmless: a fresh database already has it. There may be a few more lines about functions, triggers, policies or foreign keys intoauthorstorage, which the copy doesn't have. It ends withpg_restore: warning: errors ignored on restore: N. Note N. What matters is block 4. - Block 4:
tables in the dump, thentables in the copywith the same number, and the linemissing from the copy:with nothing after it. The first number matches BE-DP-05's count. - Block 5: two
NOTICElines the first time, then a table withviews(one more than the tables:v_rental_fee_auditis exported too) andcolumns_as_text: how many of v1's columns have a type of v1's own. Note it.
docker exec v1copy psql -U postgres -d postgres -At -c "select count(*) from information_schema.views where table_schema = 'v1_export'"docker port v1copyThe number of tables again, then nothing: no port of your Mac reaches the copy.
If it fails
Section titled “If it fails”- Block 1 says the network
supabase_network_opleetis not found: the stack isn't running. Runpnpm supabase start, then Undo, then block 1 again. - Block 1 says the name
v1copyis already in use: a copy from an earlier run is there. Undo, then block 1 again. - Block 4 names a table after
missing from the copy:: that table failed to create. Find its line in block 3's output (relation "public.<name>" does not exist, or an error just before it naming a type or a function) and post that line and the table name on #184. The fix goes intoprep.sql. Don't go on to BE-DP-07 with a table missing. - Block 3 prints
COPY failed for table: post only the table's name and the first words of the error, up to the first quote. The rest can quote a row (D15). - Block 5 fails: post its
ERRORline; it names a table and a column, never a row.
docker rm -f v1copyThe container and everything restored into it go; the dump stays in ../opleet-private. Run blocks 1 to 5 again for a fresh copy.
Log each run as a comment on #184: the date, block 3's N, block 4's three lines and block 5's two numbers.