Skip to content

feat(backend): off-chain PostgreSQL schema, migrations, and DB module#99

Open
priscaenoch wants to merge 1 commit into
Web3Novalabs:mainfrom
priscaenoch:feature/75-db-schema-migrations
Open

feat(backend): off-chain PostgreSQL schema, migrations, and DB module#99
priscaenoch wants to merge 1 commit into
Web3Novalabs:mainfrom
priscaenoch:feature/75-db-schema-migrations

Conversation

@priscaenoch

Copy link
Copy Markdown

closes #75

this PR implemented the following changes:

  • Add pg@^8.11.3 dependency and @types/pg@^8.11.6 dev dependency
  • backend/src/db/schema.sql: canonical reference schema for all four tables
  • backend/src/db/migrations/001_create_tables_up.sql: creates users, groups, members, transactions with UUIDs, FK ON DELETE CASCADE, UNIQUE constraints, CHECK (percentage > 0 AND percentage <= 100), and all documented indexes
  • backend/src/db/migrations/001_create_tables_down.sql: drops tables in reverse dependency order
  • backend/src/db/migrate.ts: CLI runner (node dist/db/migrate.js [down]); reads SQL files relative to the compiled dist directory, exposed via pnpm db:migrate / pnpm db:migrate:down scripts
  • backend/src/db/index.ts: exports a shared pg.Pool and a generic query() helper for use by future service modules
  • backend/src/db/tests/migrations.test.ts: migration smoke tests (up then assert tables/indexes then down then assert clean) plus constraint tests (duplicate wallet_address, duplicate tx_hash, out-of-range percentage, FK violation); all tests skip gracefully when DATABASE_URL is not set
  • backend/.env.example: remove duplicate HORIZON_URL entry, add Docker quick-start comment for DATABASE_URL

- Add pg@^8.11.3 dependency and @types/pg@^8.11.6 dev dependency
- backend/src/db/schema.sql: canonical reference schema for all four tables
- backend/src/db/migrations/001_create_tables_up.sql: creates users, groups,
  members, transactions with UUIDs, FK ON DELETE CASCADE, UNIQUE constraints,
  CHECK (percentage > 0 AND percentage <= 100), and all documented indexes
- backend/src/db/migrations/001_create_tables_down.sql: drops tables in
  reverse dependency order
- backend/src/db/migrate.ts: CLI runner (node dist/db/migrate.js [down]);
  reads SQL files relative to the compiled dist directory, exposed via
  pnpm db:migrate / pnpm db:migrate:down scripts
- backend/src/db/index.ts: exports a shared pg.Pool and a generic query()
  helper for use by future service modules
- backend/src/db/__tests__/migrations.test.ts: migration smoke tests (up then
  assert tables/indexes then down then assert clean) plus constraint tests
  (duplicate wallet_address, duplicate tx_hash, out-of-range percentage,
  FK violation); all tests skip gracefully when DATABASE_URL is not set
- backend/.env.example: remove duplicate HORIZON_URL entry, add Docker
  quick-start comment for DATABASE_URL
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.

feat(backend): off-chain database schema + migrations (users, groups, members, transactions)

1 participant