-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/implement multi database support #42
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f6ea793
fix(test): fix testing issue
nahuel11500 4ed8d7b
fix(test-E2E): deactivate them
nahuel11500 28e7b21
feat(multi-database): add support for multi-database migrations and c…
nahuel11500 e934d0f
chore(format): ruff format
nahuel11500 a127f5a
feat(dependencies): add toml file
nahuel11500 6f68e70
feat(test): add more tests
nahuel11500 3fe254d
docs(changelog): update changelog
nahuel11500 bcc2076
fix(deps): fix toml file
nahuel11500 00c57b1
feat(deps): implement ruff
nahuel11500 aae3986
chore(deps): remove old lib building files
nahuel11500 47adf56
feat(test): add ClickHouse and PostgreSQL migration configurations an…
nahuel11500 747710d
fix(migration): multi-db support to AlembicMigrationHelper on the ale…
nahuel11500 d44c422
fix(review): fix based on review
nahuel11500 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 5.0.0 | ||
| 6.0.0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| # Multi-Database Migration Support | ||
|
|
||
| Chartreuse now supports managing migrations for multiple databases simultaneously. This feature allows you to define multiple database configurations and run migrations across all of them. | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Single Database (Legacy) | ||
| The original single-database configuration using environment variables is still supported for backward compatibility. | ||
|
|
||
| ### Multiple Databases (New) | ||
| To use multiple databases, create a YAML configuration file and set the `CHARTREUSE_MULTI_CONFIG_PATH` environment variable to point to it. | ||
|
|
||
| #### Configuration File Format | ||
|
|
||
| ```yaml | ||
| databases: | ||
| # Main application database | ||
| main: | ||
| alembic_directory_path: /app/alembic/main | ||
| alembic_config_file_path: alembic.ini | ||
| dialect: postgresql | ||
| user: app_user | ||
| password: app_password | ||
| host: postgres-main | ||
| port: 5432 | ||
| database: app_main | ||
| allow_migration_for_empty_database: true | ||
| additional_parameters: "" | ||
|
|
||
| # Analytics database | ||
| analytics: | ||
| alembic_directory_path: /app/alembic/analytics | ||
| alembic_config_file_path: alembic.ini | ||
| dialect: postgresql | ||
| user: analytics_user | ||
| password: analytics_password | ||
| host: postgres-analytics | ||
| port: 5432 | ||
| database: analytics | ||
| allow_migration_for_empty_database: false | ||
| additional_parameters: "" | ||
| ``` | ||
|
|
||
| #### Configuration Fields | ||
|
|
||
| **Required fields:** | ||
| - Database name (used as key in the YAML) | ||
| - `alembic_directory_path`: Path to the Alembic directory for this database | ||
| - `alembic_config_file_path`: Alembic configuration file name | ||
|
|
||
| **Database connection components (all required):** | ||
| - `dialect`: Database dialect (e.g., postgresql, mysql, sqlite) | ||
| - `user`: Database username | ||
| - `password`: Database password | ||
| - `host`: Database host | ||
| - `port`: Database port | ||
| - `database`: Database name | ||
|
|
||
| **Optional fields:** | ||
| - `allow_migration_for_empty_database`: Whether to allow migrations on empty databases (default: false) | ||
| - `additional_parameters`: Additional parameters to pass to Alembic commands (default: "") | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| For multi-database mode: | ||
| - `CHARTREUSE_MULTI_CONFIG_PATH`: Path to the YAML configuration file | ||
| - `CHARTREUSE_ENABLE_STOP_PODS`: Whether to stop pods during migration (optional, default: true) | ||
| - `CHARTREUSE_RELEASE_NAME`: Kubernetes release name | ||
| - `CHARTREUSE_UPGRADE_BEFORE_DEPLOYMENT`: Whether to upgrade before deployment (optional, default: false) | ||
| - `HELM_IS_INSTALL`: Whether this is a Helm install operation (optional, default: false) | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Setting up the environment | ||
| ```bash | ||
| export CHARTREUSE_MULTI_CONFIG_PATH="/path/to/multi-database-config.yaml" | ||
| export CHARTREUSE_RELEASE_NAME="my-app" | ||
| export CHARTREUSE_ENABLE_STOP_PODS="true" | ||
| ``` | ||
|
|
||
| ### Directory Structure Example | ||
| ``` | ||
| /app/ | ||
| ├── alembic/ | ||
| │ ├── main/ | ||
| │ │ ├── alembic.ini | ||
| │ │ ├── env.py | ||
| │ │ └── versions/ | ||
| │ └── analytics/ | ||
| │ ├── alembic.ini | ||
| │ ├── env.py | ||
| │ └── versions/ | ||
| └── multi-database-config.yaml | ||
| ``` | ||
|
|
||
| ### Configuration Validation | ||
| You can validate your configuration file before deployment: | ||
|
|
||
| ```bash | ||
| python3 scripts/validate_config.py /path/to/multi-database-config.yaml | ||
| ``` | ||
|
|
||
| ## Migration Behavior | ||
|
|
||
| When using multi-database configuration: | ||
|
|
||
| 1. **Initialization**: All databases are initialized with their respective Alembic configurations | ||
| 2. **Migration Check**: Each database is checked individually for pending migrations | ||
| 3. **Migration Execution**: Only databases that need migration will be upgraded | ||
| 4. **Error Handling**: If any database migration fails, the entire process fails | ||
| 5. **Logging**: Detailed logs show which databases are being processed | ||
|
|
||
| ## Backward Compatibility | ||
|
|
||
| The original single-database configuration using environment variables continues to work unchanged. The multi-database feature is only activated when `CHARTREUSE_MULTI_CONFIG_PATH` is set. | ||
|
|
||
| ## Example Integration | ||
|
|
||
| In your Helm chart, you can use a ConfigMap to store the multi-database configuration: | ||
|
|
||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: chartreuse-config | ||
| data: | ||
| multi-database-config.yaml: | | ||
| databases: | ||
| main: | ||
| alembic_directory_path: /app/alembic/main | ||
| alembic_config_file_path: alembic.ini | ||
| dialect: postgresql | ||
| user: {{ .Values.database.main.user }} | ||
| password: {{ .Values.database.main.password }} | ||
| host: {{ .Values.database.main.host }} | ||
| port: {{ .Values.database.main.port }} | ||
| database: {{ .Values.database.main.name }} | ||
| allow_migration_for_empty_database: true | ||
| additional_parameters: "" | ||
| analytics: | ||
| alembic_directory_path: /app/alembic/analytics | ||
| alembic_config_file_path: alembic.ini | ||
| dialect: postgresql | ||
| user: {{ .Values.database.analytics.user }} | ||
| password: {{ .Values.database.analytics.password }} | ||
| host: {{ .Values.database.analytics.host }} | ||
| port: {{ .Values.database.analytics.port }} | ||
| database: {{ .Values.database.analytics.name }} | ||
| allow_migration_for_empty_database: false | ||
| additional_parameters: "" | ||
| ``` | ||
|
|
||
| Then mount it in your migration job: | ||
|
|
||
| ```yaml | ||
| env: | ||
| - name: CHARTREUSE_MULTI_CONFIG_PATH | ||
| value: "/config/multi-database-config.yaml" | ||
| volumeMounts: | ||
| - name: config | ||
| mountPath: /config | ||
| volumes: | ||
| - name: config | ||
| configMap: | ||
| name: chartreuse-config | ||
| ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| # Only used for e2e tests. Do not use in production. | ||
|
|
||
| # For Wiremind use only since it uses our private package wiremind-python | ||
| FROM python:3.12 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install uv | ||
| RUN pip install uv | ||
|
|
||
| COPY requirements.txt requirements.txt | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
| RUN uv pip install --system --no-cache -r requirements.txt | ||
|
|
||
| COPY . . | ||
| RUN pip install -e . | ||
| COPY example/alembic alembic | ||
| RUN uv pip install --system -e . | ||
| RUN uv pip install --system wiremind-python | ||
| COPY alembic alembic |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Only used for e2e tests. Do not use in production. | ||
| # For Wiremind use only since it uses our private package wiremind-python | ||
|
|
||
| FROM python:3.12 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install uv | ||
| RUN pip install uv | ||
|
|
||
| # Install dependencies if requirements.txt exists | ||
| COPY pyproject.toml . | ||
| COPY VERSION . | ||
| COPY README.md . | ||
| COPY requirements.txt* ./ | ||
| COPY src/ src/ | ||
| COPY example/alembic/ alembic/ | ||
|
|
||
| RUN if [ -f requirements.txt ]; then uv pip install --system --no-cache -r requirements.txt; fi | ||
|
|
||
| # Install the package itself | ||
| RUN uv pip install --system -e . | ||
|
|
||
| # Install wiremind-python with authentication using build secrets | ||
| # The secret will be mounted at build time but not stored in the image | ||
| RUN --mount=type=secret,id=uv_config,target=/root/.config/uv/uv.toml \ | ||
| mkdir -p /root/.config/uv && \ | ||
| uv pip install --system wiremind-python cyrillic clickhouse-sqlalchemy |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.