Skip to content

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() or auth.uid(), and policies name authenticated. In a bare Postgres those tables fail to create, and pg_restore only warns ("errors ignored on restore") and carries on without them. prep.sql gives 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.sql gives 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.

  • BE-DP-05 is done: ../opleet-private/v1_public.dump exists.
  • The local stack is running (pnpm supabase start), so its network supabase_network_opleet exists.
  • You are at the root of your clone of the repository, on main or on this pack's branch.
  • No container is named v1copy yet: docker ps -a --filter name=v1copy lists 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”
Terminal window
docker run -d --name v1copy --network supabase_network_opleet -v "$PWD/../opleet-private":/in:ro -e POSTGRES_PASSWORD=postgres postgres:17
until docker logs v1copy 2>&1 | grep -q "init process complete"; do sleep 1; done
until docker exec v1copy pg_isready -U postgres -q; do sleep 1; done
echo ready

postgres is a throwaway value for this container only. Nothing outside Docker's local network can reach it.

Terminal window
docker exec -i v1copy psql -U postgres -d postgres -v ON_ERROR_STOP=1 < tools/migration/v1-copy/prep.sql
Terminal window
docker exec v1copy pg_restore -U postgres -d postgres --no-owner --no-privileges /in/v1_public.dump

4 · Every table in the dump is in the copy

Section titled “4 · Every table in the dump is in the copy”
Terminal window
docker exec -i -e DUMP=/in/v1_public.dump v1copy sh -s < tools/migration/v1-copy/tables.sh
Terminal window
docker exec -i v1copy psql -U postgres -d postgres -v ON_ERROR_STOP=1 < tools/migration/v1-copy/export.sql
  • Block 1: a container id, then ready within a minute.
  • Block 2: CREATE ROLE three times, CREATE SCHEMA, CREATE FUNCTION four times, CREATE SCHEMA and CREATE EXTENSION three 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 into auth or storage, which the copy doesn't have. It ends with pg_restore: warning: errors ignored on restore: N. Note N. What matters is block 4.
  • Block 4: tables in the dump, then tables in the copy with the same number, and the line missing from the copy: with nothing after it. The first number matches BE-DP-05's count.
  • Block 5: two NOTICE lines the first time, then a table with views (one more than the tables: v_rental_fee_audit is exported too) and columns_as_text: how many of v1's columns have a type of v1's own. Note it.
Terminal window
docker exec v1copy psql -U postgres -d postgres -At -c "select count(*) from information_schema.views where table_schema = 'v1_export'"
docker port v1copy

The number of tables again, then nothing: no port of your Mac reaches the copy.

  • Block 1 says the network supabase_network_opleet is not found: the stack isn't running. Run pnpm supabase start, then Undo, then block 1 again.
  • Block 1 says the name v1copy is 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 into prep.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 ERROR line; it names a table and a column, never a row.
Terminal window
docker rm -f v1copy

The 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.