Skip to content

Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.

fix(v0.8.2): db-setup survives the Supabase transaction pooler

Ashiq Hussain Mirbbcc15cb6d4b
diff --git a/package.json b/package.json
index 1d778b6..586c098 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "canvix",
- "version": "0.8.1",
+ "version": "0.8.2",
"private": false,
"description": "Canvix \u2014 free & open-source graphic design tool. A community-built Canva alternative.",
"scripts": {
diff --git a/scripts/db-setup.sh b/scripts/db-setup.sh
index 8307267..dd0c12b 100755
--- a/scripts/db-setup.sh
+++ b/scripts/db-setup.sh
@@ -5,7 +5,10 @@
# npm run db:setup
#
# What it does, in order:
-# 1. prisma migrate deploy
+# 1. prisma generate — make sure the client exists no matter how
+# dependencies were installed (some package managers skip
+# postinstall scripts, which would otherwise break the seed).
+# 2. prisma migrate deploy — via a migration-safe URL:
# - fresh database → creates all tables/indexes
# - already-migrated database → no-op ("No pending migrations")
# - db-push-prepared database (pre-v0.8 setups, e.g. a Neon DB you
@@ -13,7 +16,13 @@
# baseline the initial migration (mark it applied) and re-run,
# which is Prisma's documented path for adopting migrations on
# an existing schema.
-# 2. seed the built-in template library (idempotent upserts — safe to
+# Supabase note: Migrate needs session-level advisory locks, which
+# the TRANSACTION pooler (port 6543) does not support — through it
+# the command hangs until timeout. When DATABASE_URL points there,
+# migrations are transparently run through the SESSION pooler on
+# the same host (port 5432, same credentials, IPv4-friendly). The
+# app and the seed work fine through either port.
+# 3. seed the built-in template library (idempotent upserts — safe to
# re-run any time, it also refreshes templates after upgrades).
set -u
cd "$(dirname "$0")/.."
@@ -27,20 +36,50 @@ echo "── Canvix database setup ───────────────
# a confusing P1001 against localhost).
if [ -z "${DATABASE_URL:-}" ]; then
echo " ERROR: DATABASE_URL is not set."
- echo " - locally: export DATABASE_URL='postgresql://…'"
- echo " - GitHub Actions: add the DATABASE_URL repository secret"
+ echo " - locally: export DATABASE_URL='postgresql://…'"
+ echo " - GitHub Actions: add the DATABASE_URL repository secret"
echo " (Settings → Secrets and variables → Actions), then re-run"
echo " the Canvix Database Setup workflow."
- echo " Supabase note: either URL works — the pooler (port 6543) or the"
- echo " direct connection (port 5432); sslmode/pgbouncer flags are"
- echo " applied automatically by src/lib/db-url.ts."
exit 1
fi
-echo " DATABASE_URL host: $(node -e "try{const u=new URL(process.env.DATABASE_URL||'');console.log(u.hostname)}catch{console.log('(unset)')}")"
+urlhost() { node -e "try{const u=new URL(process.env.DATABASE_URL||'');console.log(u.hostname+(u.port?':'+u.port:''))}catch{console.log('(unset)')}"; }
+echo " DATABASE_URL: $(urlhost)"
-echo " [1/2] applying migrations…"
-if npx prisma migrate deploy; then
+# ── migration-safe URL ────────────────────────────────────
+# Rewrite Supabase transaction pooler (port 6543 / pgbouncer=true) to the
+# session pooler (port 5432) and pin sslmode for remote hosts. The seed
+# and the app keep using the original URL (seed.ts normalises it itself).
+MIGRATE_URL="$(node -e '
+const url = process.env.DATABASE_URL || ""
+try {
+ const u = new URL(url)
+ const pooler = u.hostname.endsWith(".pooler.supabase.com")
+ const tx = u.port === "6543" || u.searchParams.get("pgbouncer") === "true"
+ if (pooler && tx) {
+ u.port = "5432"
+ u.searchParams.delete("pgbouncer")
+ u.searchParams.delete("connection_limit")
+ }
+ const local = ["localhost","127.0.0.1","::1","[::1]"].includes(u.hostname)
+ if (!local && !u.searchParams.has("sslmode") && !u.searchParams.has("ssl")) {
+ u.searchParams.set("sslmode", "require")
+ }
+ process.stdout.write(u.toString())
+} catch { process.stdout.write(url) }
+')"
+
+if [ "$MIGRATE_URL" != "$DATABASE_URL" ]; then
+ echo " migrations: routed via the session pooler (port 5432) — Prisma"
+ echo " Migrate cannot run through the transaction pooler (6543); the"
+ echo " credentials are identical. App + seed keep your original URL."
+fi
+
+echo " [1/3] generating the Prisma client…"
+npx prisma generate || exit 1
+
+echo " [2/3] applying migrations…"
+if DATABASE_URL="$MIGRATE_URL" npx prisma migrate deploy; then
echo " migrations: ok"
else
RC=$?
@@ -48,8 +87,8 @@ else
# P3005 (schema not empty, no migration history) comes back as exit 5
# from migrate deploy; older CLIs used 1. Try the baseline recovery.
echo " existing schema without migration history detected — baselining…"
- if npx prisma migrate resolve --applied "$MIGRATION"; then
- npx prisma migrate deploy && echo " migrations: ok (baselined)" || exit 1
+ if DATABASE_URL="$MIGRATE_URL" npx prisma migrate resolve --applied "$MIGRATION"; then
+ DATABASE_URL="$MIGRATE_URL" npx prisma migrate deploy && echo " migrations: ok (baselined)" || exit 1
else
echo " migrate deploy failed and baselining did not apply."
echo " If this is a fresh database, check DATABASE_URL / credentials."
@@ -63,7 +102,7 @@ else
fi
fi
-echo " [2/2] seeding the template library…"
+echo " [3/3] seeding the template library…"
npx tsx prisma/seed.ts || exit 1
echo "── done. Your database is ready: 110 templates, all free. ──"