Refactor all references to computer to Superbrain
release gate / check (push) Failing after 6m55s

This commit is contained in:
Andrew S Erwin
2026-10-22 00:33:44 -05:00
parent 45aa3c80aa
commit d870eece1e
84 changed files with 438 additions and 381 deletions
+12 -8
View File
@@ -13,16 +13,20 @@
set -eu
DB_HOST="${DB_HOST:-db}"
DB_USER="${DB_USER:-computer}"
[ -n "${PGPASSWORD:-}" ] || { echo "error: PGPASSWORD is required" >&2; exit 1; }
DB_USER="${DB_USER:-superbrain}"
[ -n "${PGPASSWORD:-}" ] || {
echo "error: PGPASSWORD is required" >&2
exit 1
}
BASE_DB=computer_conv_schema
CHAIN_DB=computer_conv_chain
BASE_DB=superbrain_conv_schema
CHAIN_DB=superbrain_conv_chain
psql() { command psql -h "$DB_HOST" -U "$DB_USER" -v ON_ERROR_STOP=1 "$@"; }
drop() { psql -q -d postgres -c "DROP DATABASE IF EXISTS $1 WITH (FORCE)" >/dev/null 2>&1 || true; }
drop "$BASE_DB"; drop "$CHAIN_DB"
drop "$BASE_DB"
drop "$CHAIN_DB"
trap 'drop "$BASE_DB"; drop "$CHAIN_DB"' EXIT INT TERM
psql -q -d postgres -c "CREATE DATABASE $BASE_DB"
@@ -54,8 +58,8 @@ catalog() {
ORDER BY 1"
}
catalog "$BASE_DB" > /tmp/base.catalog
catalog "$CHAIN_DB" > /tmp/chain.catalog
catalog "$BASE_DB" >/tmp/base.catalog
catalog "$CHAIN_DB" >/tmp/chain.catalog
fail() {
echo "error: db/schema.sql and db/migrations disagree (diff above)." >&2
@@ -80,7 +84,7 @@ if [ -n "$tables" ]; then
done
psql -q -d "$CHAIN_DB" -c "DELETE FROM _migration"
DB_NAME="$CHAIN_DB" sh /db/migrate.sh >/dev/null
catalog "$CHAIN_DB" > /tmp/chain.catalog
catalog "$CHAIN_DB" >/tmp/chain.catalog
diff -u /tmp/base.catalog /tmp/chain.catalog || fail
fi
+56 -23
View File
@@ -4,63 +4,96 @@
# scratch databases it creates and drops; app data is never touched. Invoked
# by 'make db-converge' alongside the schema convergence check.
set -u
FAIL_DB=computer_conv_atomicity
PSQL="psql -h db -U computer -v ON_ERROR_STOP=1"
FAIL_DB=superbrain_conv_atomicity
PSQL="psql -h db -U superbrain -v ON_ERROR_STOP=1"
$PSQL -d postgres -qc "DROP DATABASE IF EXISTS $FAIL_DB WITH (FORCE)"
$PSQL -d postgres -qc "CREATE DATABASE $FAIL_DB"
mkdir -p /tmp/migs
echo "--- case 1: failing migration leaves no ledger row and no partial DDL"
printf 'CREATE TABLE conv_probe(id text);\nSELECT 1/0;\n' > /tmp/migs/999_probe.sql
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=computer DB_NAME=$FAIL_DB sh /db/migrate.sh
printf 'CREATE TABLE conv_probe(id text);\nSELECT 1/0;\n' >/tmp/migs/999_probe.sql
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=superbrain DB_NAME=$FAIL_DB sh /db/migrate.sh
rc=$?
echo "migrate exit=$rc"
[ "$rc" -ne 0 ] || { echo "FAIL: broken migration exited 0"; exit 1; }
[ "$rc" -ne 0 ] || {
echo "FAIL: broken migration exited 0"
exit 1
}
rows=$($PSQL -At -d $FAIL_DB -c "SELECT count(*) FROM _migration")
probe=$($PSQL -At -d $FAIL_DB -c "SELECT count(*) FROM pg_tables WHERE tablename='conv_probe'")
[ "$rows" = "0" ] || { echo "FAIL: ledger recorded a rolled-back migration ($rows)"; exit 1; }
[ "$probe" = "0" ] || { echo "FAIL: partial DDL survived the rollback"; exit 1; }
[ "$rows" = "0" ] || {
echo "FAIL: ledger recorded a rolled-back migration ($rows)"
exit 1
}
[ "$probe" = "0" ] || {
echo "FAIL: partial DDL survived the rollback"
exit 1
}
echo "case 1 OK"
echo "--- case 2: successful migration applies and records atomically"
printf 'CREATE TABLE conv_probe(id text);\n' > /tmp/migs/999_probe.sql
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=computer DB_NAME=$FAIL_DB sh /db/migrate.sh
printf 'CREATE TABLE conv_probe(id text);\n' >/tmp/migs/999_probe.sql
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=superbrain DB_NAME=$FAIL_DB sh /db/migrate.sh
rc=$?
[ "$rc" -eq 0 ] || { echo "FAIL: valid migration exited $rc"; exit 1; }
[ "$rc" -eq 0 ] || {
echo "FAIL: valid migration exited $rc"
exit 1
}
rows=$($PSQL -At -d $FAIL_DB -c "SELECT count(*) FROM _migration")
probe=$($PSQL -At -d $FAIL_DB -c "SELECT count(*) FROM pg_tables WHERE tablename='conv_probe'")
{ [ "$rows" = "1" ] && [ "$probe" = "1" ]; } || { echo "FAIL: apply/record mismatch rows=$rows probe=$probe"; exit 1; }
{ [ "$rows" = "1" ] && [ "$probe" = "1" ]; } || {
echo "FAIL: apply/record mismatch rows=$rows probe=$probe"
exit 1
}
echo "case 2 OK"
echo "--- case 3: re-run is a no-op; tampered checksum aborts before applying"
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=computer DB_NAME=$FAIL_DB sh /db/migrate.sh || { echo "FAIL: idempotent re-run failed"; exit 1; }
printf 'CREATE TABLE conv_probe2(id text);\n' > /tmp/migs/999_probe.sql
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=computer DB_NAME=$FAIL_DB sh /db/migrate.sh
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=superbrain DB_NAME=$FAIL_DB sh /db/migrate.sh || {
echo "FAIL: idempotent re-run failed"
exit 1
}
printf 'CREATE TABLE conv_probe2(id text);\n' >/tmp/migs/999_probe.sql
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=superbrain DB_NAME=$FAIL_DB sh /db/migrate.sh
rc=$?
[ "$rc" -ne 0 ] || { echo "FAIL: tampered migration did not abort"; exit 1; }
[ "$rc" -ne 0 ] || {
echo "FAIL: tampered migration did not abort"
exit 1
}
probe2=$($PSQL -At -d $FAIL_DB -c "SELECT count(*) FROM pg_tables WHERE tablename='conv_probe2'")
[ "$probe2" = "0" ] || { echo "FAIL: tampered migration applied anyway"; exit 1; }
[ "$probe2" = "0" ] || {
echo "FAIL: tampered migration applied anyway"
exit 1
}
echo "case 3 OK"
echo "--- case 4: concurrent runners — exactly one applies, the loser aborts"
printf 'CREATE TABLE conv_race(id text);\n' > /tmp/migs/999_probe.sql
RACE_DB=computer_conv_race
printf 'CREATE TABLE conv_race(id text);\n' >/tmp/migs/999_probe.sql
RACE_DB=superbrain_conv_race
$PSQL -d postgres -qc "DROP DATABASE IF EXISTS $RACE_DB WITH (FORCE)"
$PSQL -d postgres -qc "CREATE DATABASE $RACE_DB"
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=computer DB_NAME=$RACE_DB sh /db/migrate.sh >/tmp/race1.log 2>&1 &
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=superbrain DB_NAME=$RACE_DB sh /db/migrate.sh >/tmp/race1.log 2>&1 &
p1=$!
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=computer DB_NAME=$RACE_DB sh /db/migrate.sh >/tmp/race2.log 2>&1 &
MIGRATIONS=/tmp/migs DB_HOST=db DB_USER=superbrain DB_NAME=$RACE_DB sh /db/migrate.sh >/tmp/race2.log 2>&1 &
p2=$!
rc1=0; rc2=0
rc1=0
rc2=0
wait $p1 || rc1=$?
wait $p2 || rc2=$?
# The loser may abort loudly (primary-key violation after the lock handoff)
# or no-op via the ledger check; what must hold: at least one succeeds, the
# ledger has exactly one row, and the file applied exactly once.
{ [ $rc1 -eq 0 ] || [ $rc2 -eq 0 ]; } || { echo "FAIL: both runners failed"; cat /tmp/race1.log /tmp/race2.log; exit 1; }
{ [ $rc1 -eq 0 ] || [ $rc2 -eq 0 ]; } || {
echo "FAIL: both runners failed"
cat /tmp/race1.log /tmp/race2.log
exit 1
}
rows=$($PSQL -At -d $RACE_DB -c "SELECT count(*) FROM _migration")
race=$($PSQL -At -d $RACE_DB -c "SELECT count(*) FROM pg_tables WHERE tablename='conv_race'")
{ [ "$rows" = "1" ] && [ "$race" = "1" ]; } || { echo "FAIL: race left rows=$rows table=$race"; cat /tmp/race1.log /tmp/race2.log; exit 1; }
{ [ "$rows" = "1" ] && [ "$race" = "1" ]; } || {
echo "FAIL: race left rows=$rows table=$race"
cat /tmp/race1.log /tmp/race2.log
exit 1
}
echo "case 4 OK"
$PSQL -d postgres -qc "DROP DATABASE IF EXISTS $RACE_DB WITH (FORCE)"
+10 -4
View File
@@ -21,10 +21,13 @@
set -eu
DB_HOST="${DB_HOST:-db}"
DB_USER="${DB_USER:-computer}"
DB_NAME="${DB_NAME:-computer}"
DB_USER="${DB_USER:-superbrain}"
DB_NAME="${DB_NAME:-superbrain}"
MIGRATIONS="${MIGRATIONS:-/db/migrations}"
[ -n "${PGPASSWORD:-}" ] || { echo "error: PGPASSWORD is required" >&2; exit 1; }
[ -n "${PGPASSWORD:-}" ] || {
echo "error: PGPASSWORD is required" >&2
exit 1
}
psql() {
command psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -v ON_ERROR_STOP=1 "$@"
@@ -67,7 +70,10 @@ for entry in $(psql -Atc "SELECT name || ':' || checksum FROM _migration"); do
done
for f in "$MIGRATIONS"/*.sql; do
[ -e "$f" ] || { echo "error: no migrations found in $MIGRATIONS" >&2; exit 1; }
[ -e "$f" ] || {
echo "error: no migrations found in $MIGRATIONS" >&2
exit 1
}
name="$(basename "$f")"
sum="$(sha256sum "$f" | cut -d' ' -f1)"
recorded="$(psql -Atc "SELECT checksum FROM _migration WHERE name='$name'")"
+2 -2
View File
@@ -1,5 +1,5 @@
-- computer database schema
-- Derived from computer_porting_guide.md section 2 and prisma/schema.prisma.
-- superbrain database schema
-- Derived from superbrain_porting_guide.md section 2 and prisma/schema.prisma.
-- IDs are text (CUID/UUID). CASCADE / SetNull per the guide.
-- Run against an EMPTY database. Never drops or recreates a database.