Skip to content

fix(db): move clan_members table definition before data migrations (closes #82) - #113

Open
trexfr-ops wants to merge 2 commits into
Bitcoindefi:mainfrom
trexfr-ops:fix/issue-82-clan-members-schema-order
Open

fix(db): move clan_members table definition before data migrations (closes #82)#113
trexfr-ops wants to merge 2 commits into
Bitcoindefi:mainfrom
trexfr-ops:fix/issue-82-clan-members-schema-order

Conversation

@trexfr-ops

Copy link
Copy Markdown

Description

Closes #82

This PR fixes the table creation ordering in api/schema.sql so that clan_members, characters.clan_id, and clan_requests are defined before the data migration CTEs that reference them.

Key Changes

  1. Added \set ON_ERROR_STOP on at the beginning of api/schema.sql to ensure execution halts if any statement fails.
  2. Relocated clan_members table creation, ALTER TABLE characters ADD COLUMN IF NOT EXISTS clan_id, clan_requests, and their associated indexes directly after the clans table definition.
  3. Placed the alignment migration updates and incompatible clan member purge queries after all referenced tables and columns exist.

/claim #82

  • EVM (Base/ETH): 0x32BB3df5B74a594956a0f33Bc353511Fa759FCa4
  • LTC: LPnftYop8yhRNQZstysT3vuJf3XkpQWKTC
  • Solana (SOL): 8Xo39uq9LoaM2rQEkgaaSfuThqHZTd18yGdJSXffkLwM
  • BTC: bc1qpyu6866qcgt26sqw4dn2mlmp8d0yc657fuedkv
  • DOGE: DDMU6D9TCE3BhqqYyy7MUZQD7JhfL39FpE

Comment thread api/schema.sql Outdated
@trexfr-ops

Copy link
Copy Markdown
Author

Resolved the review finding in commit 83c03aa:

  • Removed \set ON_ERROR_STOP on from api/schema.sql so node-postgres parses cleanly.
  • Wrapped schema execution in an explicit database transaction (BEGIN/COMMIT/ROLLBACK) inside api/src/migrate.ts to ensure atomic abort-on-error behavior across both pg driver and psql execution paths.

@gitar-bot

gitar-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Reorders schema definitions and wraps database migration scripts in an atomic transaction to prevent missing table errors. The psql meta-command issue was successfully resolved.

✅ 1 resolved
Bug: psql meta-command \set breaks migrate.ts execution path

📄 api/schema.sql:1
\set ON_ERROR_STOP on is a psql client meta-command, not a SQL statement. schema.sql is applied two ways: via the Postgres docker init entrypoint (psql, where \set works) and via api/src/migrate.ts, which reads the file and runs pool.query(schemaSql) through node-postgres (pg). The pg driver sends the text straight to the server over the simple-query protocol, so \set ON_ERROR_STOP on produces syntax error at or near "" and the entire migration aborts before any table is created. This makes the migrate.ts path unusable. Remove the \set line from schema.sql and instead enforce abort-on-error at the caller (e.g. wrap the schema in a transaction, or run via psql with -v ON_ERROR_STOP=1), or strip/handle the meta-command in migrate.ts before executing.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schema.sql aplica tres migraciones sobre clan_members antes de crear la tabla

1 participant