Skip to content

Conversation

@HarshMN2345
Copy link
Member

@HarshMN2345 HarshMN2345 commented Nov 22, 2025

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

Summary by CodeRabbit

  • Bug Fixes

    • Added error handling for backup policy creation; users now receive a warning if policy creation fails while the database is created.
  • Refactor

    • Backup UI and feature gating now rely on each plan's backup capabilities and policy limits (e.g., backups enabled / policy count) for consistent visibility.
    • Dropdown logic simplified to use policy-count checks when showing policy options.

✏️ Tip: You can customize this high-level summary in your review settings.

@appwrite
Copy link

appwrite bot commented Nov 22, 2025

Console (appwrite/console)

Project ID: 688b7bf400350cbd60e9

Sites (1)
Site Status Logs Preview QR
 console-stage
688b7cf6003b1842c9dc
Ready Ready View Logs Preview URL QR Code

Tip

GraphQL API works alongside REST and WebSocket protocols

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

Walkthrough

This PR updates three Svelte UI files to replace direct billing-plan checks with a new currentPlan store usage. Imports of BillingPlan and organization were removed and replaced with currentPlan from $lib/stores/organization. UI conditionals that previously used organization.billingPlan/BillingPlan now use currentPlan.backupsEnabled or currentPlan.backupPolicies. In the backups dropdown, plan-based visibility was replaced by a maxPolicies === 1 check. Optional chaining is used where currentPlan may be undefined.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Files needing focused review:
    • src/routes/(console)/project-[region]-[project]/databases/create.svelte — verify currentPlan.backupsEnabled gating and template bindings
    • src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/containerHeader.svelte — confirm maxPolicies === 1 logic matches intended UX
    • src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/createPolicy.svelte — review all replacements of BillingPlan/organization.billingPlan with currentPlan?.backupPolicies and optional chaining
  • Cross-cutting:
    • Ensure currentPlan store import paths and naming are consistent
    • Confirm null/undefined handling (optional chaining) does not change UX in edge cases
    • Verify no remaining references to the removed BillingPlan or organization symbols remain in these files

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: use plan capabilities instead of hardcoded plan checks for backup policy' accurately summarizes the main change across all three modified files: replacing hardcoded BillingPlan checks with dynamic plan capability attributes (backupsEnabled, backupPolicies, maxPolicies).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-use-plan-capabilities-for-policy-checks

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a07c0a and e0d881d.

📒 Files selected for processing (1)
  • src/routes/(console)/project-[region]-[project]/databases/create.svelte (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/routes/(console)/project-[region]-[project]/databases/create.svelte
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: e2e
  • GitHub Check: build

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/createPolicy.svelte (1)

23-24: Plan-capability checks via $currentPlan.backupPolicies look correct; clarify edge cases and comment

  • Importing currentPlan and driving behavior off $currentPlan?.backupPolicies (1 → Pro “daily-only” flow, >1 → Scale+ full presets/custom) achieves the goal of removing hardcoded BillingPlan checks and aligns with how the UI is structured here.
  • The reactive pre-check for Pro (if ($currentPlan?.backupPolicies === 1 && isFromBackupsTab)) is consistent with the Pro path below, but the comment “pre-check the hourly if on pro plan” no longer matches the implementation (it checks policy.label === 'Daily'). Consider updating the comment to avoid confusion.
  • For plans where backupPolicies might be 0 or undefined but backups are still technically enabled, this component will fall into the “Scale+” ({:else}) branch and show the full custom-policy UI. If such configurations are possible, it may be worth explicitly handling 0/undefined (e.g., by gating on backupPolicies >= 2 or by avoiding rendering until currentPlan is fully resolved) so we don’t accidentally expose UI that the backend rejects.

Also applies to: 139-160, 178-195, 197-239

src/routes/(console)/project-[region]-[project]/databases/create.svelte (1)

10-11: Policy-creation error handling and $currentPlan.backupsEnabled gating are solid; consider initial-plan state

  • The inner try { await createPolicies(databaseId); } catch (policyError) { ... } is a good refinement: database creation no longer fails if policy creation does, but users still get a clear warning and error telemetry via trackError. The fallback message also makes it explicit that the database was created successfully.
  • Switching the Cloud-only backups UI to {#if !$currentPlan?.backupsEnabled} … {:else} <CreatePolicy … /> {/if} correctly ties visibility to plan capabilities rather than BillingPlan constants, and createPolicies’ early-return on an empty totalPolicies keeps the unconditional call safe.
  • One subtle edge case: when the component first renders and $currentPlan is still undefined (if the store is hydrated asynchronously), !$currentPlan?.backupsEnabled evaluates to true, so paying users might briefly see the “This database won't be backed up” warning before the store updates. If that’s observable in practice, consider guarding on a dedicated “plan loaded” flag or a default currentPlan value so the alert only appears once the plan is known.

Also applies to: 80-101, 143-158

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7407bbd and 0a07c0a.

📒 Files selected for processing (3)
  • src/routes/(console)/project-[region]-[project]/databases/create.svelte (3 hunks)
  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/containerHeader.svelte (1 hunks)
  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/createPolicy.svelte (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-30T07:41:06.679Z
Learnt from: ItzNotABug
Repo: appwrite/console PR: 2425
File: src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)/empty.svelte:454-468
Timestamp: 2025-09-30T07:41:06.679Z
Learning: In `src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)/empty.svelte`, the column suggestions API (console.suggestColumns) has a maximum limit of 7 columns returned, which aligns with the initial placeholder count of 7 in customColumns.

Applied to files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/containerHeader.svelte
📚 Learning: 2025-10-07T14:17:11.597Z
Learnt from: ItzNotABug
Repo: appwrite/console PR: 2413
File: src/routes/(console)/project-[region]-[project]/databases/database-[database]/(entity)/helpers/terminology.ts:28-28
Timestamp: 2025-10-07T14:17:11.597Z
Learning: In src/routes/(console)/project-[region]-[project]/databases/database-[database]/(entity)/helpers/terminology.ts, the empty `vectordb: {}` entry in baseTerminology is intentional. The vectordb database type is not currently used because the backend API is not finalized, and no database type returns 'vectordb' at the moment.

Applied to files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/containerHeader.svelte
  • src/routes/(console)/project-[region]-[project]/databases/create.svelte
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: e2e
  • GitHub Check: build
🔇 Additional comments (1)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/backups/containerHeader.svelte (1)

51-67: Using maxPolicies === 1 as the switch for Tag vs Badge looks consistent

The new condition that treats maxPolicies === 1 as the “single-policy plan” path and falls back to the Badge for all other values keeps the UI behavior simple and decouples it from specific plan enums. As long as parents reliably pass maxPolicies according to the plan capabilities (1 for Pro, >1 for Scale, etc.), this should behave identically to the previous plan-based logic.

Comment on lines 93 to 100
addNotification({
type: 'warning',
message:
policyError.message ||
'Failed to create backup policies. The database was created successfully.'
});
trackError(policyError, Submit.DatabaseCreate);
}
Copy link
Member

Choose a reason for hiding this comment

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

I doubt this would if proper plan based are already added above.

@ItzNotABug ItzNotABug merged commit 5b141ec into main Nov 22, 2025
4 checks passed
@ItzNotABug ItzNotABug deleted the fix-use-plan-capabilities-for-policy-checks branch November 22, 2025 12:40
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.

3 participants