8000 feat: Postgres base as schema by pranavxc · Pull Request #9591 · nocodb/nocodb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Postgres base as schema #9591

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

Merged
merged 4 commits into from
Oct 5, 2024
Merged

Conversation

pranavxc
Copy link
Member
@pranavxc pranavxc commented Oct 5, 2024

Change Summary

Provide summary of changes with issue number if any.

Change type

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Test/ Verification

Provide summary of changes.

Additional information / screenshots (optional)

Anything for maintainers to be made aware of

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 5, 2024
@pranavxc pranavxc requested a review from mertmit October 5, 2024 11:54
Copy link
Contributor
coderabbitai bot commented Oct 5, 2024
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request includes significant updates to the environment variable documentation and related code functionalities. A new environment variable, NC_DISABLE_BASE_AS_PG_SCHEMA, is introduced, enhancing the configuration for PostgreSQL schemas. The documentation is restructured to improve clarity, with several new Litestream-related variables added. Additionally, the initBaseBehaviour.ts file receives a new function for checking schema creation permissions, while the BasesService class refines its database configuration logic based on the updated environment variables.

Changes

File Path Change Summary
packages/noco-docs/docs/...020.environment-variables.md Restructured documentation; added new variable NC_DISABLE_BASE_AS_PG_SCHEMA; moved LITESTREAM_S3_BUCKET and added multiple Litestream-related variables. Updated descriptions for clarity.
packages/nocodb/src/helpers/initBaseBehaviour.ts Added async function isSchemaCreateAllowed for checking schema creation permissions; modified initBaseBehavior to use this function.
packages/nocodb/src/providers/init-meta-service.provider.ts Repositioned initBaseBehavior function call within the initialization process; no new functionality added.
packages/nocodb/src/services/bases.service.ts Updated baseCreate method logic to incorporate new environment variable checks for database configurations; refined error handling and sanitization.

Possibly related PRs

Suggested labels

🛑 Status: Do Not Merge, trigger-CI, size:XL, lgtm

Suggested reviewers

  • mertmit

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 797748c and 1851104.

