Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove table const usage in favour of string literals #426

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

mike182uk
Copy link
Member

no refs

We decided to remove the usage of table constants in favour of string literals. This brings constistency where table names are referenced and also makes writing / reading complex queries easier

Verified

This commit was signed with the committer’s verified signature.
mike182uk Michael Barrett
no refs

We decided to remove the usage of table constants in favour of string literals.
This brings constistency where table names are referenced and also makes writing
/ reading complex queries easier
Copy link

coderabbitai bot commented Mar 20, 2025

Walkthrough

This pull request removes constant declarations that represent database table names from various parts of the codebase. Instead of using constants for tables like "accounts", "follows", "sites", "users", "posts", "likes", "reposts", and "feeds", the code now uses string literals directly in the database operations. The changes have been applied across different modules including step definitions, service integration tests, and repository tests. Imports of these constants from a central module have also been removed. No modifications have been made to the underlying business logic or control flow; the updates solely alter the way table names are referenced in database queries and setup/cleanup procedures.

Suggested reviewers

  • allouis
  • vershwal

📜 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 4b84f9c and c4311cf.

📒 Files selected for processing (8)
  • features/step_definitions/stepdefs.js (5 hunks)
  • src/account/account.service.integration.test.ts (8 hunks)
  • src/account/account.service.ts (16 hunks)
  • src/constants.ts (0 hunks)
  • src/feed/feed.service.integration.test.ts (2 hunks)
  • src/post/post.repository.knex.integration.test.ts (17 hunks)
  • src/post/post.repository.knex.ts (11 hunks)
  • src/site/site.service.integration.test.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • src/constants.ts
🧰 Additional context used
🧬 Code Definitions (4)
src/site/site.service.integration.test.ts (1)
src/app.ts (1) (1)
  • db (235-235)
src/account/account.service.ts (1)
features/step_definitions/stepdefs.js (1) (1)
  • accountId (551-568)
src/post/post.repository.knex.integration.test.ts (1)
features/step_definitions/stepdefs.js (1) (1)
  • client (415-415)
features/step_definitions/stepdefs.js (1)
src/db.ts (1) (1)
  • client (3-16)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build, Test and Deploy
🔇 Additional comments (35)
src/post/post.repository.knex.integration.test.ts (2)

44-46: Table string literals implemented consistently.

The replacement of table constants with string literals ('reposts', 'likes', 'posts') aligns with the PR objective of improving query readability and consistency.


177-177: String literals for table names applied consistently.

The use of string literals for table names in database queries is consistently applied throughout the test file, improving readability and making it easier to understand the queries at a glance.

Also applies to: 221-221, 239-239, 254-254, 292-292, 302-302, 356-356, 587-587, 631-631, 667-667, 677-677, 738-738, 824-824, 833-833

src/post/post.repository.knex.ts (4)

596-596: Table name as string literal applied to post insert.

The replacement of the table constant with the string literal 'posts' makes the code more direct and easier to read.


640-640: Consistent use of 'likes' string literal in database operations.

The database operations for likes now use the string literal 'likes' directly, which is consistent with the PR objective of simplifying database queries.

Also applies to: 655-655, 682-682


708-708: Repost table operations updated with string literals.

All database operations related to 'reposts' have been updated to use string literals, maintaining consistency across the repository.

Also applies to: 724-724, 752-752, 773-773


497-497: String literals used in post updates.

The transaction updates for post like and repost counts now use string literals for the 'posts' table, which is consistent with other changes in this file.

Also applies to: 534-534

src/account/account.service.integration.test.ts (3)

52-55: Consistent string literal usage in DB cleanup.

The database cleanup now uses string literals ('follows', 'accounts', 'users', 'sites') instead of constants, which aligns with the PR objective of improving consistency.


151-151: Account and user tables referenced with string literals.

Database queries for accounts and users now use direct string literals, making the code more straightforward.

Also applies to: 160-160, 181-181


205-205: Follow relationship queries updated to use string literals.

All queries related to the 'follows' table now use string literals directly, improving consistency and readability of database operations.

Also applies to: 216-216, 236-236, 258-258, 263-263

src/site/site.service.integration.test.ts (2)

41-43: DB cleanup using string literals instead of constants.

The database cleanup operations now use string literals for table names, aligning with the project-wide change to improve query consistency.


89-89: Site queries updated to use string literals.

Queries for site information now use the 'sites' string literal directly instead of a constant, making the code more direct and easier to read.

Also applies to: 103-103

src/feed/feed.service.integration.test.ts (3)

96-99: Replaced table constants with string literals

The change to use string literals for table names ('feeds', 'users', 'accounts') aligns with the PR objective to improve consistency in table name references.


107-113: String literals used consistently across table operations

Table names are now consistently referenced as string literals in truncate operations, which makes the code more straightforward.


225-227: Direct string literal usage for 'reposts' table

Table name string literal is consistently used here for the reposts table.

src/account/account.service.ts (16)

125-130: Replaced table constants with string literals in account creation

String literals ('accounts', 'users') are now used directly in the database operations, consistent with the PR objective.


153-156: String literal used for external account creation

'accounts' string literal is used directly in the database query for creating external accounts.


175-181: Direct string reference for follows table

The 'follows' table is now referenced directly as a string literal in the recordAccountFollow method.


194-199: String literal for follows table in unfollow operation

Consistent use of 'follows' string literal in the database operation for unfollowing.


212-212: Direct string reference for accounts table lookup

Using 'accounts' string literal directly in the getAccountByApId method.


221-222: String literal for users table

'users' string literal is used directly in the query for finding users by site ID.


235-237: String literal for accounts table in getDefaultAccountForSite

Direct use of 'accounts' string literal in the query to fetch account data.


258-270: String literals in complex join query

Table references ('follows', 'accounts') have been converted to string literals in this more complex select query with joins and ordering.


279-281: String literal in count query for follows

'follows' string literal used in the getFollowingAccountsCount method.


292-296: String literals in liked count join query

'likes' and 'posts' table references are now string literals in this join query.


307-313: String literals in post count queries

Both 'posts' and 'reposts' tables are referenced as string literals in the getPostCount method.


330-342: String literals in follower accounts query

The complex query in getFollowerAccounts now uses string literals ('follows', 'accounts') consistently.


351-353: String literal in follower count query

'follows' string literal used in the getFollowerAccountsCount method.


368-372: String literal in following check query

'follows' string literal used in the checkIfAccountIsFollowing method.


378-378: String literal in account lookup by ID

'accounts' string literal used in the getByInternalId method.


415-415: String literal in account update operation

'accounts' string literal used in the updateAccount method.

features/step_definitions/stepdefs.js (5)

451-456: Replaced table constants with string literals in test truncation operations

String literals ('key_value', 'follows', 'accounts', 'users', 'sites') are used consistently in the beforeAll cleanup.


524-529: String literals in Before hook truncation operations

Table truncation operations in the Before hook also consistently use string literals.


531-534: String literal for sites table insertion

'sites' string literal used when inserting site data in the test setup.


551-568: String literal for accounts table insertion

'accounts' string literal used for the insert operation when setting up test actor accounts.


570-573: String literal for users table insertion

'users' string literal used when inserting user data that links to the account.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @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.

Sorry, something went wrong.

@mike182uk mike182uk merged commit 0c32e2a into main Mar 21, 2025
4 checks passed
@mike182uk mike182uk deleted the misc-remove-table-const-usage branch March 21, 2025 08:04
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.

None yet

2 participants