Skip to content

Schema sync api#353

Merged
yash-pouranik merged 10 commits into
geturbackend:mainfrom
Ayush4958:schema-sync-api
Jul 11, 2026
Merged

Schema sync api#353
yash-pouranik merged 10 commits into
geturbackend:mainfrom
Ayush4958:schema-sync-api

Conversation

@Ayush4958

@Ayush4958 Ayush4958 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

🚀 Pull Request Description

I had created the backend infrastructure and CLI tooling for a declarative Schema as Code workflow. It allows developers to define and update their MongoDB schemas locally in their repository &atomically synchronize them to the remote urBackend project using ub push.

🛠️ Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 UI/UX improvement (Frontend only)
  • ⚙️ Refactor / Chore

🧪 Testing & Validation

Backend Verification:

  • I have run npm test in the backend/ directory and all tests passed.
  • I have verified the API endpoints using Postman/Thunder Client.
  • New unit tests have been added (if applicable).

Frontend Verification:

  • I have run npm run lint in the frontend/ directory.
  • Verified the UI changes on different screen sizes (Responsive).
  • Checked for any console errors in the browser dev tools.

✅ Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings or errors.
  • I have updated the documentation (README/Docs) accordingly.

Summary by CodeRabbit

  • New Features
    • Added a CLI push command to sync local schemas with a linked remote project.
    • Introduced PUT /projects/:projectId/sync-schema to sync collections (with schema validation and plan-based limits).
    • Preserves existing collection settings during synchronization and invalidates related caches after updates.
  • Bug Fixes
    • Improved CSRF handling for eligible bearer-token requests.
    • Refined auth token refresh retry behavior for more reliable 401 recovery.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff92a1b2-098e-4215-9aaf-72de54b259ff

📥 Commits

Reviewing files that changed from the base of the PR and between b957cc3 and a80ae5e.

📒 Files selected for processing (3)
  • apps/dashboard-api/src/controllers/syncSchema.controller.js
  • sdks/urbackend-cli/src/commands/push/index.ts
  • sdks/urbackend-sdk/src/client.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/dashboard-api/src/controllers/syncSchema.controller.js
  • sdks/urbackend-cli/src/commands/push/index.ts

📝 Walkthrough

Walkthrough

Adds a ub push CLI command that validates and synchronizes local schemas to a linked project through a new admin-protected API endpoint, preserving collection RLS settings and supporting PAT-authenticated requests.

Changes

Schema synchronization

Layer / File(s) Summary
Schema validation and project update
packages/common/src/utils/input.validation.js, packages/common/src/index.js, apps/dashboard-api/src/controllers/syncSchema.controller.js
Validates collection payloads, sanitizes schemas, preserves RLS settings, validates the users collection, updates project collections atomically, and refreshes caches.
Project route and API client
apps/dashboard-api/src/app.js, apps/dashboard-api/src/routes/projects.js, sdks/urbackend-cli/src/services/project.service.ts, sdks/urbackend-sdk/src/client.ts
Adds the protected sync endpoint, permits ubpat_ bearer requests through CSRF bypass, provides a typed client request, and uses typed access-token extraction during refresh retries.
CLI push command
sdks/urbackend-cli/src/commands/push/index.ts, sdks/urbackend-cli/src/index.ts
Loads local schemas, submits them to the linked project, reports synced collections, handles API errors, and registers the push command.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant pushCommand
  participant ProjectAPI
  participant ProjectDatabase
  Developer->>pushCommand: Run ub push
  pushCommand->>ProjectAPI: PUT /projects/:projectId/sync-schema
  ProjectAPI->>ProjectDatabase: Atomically replace collections
  ProjectDatabase-->>ProjectAPI: Updated project
  ProjectAPI-->>pushCommand: Synced collection names
  pushCommand-->>Developer: Print synchronization summary
Loading

Possibly related PRs

Suggested labels: type:feature, level:advanced

Suggested reviewers: yash-pouranik, Nitin-kumar-yadav1307

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly refers to the new schema sync API added by this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/dashboard-api/src/controllers/syncSchema.controller.js (1)

15-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared helpers instead of mirroring from project.controller.js.

The comment explicitly states these helpers are "mirrored from project.controller.js." Duplicating normalizeFieldKey, normalizeFieldType, isRequiredField, toPlainObject, sanitizeSchemaFields, getDefaultRlsForCollection, and validateUsersSchema across two controllers risks divergent behavior — a bug fix in one location won't propagate to the other. Extract these into a shared module (e.g., packages/common/src/utils/schema.helpers.js) and import from both controllers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/dashboard-api/src/controllers/syncSchema.controller.js` at line 15,
Extract normalizeFieldKey, normalizeFieldType, isRequiredField, toPlainObject,
sanitizeSchemaFields, getDefaultRlsForCollection, and validateUsersSchema from
both controllers into a shared schema helpers module, then update
syncSchema.controller.js and project.controller.js to import and use those
shared implementations instead of maintaining duplicated helpers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/dashboard-api/src/controllers/syncSchema.controller.js`:
- Line 179: Update the users collection check in the relevant schema-sync logic
to compare entry.name case-insensitively using entry.name.toLowerCase() ===
"users", matching getDefaultRlsForCollection and ensuring validation applies to
names such as "Users".

In `@sdks/urbackend-cli/src/commands/push/index.ts`:
- Around line 76-78: Update the catch-all branch in the push command’s error
handling to include the caught error details in the logger.error call instead of
logging only the generic connection message. Preserve the existing
APIError-specific handling and exit-code behavior, while adding clear context
and the original error for unexpected failures.

---

Nitpick comments:
In `@apps/dashboard-api/src/controllers/syncSchema.controller.js`:
- Line 15: Extract normalizeFieldKey, normalizeFieldType, isRequiredField,
toPlainObject, sanitizeSchemaFields, getDefaultRlsForCollection, and
validateUsersSchema from both controllers into a shared schema helpers module,
then update syncSchema.controller.js and project.controller.js to import and use
those shared implementations instead of maintaining duplicated helpers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a0d5d6d4-aca4-46f4-9141-d0130b1cc60f

📥 Commits

Reviewing files that changed from the base of the PR and between 272bbe5 and b957cc3.

📒 Files selected for processing (8)
  • apps/dashboard-api/src/app.js
  • apps/dashboard-api/src/controllers/syncSchema.controller.js
  • apps/dashboard-api/src/routes/projects.js
  • packages/common/src/index.js
  • packages/common/src/utils/input.validation.js
  • sdks/urbackend-cli/src/commands/push/index.ts
  • sdks/urbackend-cli/src/index.ts
  • sdks/urbackend-cli/src/services/project.service.ts

Comment thread apps/dashboard-api/src/controllers/syncSchema.controller.js Outdated
Comment thread sdks/urbackend-cli/src/commands/push/index.ts
@Ayush4958

Copy link
Copy Markdown
Contributor Author

@yash-pouranik
PR is ready for review

@yash-pouranik
yash-pouranik merged commit 5e9c95a into geturbackend:main Jul 11, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants