Skip to content

feat: add network column to schema for multi-network support#463

Open
silent-cipher wants to merge 14 commits into
mainfrom
refactor/add-network-to-schema
Open

feat: add network column to schema for multi-network support#463
silent-cipher wants to merge 14 commits into
mainfrom
refactor/add-network-to-schema

Conversation

@silent-cipher
Copy link
Copy Markdown
Collaborator

Summary

Introduces a network column to the core runtime tables so a single dealbot instance can safely operate across both calibration and mainnet without collisions between same-address providers/deals on different chains.

Step towards #297

Copilot AI review requested due to automatic review settings April 22, 2026 11:09
@FilOzzy FilOzzy added this to FOC Apr 22, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds network scoping to core runtime tables so a single backend instance can operate against both calibration and mainnet without address/deal collisions.

Changes:

  • Introduces network columns and updates PK/FK/unique constraints to be network-aware (migration + entity updates).
  • Updates several upsert/conflict targets to include network for correct deduplication across chains.
  • Adds SUPPORTED_NETWORKS constant and updates unit tests to reflect conflict key changes.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
apps/backend/src/database/migrations/1776790420000-AddNetworkColumn.ts Adds network columns, updates PK/FK/unique constraints and supporting indexes for multi-network isolation.
apps/backend/src/database/entities/storage-provider.entity.ts Makes StorageProvider primary key composite (address, network).
apps/backend/src/database/entities/deal.entity.ts Adds network column and updates SP relation join to (sp_address, network).
apps/backend/src/database/entities/job-schedule-state.entity.ts Adds network column (but currently leaves unique index definition misaligned with new schema).
apps/backend/src/database/entities/data-retention-baseline.entity.ts Makes baseline primary key composite (provider_address, network).
apps/backend/src/wallet-sdk/wallet-sdk.service.ts Updates provider upsert conflict target to include network.
apps/backend/src/wallet-sdk/wallet-sdk.service.spec.ts Updates unit test to expect network-aware conflict paths.
apps/backend/src/jobs/repositories/job-schedule.repository.ts Updates job schedule upsert conflict target to include network.
apps/backend/src/data-retention/data-retention.service.ts Updates baseline upsert conflict columns to include network.
apps/backend/src/data-retention/data-retention.service.spec.ts Updates unit test to expect network-aware conflict columns.
apps/backend/src/common/constants.ts Adds SUPPORTED_NETWORKS constant used by the migration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/backend/src/data-retention/data-retention.service.spec.ts
Comment thread apps/backend/src/wallet-sdk/wallet-sdk.service.ts
Comment thread apps/backend/src/jobs/repositories/job-schedule.repository.ts Outdated
Comment thread apps/backend/src/data-retention/data-retention.service.ts
Comment thread apps/backend/src/database/entities/job-schedule-state.entity.ts
Comment thread apps/backend/src/wallet-sdk/wallet-sdk.service.spec.ts Outdated
@rjan90 rjan90 requested a review from SgtPooki April 22, 2026 11:29
@rjan90 rjan90 moved this from 📌 Triage to 🔎 Awaiting review in FOC Apr 22, 2026
@rjan90 rjan90 added this to the M4.5: GA Fast Follows milestone Apr 22, 2026
@silent-cipher silent-cipher self-assigned this Apr 23, 2026
Copy link
Copy Markdown
Collaborator

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are just a few more gaps, and we need to make sure runtime reads pull from the correct network-scoped records. Pass network in the relevant DB read functions and make sure it’s handled in the appropriate repository/query logic.

Comment thread apps/backend/src/data-retention/data-retention.service.spec.ts
Comment thread apps/backend/src/data-retention/data-retention.service.ts
Comment thread apps/backend/src/database/entities/data-retention-baseline.entity.ts Outdated
Comment thread apps/backend/src/database/entities/deal.entity.ts Outdated
Comment thread apps/backend/src/database/entities/job-schedule-state.entity.ts Outdated
Comment thread apps/backend/src/database/entities/storage-provider.entity.ts Outdated
@github-project-automation github-project-automation Bot moved this from 🔎 Awaiting review to ⌨️ In Progress in FOC Apr 27, 2026
@BigLep BigLep moved this from ⌨️ In Progress to 🐱 Todo in FOC May 3, 2026
Copy link
Copy Markdown
Collaborator

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't see anything wrong at first glance, so I threw gemini + claude + codex at it and they uncovered potential gaps.. I'm testing locally and will get back with findings.

Comment thread apps/backend/src/jobs/jobs.service.ts
Comment thread apps/backend/src/jobs/jobs.service.ts Outdated
@silent-cipher
Copy link
Copy Markdown
Collaborator Author

I'm finding it a bit tricky to define the scope of this pr and where to draw the boundary for changes. My initial thought was to split the work between this pr and #468 so we could roll out smaller prs. Would you prefer that approach, or should I instead consolidate everything from #468 into this pr and make it a single change?

@SgtPooki
Copy link
Copy Markdown
Collaborator

SgtPooki commented May 6, 2026

@silent-cipher yea, i think the idea of a schema-only PR change would be ideal, and keeping PRs small, but this PR already does some application level piping through of data. as a minimum, I think we need #510 on top of this (or similar if you recommend differently)

I don't want to disrupt you too much, so let me know what you think would be best

@silent-cipher
Copy link
Copy Markdown
Collaborator Author

I’m thinking of splitting this into three PRs to keep things small and backward compatible -

silent-cipher and others added 6 commits May 21, 2026 18:11
* fix(network): close multi-network gaps before #297 expansion

- NETWORK env now required (Joi). Migration's fail-fast was bypassed by
  Joi default writing back to process.env.
- DealService + dev-tools set deal.network from config on every insert.
  Drop DB DEFAULT clauses post-backfill so missed write paths fail loudly.
- Thread network through ScheduleRow and pg-boss payloads (SpJobData,
  ProvidersRefreshJobData, DataRetentionJobData) so workers can route
  by network instead of relying on the running pod's NETWORK env.

* refactor: expand network filtering

* refactor: use network filtering in job scheduling

---------

Co-authored-by: silent-cipher <puspendramahariya@gmail.com>
@rjan90 rjan90 moved this from 🐱 Todo to ⌨️ In Progress in FOC May 25, 2026
@silent-cipher silent-cipher requested a review from SgtPooki May 26, 2026 15:48
@BigLep BigLep moved this from ⌨️ In Progress to 🔎 Awaiting review in FOC May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review

Development

Successfully merging this pull request may close these issues.

6 participants