Skip to content

chore: switch to timeM#2908

Merged
chronark merged 3 commits intomainfrom
switch-to-timeM
Feb 23, 2025
Merged

chore: switch to timeM#2908
chronark merged 3 commits intomainfrom
switch-to-timeM

Conversation

@chronark
Copy link
Collaborator

@chronark chronark commented Feb 23, 2025

  • chore: read and write xxxM times
  • chore: make everything optional

Summary by CodeRabbit

This update brings behind‐the-scenes improvements that optimize system reliability and data consistency while preserving current functionality.

  • Refactor
    • Standardized internal data handling for key management, permissions, and rate limiting to ensure consistent performance.
  • Chores
    • Enhanced timestamp precision for more accurate record keeping.
    • Made formatting and cleanup adjustments for improved maintainability.

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2025

⚠️ No Changeset found

Latest commit: 2f2854f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2025 4:18pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2025 4:18pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2025 4:18pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2025 4:18pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2025

📝 Walkthrough

Walkthrough

This pull request updates several type definitions and schema comments across multiple modules. The modifications include introducing new Insert* types to specify insertion models, updating variable type declarations (e.g., switching from Permission[] to InsertPermission[]), and adjusting SQL timestamp precision in billing-related files. Commented examples in internal database schema files are revised to suggest default timestamp values. No changes to control flow or logic are introduced beyond these type refinements and formatting improvements.

Changes

File(s) Change Summary
apps/api/.../harness.ts Added new type InsertPermission and updated the create variable type in createRootKey from Permission[] to InsertPermission[].
apps/api/.../v1_migrations_createKey.ts Updated type declarations to use InsertEncryptedKey, InsertIdentity, InsertKey, InsertKeyPermission, and InsertKeyRole for key management arrays.
apps/api/.../v1_ratelimits_limit.ts Modified import and variable type by replacing RatelimitNamespace with InsertRatelimitNamespace.
apps/billing/.../keywords.ts and apps/billing/.../keyword-research.ts Adjusted SQL statement for updatedAt to use CURRENT_TIMESTAMP(3); applied minor formatting/whitespace tweaks.
apps/dashboard/.../rbac.ts Changed the newPermissions array type from Permission[] to InsertPermission[] and updated the permission object declaration (explicitly typed, with removal of deletedAtM).
internal/db/.../keys.ts, ratelimit.ts, rbac.ts, workspaces.ts Revised commented-out timestamp declarations by suggesting default values (using CURRENT_TIMESTAMP(3)) and adjusted comment formatting where applicable.
internal/db/.../types.ts Added new export types for insert operations (e.g., InsertKey, InsertApi, InsertWorkspace, etc.) using InferInsertModel from drizzle-orm.

Possibly related PRs

  • fix: key creation and default prefix #2816: Updates the newPermissions array type in the upsertPermissions function to use InsertPermission[], aligning with changes in this PR.
  • chore: lifecycle date migration #2906: Modifies the create variable type in the createRootKey method of the Harness class to adopt InsertPermission, directly relating to this PR’s type update.
  • feat: analytics api #2740: Aligns the usage of the InsertPermission type across permission handling functions, showing a direct code-level connection to the modifications in this pull request.

Suggested reviewers

  • mcstepp
  • perkinsjr
  • MichaelUnkey
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2025

Thank you for following the naming conventions for pull request titles! 🙏

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

🧹 Nitpick comments (2)
internal/db/src/schema/ratelimit.ts (1)

14-19: Consider implementing the suggested timestamp handling.

The commented code provides a good pattern for timestamp handling with proper precision. Consider uncommenting and implementing these changes to ensure consistent timestamp management across the codebase.

internal/db/src/schema/keys.ts (1)

51-51: Consider implementing the suggested timestamp handling.

The commented timestamp field with millisecond precision aligns with the codebase's timestamp handling pattern. Consider uncommenting and implementing this change for consistent timestamp management.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9999431 and 2f2854f.

