Drizzle setup + drizzle-kit pull schema.ts from basketball db #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Lineage
Hard depends on
forgejo_admin/westside-admin#6(scaffolding — repo must havepackage.json,src/lib/server/directory). Hard depends onforgejo_admin/pal-e-platform#302(admin_app Postgres user — needed for the integration AC and CI drift check).Repo
forgejo_admin/westside-adminUser Story
story-westside-admin-admin-row-crud. Implements the schema introspection safety constraint — schema is generated from live DB, not hand-typed.Context
Drizzle ORM provides type-safe SQL via a TypeScript schema file. Rather than hand-write the schema for 22 tables × ~10 columns, we use
drizzle-kit pullto introspect the live basketball Postgres and generatesrc/lib/server/schema.ts. This file is the source of truth for what tables/columns exist and is checked into git.The basketball DB has 22 tables and 18 enums (verified). Sensitive columns (oauth_tokens.token_data, password_reset_tokens.token, parents.registration_token, players.contract_token) need to remain in the schema (so updates work) but get hidden via a separate visible-columns config in a later ticket. See
arch-domain-westside-adminfor the full table inventory.DB credentials come from
DATABASE_URLenv var. v1 connects as theadmin_appPostgres user (created inforgejo_admin/pal-e-platform#302).File Targets
Create:
drizzle.config.ts—drizzle-kitconfig: dialect=postgresql, schema=src/lib/server/schema.ts, dbCredentials from envsrc/lib/server/db.ts— exportsdbfromdrizzle(pg.Pool)usingDATABASE_URL. Marked@internal; consumed only by query helper (#3)src/lib/server/schema.ts— generated bydrizzle-kit pull. CHECKED INTO GIT.package.json— adddrizzle-orm,drizzle-kit,pg,@types/pg, npm scriptdb:pullscripts/check-schema-drift.sh— local-runnable script that runsdb:pullagainstDATABASE_URLand compares to committedschema.ts, exits non-zero on diffDo NOT create:
forgejo_admin/westside-admin#8(.woodpecker.yaml). This ticket only provides the script.Acceptance Criteria
npm run db:pullconnects to basketball db and regeneratesschema.tspgEnum()declarationsschema.tsis committed to gitscripts/check-schema-drift.shruns locally withDATABASE_URLset and exits 0 if schema matches, non-zero on diffdb.tslazy-initializes pool on first import; closes cleanly on SIGTERMTest Expectations
playershas at least 30 columns (sanity check against introspection)db.select().from(schema.tenants).limit(1)returns at least 1 row when DATABASE_URL is set to the admin_app credentialsConstraints
pgdriver (notpostgres-js) to match the connection pool pattern westside-app usesunknown— manually narrowoauth_tokens.token_data,players.contract_overrides,teams.contract_config,contract_audit_log.old_state/new_statein a typed extension file (or document and defer)Checklist
npm run db:pullreproducibleRelated
project-westside-adminarch-domain-westside-adminarch-dataflow-westside-admin#6(scaffolding),forgejo_admin/pal-e-platform#302(admin_app Postgres user)Scope Review: NEEDS_REFINEMENT
Review note:
review-1089-2026-04-25Scope is solid for a greenfield Drizzle setup; three fixable issues before backlog -> todo:
[BODY]"Depends on scaffolding ticket" is vague — replace with "Blocked by westside-admin#6 (scaffolding) and pal-e-platform#302 (admin_app DB user)".[BODY]CI drift AC depends on Woodpecker wiring (westside-admin#8, also backlog). Either narrow AC to "script exists, runnable locally" or add explicit #8 dependency.[SCOPE]arch:scopeddb-helperlabel has no backing arch note. Project page lists arch-domain/dataflow/deployment only. Either createarch-scopeddb-helperor re-label (arch-domain-westside-admin is closest). Same label is on issue #3, decide jointly.No decomposition needed (4 files, 6 ACs, ~5–10 min agent work).
Scope Re-review (v2): NEEDS_REFINEMENT
Review note:
review-1089-2026-04-25-v2All [BODY] recommendations from
review-1089-2026-04-25are resolved (explicit#6+pal-e-platform#302lineage; CI drift AC narrowed to local scriptscripts/check-schema-drift.sh; Woodpecker wiring deferred to#8). Ticket body is dispatch-ready.One remaining issue blocks backlog → todo:
[SCOPE]arch:scoped-dblabel has no backing note. Search forarch-scoped-dbreturns 404;project-westside-adminArchitecture section lists onlyarch-domain-westside-admin,arch-dataflow-westside-admin,arch-deployment-westside-admin. Two paths:arch-scoped-dbnote (~5 min docs task) and add to project page Architecture list. Pairs naturally with #3 (scoped-db helper).arch:domain-westside-admin(closest existing fit since schema.ts is the domain-schema artifact).Once Ava picks a path, advance backlog → todo. No decomposition required.
Scope Review v3: READY
Review note:
review-1089-2026-04-25-v3v2 [SCOPE] blocker resolved. New arch note
arch-scoped-db-westside-adminexists in pal-e-docs with a components table that explicitly mapsarch:scoped-dbto real components (scopedDb, systemDb), plus a Mermaid diagram and key decisions. Note cross-references this ticket in its Implementation Tickets section.All traceability legs verified:
arch-scoped-db-westside-adminNo action needed. Advance backlog → todo.
build/index.htmldoesn't exist for adapter-node #12