📒 Files selected for processing (1)
  • packages/nocodb/.npmignore (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/nocodb/.npmignore

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 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.

@dosubot dosubot bot added the 🔦 Type: Feature New functionality is requested. label Oct 5, 2024
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: 5

🧹 Outside diff range and nitpick comments (8)
packages/nocodb/src/providers/init-meta-service.provider.ts (1)

Line range hint 1-122: LGTM: Initialization process structure maintained

The overall structure and flow of the initialization process have been maintained, with the only change being the repositioning of initBaseBehavior. This change appears intentional and likely aims to ensure that the base behavior is set up after all other components are initialized.

Consider updating the comments at the beginning of the useFactory function to reflect the new order of operations, including the initBaseBehavior step at the end. This will help maintain clear documentation of the initialization process.

packages/noco-docs/docs/020.getting-started/050.self-hosted/020.environment-variables.md (4)

78-96: LGTM! Consider adding a link to the Postgres Base as Schema section.

The changes in the "Product Configuration" section look good. The new variable NC_DISABLE_BASE_AS_PG_SCHEMA is well-described, and the updates to existing variable descriptions improve clarity.

Consider adding a direct link to the "Postgres Base as Schema" section in the description of NC_DISABLE_BASE_AS_PG_SCHEMA for easier navigation. For example:

-| `NC_DISABLE_BASE_AS_PG_SCHEMA` | No | Disables the creation of a schema for each base in PostgreSQL.  [Click here for more detail](#postgres-base-as-schema)                                                                                |                                            |
+| `NC_DISABLE_BASE_AS_PG_SCHEMA` | No | Disables the creation of a schema for each base in PostgreSQL. See [Postgres Base as Schema](#postgres-base-as-schema) for more details.                                                             |                                            |
🧰 Tools
🪛 LanguageTool

[uncategorized] ~87-~87: The official spelling of this programming framework is “Express.js”.
Context: ... allowed in the request body, based on [ExpressJS limits](https://expressjs.com/en/resour...

(NODE_JS)


97-99: Expand the explanation of the Postgres Base as Schema feature.

The new section provides a good introduction to the Postgres Base as Schema feature. However, it could benefit from a slightly more detailed explanation.

Consider expanding the explanation to include:

  1. The benefits of using this feature (e.g., improved organization, security, or performance).
  2. Any potential implications of disabling it.
  3. A brief example of how it affects database structure.

Here's a suggested expansion:

### Postgres Base as Schema

For PostgreSQL, a unique schema is created for each base, providing logical separation within the database. This feature offers several benefits:
- Improved organization: Each base's tables are grouped in their own schema.
- Enhanced security: It's easier to manage permissions at the schema level.
- Reduced naming conflicts: Table names can be reused across different bases.

This feature is enabled by default if the user has the required permissions. To disable it, set the `NC_DISABLE_BASE_AS_PG_SCHEMA` environment variable to `true`. Note that disabling this feature may affect how your database is organized and could impact existing queries or permissions if you've been relying on the schema structure.

Example: With this feature enabled, a base named "Project A" might create its tables in a schema called "project_a" instead of the public schema.

Line range hint 100-134: LGTM! Consider adding a brief introduction to Litestream.

The new Litestream section is comprehensive and well-structured. It provides clear descriptions for all the new environment variables and includes helpful deprecation notices.

To improve clarity for users who might not be familiar with Litestream, consider adding a brief introduction at the beginning of the section. For example:

## Litestream
Litestream is a tool that provides replication and disaster recovery for SQLite databases. In NocoDB, it's used to back up the SQLite database to S3-compatible storage when `NC_DB` is set to SQLite.

> Note: Litestream is used **only** when `NC_DB` is set to SQLite. It backs up the SQLite database and stores it in S3-compatible storage.

| Variable | Mandatory | Description | If Not Set |
...

This introduction provides context for the subsequent configuration options and clarifies when Litestream is relevant to NocoDB users.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~87-~87: The official spelling of this programming framework is “Express.js”.
Context: ... allowed in the request body, based on [ExpressJS limits](https://expressjs.com/en/resour...

(NODE_JS)


87-87: Minor: Update "ExpressJS" to "Express.js" for consistency.

For consistency with official naming conventions, consider updating "ExpressJS" to "Express.js".

Apply this change:

-| `NC_REQUEST_BODY_SIZE` | No | Maximum bytes allowed in the request body, based on [ExpressJS limits](https://expressjs.com/en/resources/middleware/body-parser.html#limit).                                                         | Defaults to `1048576` (1 MB). |
+| `NC_REQUEST_BODY_SIZE` | No | Maximum bytes allowed in the request body, based on [Express.js limits](https://expressjs.com/en/resources/middleware/body-parser.html#limit).                                                         | Defaults to `1048576` (1 MB). |
🧰 Tools
🪛 LanguageTool

[uncategorized] ~87-~87: The official spelling of this programming framework is “Express.js”.
Context: ... allowed in the request body, based on [ExpressJS limits](https://expressjs.com/en/resour...

(NODE_JS)

packages/nocodb/src/helpers/initBaseBehaviour.ts (1)

68-78: Avoid modifying process.env at runtime for configuration flags.

Modifying environment variables at runtime can lead to unexpected behavior, especially if other modules read these variables at startup. It's better to use a configuration object or a dedicated configuration management solution to manage feature flags within the application.

packages/nocodb/src/services/bases.service.ts (2)

190-195: Move require statements to the top of the file

For better code organization and readability, it's a good practice to place all require or import statements at the beginning of the file.

Please move the following declarations to the top:

+ const fs = require('fs').promises;
...
+ const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);

This helps maintain consistency and makes dependencies easier to locate.


Line range hint 222-231: Avoid code duplication by refactoring shared logic

The code for setting baseBody.sources has similar structures in different conditional branches. Refactoring can improve maintainability.

Consider extracting the common parts or creating helper functions to handle the source configuration setup. This reduces repetition and potential errors in future modifications.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2411da7 and 797748c.

📒 Files selected for processing (4)
  • packages/noco-docs/docs/020.getting-started/050.self-hosted/020.environment-variables.md (1 hunks)
  • packages/nocodb/src/helpers/initBaseBehaviour.ts (2 hunks)
  • packages/nocodb/src/providers/init-meta-service.provider.ts (1 hunks)
  • packages/nocodb/src/services/bases.service.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/noco-docs/docs/020.getting-started/050.self-hosted/020.environment-variables.md

[uncategorized] ~87-~87: The official spelling of this programming framework is “Express.js”.
Context: ... allowed in the request body, based on [ExpressJS limits](https://expressjs.com/en/resour...

(NODE_JS)

🔇 Additional comments (3)
packages/nocodb/src/providers/init-meta-service.provider.ts (1)

116-118: Verify the impact of repositioning initBaseBehavior

The initBaseBehavior function call has been moved to the end of the initialization process. While this change ensures that all other components are initialized before setting up the base behavior, it's important to verify that this repositioning doesn't have any unintended consequences.

Consider the following:

  1. Does the base behavior depend on any components that were previously initialized after it?
  2. Are there any components or processes that depend on the base behavior being initialized earlier in the process?

To ensure this change doesn't introduce any issues, please run the following verification:

Please review the results of this verification to ensure that the repositioning of initBaseBehavior doesn't break any existing functionality or dependencies.

✅ Verification successful

Repositioning initBaseBehavior Verified

The movement of the initBaseBehavior function call to the end of the initialization process has been confirmed not to affect other components or dependencies within the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any dependencies on initBaseBehavior throughout the codebase

# Search for direct calls or references to initBaseBehavior
echo "Searching for direct calls or references to initBaseBehavior:"
rg "initBaseBehavior" --type ts

# Search for any code that might depend on the base behavior being set
echo "\nSearching for potential dependencies on base behavior:"
rg "getBaseBehavior|setBaseBehavior" --type ts

# Check if initBaseBehavior is exported and used elsewhere
echo "\nChecking if initBaseBehavior is exported and used elsewhere:"
rg "export.*initBaseBehavior" --type ts
rg "import.*initBaseBehavior" --type ts

Length of output: 1173

packages/noco-docs/docs/020.getting-started/050.self-hosted/020.environment-variables.md (1)

Line range hint 1-134: Overall, excellent updates to the environment variables documentation.

The changes in this file significantly improve the NocoDB environment variables documentation. The addition of the Litestream section, the new Postgres Base as Schema feature explanation, and the updates to existing variable descriptions enhance the overall clarity and completeness of the document.

The suggested improvements, if implemented, will further refine the document:

  1. Adding a link to the Postgres Base as Schema section for easier navigation.
  2. Expanding the explanation of the Postgres Base as Schema feature.
  3. Including a brief introduction to Litestream.
  4. Updating "ExpressJS" to "Express.js" for consistency.

These changes will make the documentation more user-friendly and informative for NocoDB users.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~87-~87: The official spelling of this programming framework is “Express.js”.
Context: ... allowed in the request body, based on [ExpressJS limits](https://expressjs.com/en/resour...

(NODE_JS)

packages/nocodb/src/services/bases.service.ts (1)

169-170: Ensure consistent handling of environment variables

The environment variables NC_DISABLE_BASE_AS_PG_SCHEMA and NC_MINIMAL_DBS are being compared to the string 'true'. This approach can lead to unexpected behavior if the environment variable is not set or has different casing.

Consider normalizing and parsing environment variables as booleans:

const isPgSchemaEnabled = process.env.NC_DISABLE_BASE_AS_PG_SCHEMA !== 'true';
...
if (
  dataConfig?.client === 'pg' &&
- process.env.NC_DISABLE_BASE_AS_PG_SCHEMA !== 'true'
+ isPgSchemaEnabled
) {

Similarly for NC_MINIMAL_DBS:

const isMinimalDbsEnabled = process.env.NC_MINIMAL_DBS === 'true';
...
if (
  dataConfig?.client === 'sqlite3' &&
- process.env.NC_MINIMAL_DBS === 'true'
+ isMinimalDbsEnabled
) {

This clarifies the intent and reduces the chance of errors due to string comparisons.

Also applies to: 186-187

Signed-off-by: Pranav C <pranavxc@gmail.com>
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 5, 2024
@mertmit mertmit merged commit 61b2562 into develop Oct 5, 2024
24 of 25 checks passed
@mertmit mertmit deleted the nc-refactor/new-env-for-pg-minimal-db branch October 5, 2024 22:05
@coderabbitai coderabbitai bot mentioned this pull request Nov 25, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files. 🔦 Type: Feature New functionality is requested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0