Skip to content

Migrate local dev tooling to PostgreSQL and generate all required wallet keys#3838

Merged
TaprootFreak merged 3 commits into
developfrom
feat/local-setup-postgres
Jun 8, 2026
Merged

Migrate local dev tooling to PostgreSQL and generate all required wallet keys#3838
TaprootFreak merged 3 commits into
developfrom
feat/local-setup-postgres

Conversation

@TaprootFreak

@TaprootFreak TaprootFreak commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

The API was migrated to PostgreSQL (#3620), but the local-development tooling still targeted MSSQL, so a fresh npm run setup could not produce a working local environment (the pg-based API could not connect to the MSSQL container, and the API crashed on boot because some wallet keys were never generated). This PR aligns the local tooling with the PostgreSQL stack and makes the setup script generate every wallet key the API parses on startup.

Changes

Local DB tooling → PostgreSQL

  • docker-compose.yml: run postgres:16 instead of mssql/server:2022. Postgres creates the database from POSTGRES_DB, so the separate db-init service is removed; the healthcheck uses pg_isready.
  • .env.local.example: SQL_PORT 1433 → 5432, and SQL_ENCRYPTSQL_SSL=false.
  • scripts/setup.js: use pg instead of mssql. The readiness check, admin-role update and deposit seeding are rewritten as PostgreSQL queries (quoted identifiers, information_schema, parameterized statements). SSL defaults off for this local-only script (opt in via SQL_SSL=true).
  • migration/seed/seed.js: use pg instead of mssql. Quote camelCase identifiers, insert real boolean literals, advance the identity sequence after explicit-id inserts, and port the index drop / ip_log / fiat-fix statements to PostgreSQL.

Complete wallet-key generation

npm run setup now generates every key the blockchain/integration services parse on startup, in the correct format:

  • Mnemonic seeds: ICP_WALLET_SEED, PAYMENT_ICP_SEED, BOLTZ_SEED, SPARK_WALLET_SEED
  • EVM key + address: CITREA_WALLET_PRIVATE_KEY, CITREA_WALLET_ADDRESS
  • Ark identity key (raw hex): ARK_PRIVATE_KEY
  • KuCoin Pay signing key (PKCS#8, base64 DER): DFX_KUCOINPAY_PRIVATE_KEY
  • Payment-webhook signing key (PKCS#8 PEM): PAYMENT_WEBHOOK_PRIVATE_KEY

Previously the API crashed on boot because ICP_WALLET_SEED and CITREA_WALLET_PRIVATE_KEY were missing.

CI

  • .github/workflows/api-migration-check.yaml: scope the migration-immutability check to schema migrations only. The seed script and its data under migration/seed/ are actively maintained, not immutable migrations.

Docs & cleanup

  • README.md: update the Docker commands, environment notes and mock-mode section to PostgreSQL.
  • Removed the orphaned scripts/setup.sh bash wrapper: it duplicated the canonical npm run setup flow, was not referenced anywhere, and relied on the MSSQL-only scripts/testdata.js / scripts/kyc/kyc-testdata.js seeders (out of this PR's scope). npm run setup is the documented local-setup entrypoint.

Acceptance

A fresh cp .env.local.example .env && docker compose up -d && npm run setup now:

  • boots cleanly with no manual .env edits,
  • seeds the full dataset on PostgreSQL (7 languages, 24 fiats, 250 countries, 227 assets, 62 price rules, 27 fees, 6 banks, ip_log, wallet) plus 5 deposit addresses,
  • serves http://localhost:3000/swagger (HTTP 200),
  • returns data from the seed-backed RealUnit endpoints (/v1/realunit/price, /v1/realunit/price/history) instead of 500.

Note: /v1/realunit/account and /v1/realunit/holders query the external Ponder subgraph, which is mocked under ENVIRONMENT=loc; those endpoints remain a mock-mode limitation, independent of this change.

PR Completeness

  • Migration: n/a — no entity/column changes; the schema migration to PostgreSQL already landed in PSQL migration #3620.
  • Environment/Infrastructure: yes — docker-compose.yml, .env.local.example.
  • Service updates: n/a.
  • Frontend synchronization: n/a.

…let keys

The API was migrated to PostgreSQL (#3620) but the local setup tooling still
targeted MSSQL. Switch docker-compose, .env.local.example, scripts/setup.js and
migration/seed/seed.js to PostgreSQL, and generate every wallet key the
blockchain/integration services parse on startup (ICP, Citrea, Ark, KuCoin Pay,
payment webhook, Spark, Boltz). Scope the migration-immutability CI check to
schema migrations so the seed script can be maintained, and update the README.
Address review feedback: run the sequence setval even when a table is already
seeded (so a re-run after an interrupted first seed cannot leave the sequence
behind the existing ids), and update scripts/setup.sh to wait on Postgres
readiness instead of the removed db-init service.
scripts/setup.sh duplicated the canonical 'npm run setup' flow, was unreferenced,
and depended on MSSQL-only seeders (testdata.js, kyc-testdata.js) that are out of
scope for this migration and broke under the PostgreSQL switch.
@TaprootFreak TaprootFreak marked this pull request as ready for review June 8, 2026 13:37
@TaprootFreak TaprootFreak requested a review from davidleomay as a code owner June 8, 2026 13:37
@TaprootFreak TaprootFreak merged commit 05bf317 into develop Jun 8, 2026
7 checks passed
@TaprootFreak TaprootFreak deleted the feat/local-setup-postgres branch June 8, 2026 16:32
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.

2 participants