📒 Files selected for processing (11)
  • apps/api/src/pkg/testutil/harness.ts (2 hunks)
  • apps/api/src/routes/v1_migrations_createKey.ts (2 hunks)
  • apps/api/src/routes/v1_ratelimits_limit.ts (2 hunks)
  • apps/billing/src/lib/keywords.ts (6 hunks)
  • apps/billing/src/trigger/glossary/keyword-research.ts (1 hunks)
  • apps/dashboard/lib/trpc/routers/rbac.ts (3 hunks)
  • internal/db/src/schema/keys.ts (1 hunks)
  • internal/db/src/schema/ratelimit.ts (2 hunks)
  • internal/db/src/schema/rbac.ts (5 hunks)
  • internal/db/src/schema/workspaces.ts (1 hunks)
  • internal/db/src/types.ts (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • apps/billing/src/trigger/glossary/keyword-research.ts
  • apps/billing/src/lib/keywords.ts
  • internal/db/src/schema/workspaces.ts
  • internal/db/src/schema/rbac.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Go API Local / test_agent_local
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
internal/db/src/types.ts (1)

1-69: LGTM! Well-structured type definitions.

The introduction of Insert* types for each schema model is a good practice. It provides clear type separation between read and write operations, enhancing type safety and making the codebase more maintainable.

apps/api/src/pkg/testutil/harness.ts (2)

8-18: LGTM! Good type safety in test utilities.

The addition of InsertPermission type and its usage in the test harness maintains type safety and aligns with the new type system.


108-117: LGTM! Proper use of insert type.

The change from Permission[] to InsertPermission[] correctly reflects the type system changes and maintains type safety in test data creation.

apps/api/src/routes/v1_ratelimits_limit.ts (1)

9-9: Type changes align with insertion operation requirements.

The change from RatelimitNamespace to InsertRatelimitNamespace better reflects the intent of creating a new namespace record. This type specificity helps prevent accidental misuse of fields that should only be present after insertion.

Also applies to: 188-188

apps/api/src/routes/v1_migrations_createKey.ts (1)

10-14: Consistent application of Insert types for database operations.*

The changes properly implement the Insert* type pattern across all relevant type declarations, improving type safety during insertion operations. The array declarations now correctly reflect that these are collections of entities being prepared for insertion rather than existing records.

Also applies to: 319-323

apps/dashboard/lib/trpc/routers/rbac.ts (1)

1-1: Type refinements improve clarity and consistency.

The changes enhance type safety and readability:

  1. Import statement now correctly includes both Permission and InsertPermission types
  2. newPermissions array properly typed as InsertPermission[]
  3. Explicit Permission type annotation adds clarity to the object structure

Also applies to: 765-765, 775-775

Comment on lines +69 to 76
// createdAt: datetime("created_at", { mode: "date", fsp: 3 })
// .notNull()
// .default(sql`CURRENT_TIMESTAMP(3)`)
// .$defaultFn(() => new Date()),
// updatedAt: datetime("updated_at", { mode: "date", fsp: 3 }).$onUpdateFn(() => new Date()),
// updatedAt: datetime("updated_at", { mode: "date", fsp: 3 }),
// deletedAt: datetime("deleted_at", { mode: "date", fsp: 3 }),
...lifecycleDatesMigration,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify timestamp handling consistency.

The commented timestamp handling in ratelimitOverrides should match the pattern in ratelimitNamespaces. Consider implementing both to maintain consistency.

Run this script to check timestamp handling across the codebase:


🏁 Script executed:

#!/bin/bash
# Description: Check timestamp handling patterns across schema files

# Search for timestamp-related patterns in schema files
rg -A 3 'CURRENT_TIMESTAMP\(3\)' 
rg -A 3 '\$defaultFn\(\(\) => new Date\(\)\)'
rg -A 3 '\$onUpdateFn\(\(\) => new Date\(\)\)'

Length of output: 7164


Timestamp Handling Consistency in Schema Files

In file internal/db/src/schema/ratelimit.ts, the commented-out timestamp logic (using patterns like $defaultFn(() => new Date()) and $onUpdateFn(() => new Date())) does not currently align with the pattern used in other parts of the codebase (for example, the SQL-based CURRENT_TIMESTAMP(3) approach seen in files such as apps/billing/src/lib/keywords.ts). Please review and update the timestamp handling so that the implementation in ratelimitOverrides mirrors that in ratelimitNamespaces—whether that means uncommenting and adapting the current logic or switching entirely to the SQL default pattern. This adjustment will help ensure a uniform, predictable behavior for timestamp fields across our schemas.

@chronark chronark merged commit 74fb622 into main Feb 23, 2025
29 of 31 checks passed
@chronark chronark deleted the switch-to-timeM branch February 23, 2025 16:31
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.

1 participant