feat(backend): add sanitized schema generation for analytics views#5251
Merged
feat(backend): add sanitized schema generation for analytics views#5251
Conversation
## Context Adds the ability to generate a sanitized PostgreSQL schema (`infisical-sanitized`) containing read-only views of database tables. This enables external analytics tools to query data without accessing the main schema directly. **How it works:** - Controlled by `GENERATE_SANITIZED_SCHEMA` environment variable - Drops the existing sanitized schema before migrations run (to avoid blocking `ALTER TABLE` operations) - Recreates the schema with views after migrations complete - Uses advisory locks to ensure only one container executes schema generation in multi-replica deployments - Fails silently without blocking application startup, logging errors with `SANITIZED_SCHEMA_ERROR` identifier ## Screenshots N/A - Backend only change ## Steps to verify the change 1. Set `GENERATE_SANITIZED_SCHEMA=true` in .env 2. Connect to PostgreSQL and verify the `infisical-sanitized` schema exists with views ## Type - [ ] Fix - [x] Feature - [ ] Improvement - [ ] Breaking - [ ] Docs - [ ] Chore ## Checklist - [x] Title follows the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) format: `type(scope): short description` (scope is optional, e.g., `fix: prevent crash on sync` or `fix(api): handle null response`). - [ ] Tested locally - [ ] Updated docs (if needed) - [x] Read the [contributing guide](https://infisical.com/docs/contributing/getting-started/overview)
Collaborator
Author
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Contributor
Greptile OverviewGreptile SummaryAdds the ability to generate a sanitized PostgreSQL schema ( Key changes:
Issues found:
Confidence Score: 3/5
Important Files Changed
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Adds the ability to generate a sanitized PostgreSQL schema (
infisical-sanitized) containing read-only views of database tables. This enables external analytics tools to query data without accessing the main schema directly.How it works:
GENERATE_SANITIZED_SCHEMAenvironment variableALTER TABLEoperations)SANITIZED_SCHEMA_ERRORidentifierScreenshots
N/A - Backend only change
Steps to verify the change
GENERATE_SANITIZED_SCHEMA=truein .envinfisical-sanitizedschema exists with viewsType
Checklist
type(scope): short description(scope is optional, e.g.,fix: prevent crash on syncorfix(api): handle null response).