Skip to content

Conversation

@ChiragAgg5k
Copy link
Member

@ChiragAgg5k ChiragAgg5k commented Oct 20, 2025

Summary by CodeRabbit

  • New Features

    • Improved database management: list and delete databases and view their tables from the CLI.
    • Push workflow now shows planned DB changes and, after confirmation, applies deletions, creations, and updates in order.
    • Automatic resync of local configuration with remote state after destructive changes.
  • Bug Fixes / Behavior Changes

    • Remote-database-not-found now reports an error instead of silently creating a database.
    • Deletion warnings added for cascading effects.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Warning

Rate limit exceeded

@ChiragAgg5k has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 075c00c and 3d18a1e.

📒 Files selected for processing (1)
  • templates/cli/lib/commands/push.js.twig (2 hunks)

Walkthrough

This pull request updates the push command template to add three exports from ./tables-dbtablesDBList, tablesDBDelete, and tablesDBListTables — and introduces an internal helper checkAndApplyTablesDBChanges that computes diffs between local and remote TablesDB configurations, displays a change summary, prompts for confirmation, and applies deletions, creations, and updates in that order. pushTable is updated to call this helper and, when required, re-sync local configuration (tables and tablesDB) to reflect remote state. Error handling for missing remote databases now logs an error instead of creating them automatically.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

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 pull request title "feat: cli sync databases" accurately captures the main purpose of the changeset. The raw summary shows that the primary changes involve adding a checkAndApplyTablesDBChanges helper function that synchronizes local and remote TablesDB configurations, along with resync logic in the pushTable function to align local config with remote state after database changes. The title directly reflects this synchronization functionality and is specific enough to convey the primary change without being vague or overly broad. The title is concise, uses proper conventional prefixes, and clearly communicates the feature to a teammate reviewing the history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85f51dc and 16620e6.

📒 Files selected for processing (1)
  • templates/cli/lib/commands/push.js.twig (2 hunks)
⏰ 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). (19)
  • GitHub Check: build (8.3, Ruby30)
  • GitHub Check: build (8.3, Node16)
  • GitHub Check: build (8.3, KotlinJava17)
  • GitHub Check: build (8.3, Go118)
  • GitHub Check: build (8.3, PHP83)
  • GitHub Check: build (8.3, Node20)
  • GitHub Check: build (8.3, KotlinJava8)
  • GitHub Check: cli (console)
  • GitHub Check: build (8.3, FlutterStable)
  • GitHub Check: build (8.3, CLINode18)
  • GitHub Check: apple (client)
  • GitHub Check: build (8.3, CLINode16)
  • GitHub Check: build (8.3, Android5Java17)
  • GitHub Check: build (8.3, Android14Java17)
  • GitHub Check: swift (server)
  • GitHub Check: node (server)
  • GitHub Check: android (client)
  • GitHub Check: web (client)
  • GitHub Check: react-native (client)
🔇 Additional comments (2)
templates/cli/lib/commands/push.js.twig (2)

58-62: LGTM - New imports support database synchronization.

The added imports (tablesDBList, tablesDBDelete, tablesDBListTables) are necessary for the new synchronization functionality.


1828-1845: Configuration resync logic is correct and properly persists changes.

The localConfig.set() method updates the configuration data and calls this.write() to persist changes to the file, confirming that the integration at lines 1828-1845 will correctly:

  1. Filter out tables and tablesDBs that were deleted remotely
  2. Persist both updates to the local configuration file

No issues found.

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

♻️ Duplicate comments (3)
templates/cli/lib/commands/push.js.twig (3)

1747-1763: Avoid duplicate updates when both name and enabled change.

Current else-if chain can push the same DB twice to toUpdate. Compute both differences first, then push once.

Apply:

-        } else if (remoteDB.name !== localDB.name) {
-            toUpdate.push(localDB);
-            changes.push({
-                id: localDB.$id,
-                key: 'Name',
-                remote: chalk.red(remoteDB.name),
-                local: chalk.green(localDB.name)
-            });
-        } else if (remoteDB.enabled !== localDB.enabled) {
-            toUpdate.push(localDB);
-            changes.push({
-                id: localDB.$id,
-                key: 'Enabled?',
-                remote: chalk.red(remoteDB.enabled),
-                local: chalk.green(localDB.enabled)
-            });
-        }
+        } else {
+            let hasChanges = false;
+            if (remoteDB.name !== localDB.name) {
+                hasChanges = true;
+                changes.push({
+                    id: localDB.$id,
+                    key: 'Name',
+                    remote: chalk.red(remoteDB.name),
+                    local: chalk.green(localDB.name)
+                });
+            }
+            if (remoteDB.enabled !== localDB.enabled) {
+                hasChanges = true;
+                changes.push({
+                    id: localDB.$id,
+                    key: 'Enabled?',
+                    remote: chalk.red(remoteDB.enabled),
+                    local: chalk.green(localDB.enabled)
+                });
+            }
+            if (hasChanges) {
+                toUpdate.push(localDB);
+            }
+        }

1797-1804: Creation should honor enabled flag.

tablesDBCreate omits enabled, so newly created DBs won’t match local config.

Apply:

         await tablesDBCreate({
             databaseId: db.$id,
             name: db.name,
+            enabled: db.enabled,
             parseOutput: false
         });

1783-1816: Add failure isolation around delete/create/update loops.

A mid-run failure can leave state inconsistent. Wrap each op with try/catch, log context, and abort with a clear error.

Example:

-    for (const db of toDelete) {
-        log(`Deleting database ${db.name} ( ${db.$id} ) ...`);
-        await tablesDBDelete({ databaseId: db.$id, parseOutput: false });
-        success(`Deleted ${db.name} ( ${db.$id} )`);
-        needsResync = true;
-    }
+    for (const db of toDelete) {
+        try {
+            log(`Deleting database ${db.name} ( ${db.$id} ) ...`);
+            await tablesDBDelete({ databaseId: db.$id, parseOutput: false });
+            success(`Deleted ${db.name} ( ${db.$id} )`);
+            needsResync = true;
+        } catch (e) {
+            error(`Failed to delete database ${db.name} ( ${db.$id} ): ${e.message}`);
+            throw new Error(`Database sync failed during deletion of ${db.$id}. Some changes may have been applied.`);
+        }
+    }
@@
-    for (const db of toCreate) {
-        log(`Creating database ${db.name} ( ${db.$id} ) ...`);
-        await tablesDBCreate({
-            databaseId: db.$id,
-            name: db.name,
-            parseOutput: false
-        });
-        success(`Created ${db.name} ( ${db.$id} )`);
-    }
+    for (const db of toCreate) {
+        try {
+            log(`Creating database ${db.name} ( ${db.$id} ) ...`);
+            await tablesDBCreate({
+                databaseId: db.$id,
+                name: db.name,
+                enabled: db.enabled,
+                parseOutput: false
+            });
+            success(`Created ${db.name} ( ${db.$id} )`);
+        } catch (e) {
+            error(`Failed to create database ${db.name} ( ${db.$id} ): ${e.message}`);
+            throw new Error(`Database sync failed during creation of ${db.$id}. Some changes may have been applied.`);
+        }
+    }
@@
-    for (const db of toUpdate) {
-        log(`Updating database ${db.name} ( ${db.$id} ) ...`);
-        await tablesDBUpdate({
-            databaseId: db.$id,
-            name: db.name,
-            enabled: db.enabled,
-            parseOutput: false
-        });
-        success(`Updated ${db.name} ( ${db.$id} )`);
-    }
+    for (const db of toUpdate) {
+        try {
+            log(`Updating database ${db.name} ( ${db.$id} ) ...`);
+            await tablesDBUpdate({
+                databaseId: db.$id,
+                name: db.name,
+                enabled: db.enabled,
+                parseOutput: false
+            });
+            success(`Updated ${db.name} ( ${db.$id} )`);
+        } catch (e) {
+            error(`Failed to update database ${db.name} ( ${db.$id} ): ${e.message}`);
+            throw new Error(`Database sync failed during update of ${db.$id}. Some changes may have been applied.`);
+        }
+    }
🧹 Nitpick comments (2)
templates/cli/lib/commands/push.js.twig (2)

1716-1764: Reduce O(n²) scans with maps.

Building a map of remote DBs avoids repeated array.find and scales better.

Apply:

-    const changes = [];
+    const changes = [];
     const toCreate = [];
     const toUpdate = [];
     const toDelete = [];
 
-    // Check for deletions - remote DBs that aren't in local config
+    // Index remote by id
+    const remoteById = new Map(remoteTablesDBs.map(db => [db.$id, db]));
+
+    // Check for deletions - remote DBs that aren't in local config
     for (const remoteDB of remoteTablesDBs) {
-        const localDB = localTablesDBs.find(db => db.$id === remoteDB.$id);
+        const localDB = localTablesDBs.find(db => db.$id === remoteDB.$id);
         if (!localDB) {
             toDelete.push(remoteDB);
             changes.push({
@@
-    for (const localDB of localTablesDBs) {
-        const remoteDB = remoteTablesDBs.find(db => db.$id === localDB.$id);
+    for (const localDB of localTablesDBs) {
+        const remoteDB = remoteById.get(localDB.$id);

1892-1893: Differentiate 404 (expected) from real errors in tablesDB name sync.

Only log-and-continue on 404; surface other errors.

Apply:

-        } catch (err) {
-            log(`There was an error when pushing tables: ${err.message}`);
+        } catch (err) {
+            if (Number(err.code) === 404) {
+                log(`Tables DB ${databaseId} not found. Skipping name sync (possibly declined earlier).`);
+            } else {
+                error(`Failed to sync tables DB ${databaseId} name: ${err.message}`);
+                throw err;
+            }
         }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16620e6 and 075c00c.

📒 Files selected for processing (1)
  • templates/cli/lib/commands/push.js.twig (3 hunks)
🔇 Additional comments (2)
templates/cli/lib/commands/push.js.twig (2)

1828-1845: Resync flow after deletions looks good.

Fetching fresh remote DBs and pruning local tables/tablesDB to match is correct. Nice.


58-62: Verify that imported modules exist or will be provided during build/runtime.

After exhaustive repository search, the following modules referenced in lines 58–62 could not be located:

  • ./tables-db (imported functions: tablesDBList, tablesDBDelete, tablesDBListTables, tablesDBUpdateTable)
  • Also missing: ./databases, ./storage, ./messaging, ./teams, ./projects

These modules do not appear as .js, .twig, or any other file in the repository. Note that pull.js.twig (line 12) imports the same ./tables-db module, suggesting either: (1) modules are generated/injected at build time, (2) they are dynamically loaded, or (3) they require separate implementation.

Confirm these modules exist or will be provided before merge to prevent runtime errors.

@ChiragAgg5k ChiragAgg5k merged commit 0c4f514 into master Oct 21, 2025
52 checks passed
@ChiragAgg5k ChiragAgg5k deleted the sync-databases branch October 21, 2025 05:00
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