Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8532 +/- ##
=======================================
Coverage 87.78% 87.79%
=======================================
Files 153 153
Lines 19432 19432
Branches 2231 2231
=======================================
+ Hits 17059 17060 +1
Misses 2076 2076
+ Partials 297 296 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
👑 |
|
I need to get my hands dirty with this for a few more days to make it fully ready. |
|
Is this really something that should be on the celery side?
|
|
I will share more context here. |
we got a regression report and had to revert #8475 (comment) so thought that adding migration is the safer bet. what do you think? |
|
I think DB changes should be clearly documented in the changelog. But executing them extremely dependent on the environment. Note: This is assuming that you do not maintain your completely separate sqlalchemy environment. If you do, then migrations in celery make sense (because it's completely independent of the application's database usage). But if you defer this to the application's sqlalchemy environment, then IMHO what I mentioned in my previous comment applies. |
|
is using multi db schema migrations a feasible option? |
There was a problem hiding this comment.
Pull request overview
Adds initial Alembic scaffolding intended to support schema migrations for Celery’s SQLAlchemy database result backend.
Changes:
- Introduces an Alembic environment (
env.py) and revision script template (script.py.mako) undercelery/backends/database/migrations/. - Adds an Alembic configuration file at
celery/backends/database/alembic.ini. - Adds a minimal migrations README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| celery/backends/database/migrations/script.py.mako | Adds Alembic revision script template used for generated migrations. |
| celery/backends/database/migrations/env.py | Adds Alembic environment configuration for online/offline migrations. |
| celery/backends/database/migrations/README | Adds placeholder README for the migrations directory. |
| celery/backends/database/alembic.ini | Adds Alembic INI configuration pointing at the migrations directory. |
| @@ -0,0 +1,76 @@ | |||
| from logging.config import fileConfig | |||
|
|
|||
| from alembic import context | |||
There was a problem hiding this comment.
env.py imports alembic, but the repository’s sqlalchemy extra currently only depends on SQLAlchemy. If these migrations are meant for end users, Alembic needs to be declared as an optional dependency (e.g., in the SQLAlchemy extra or a new migrations extra), otherwise running the migration environment will fail with ModuleNotFoundError in a standard install.
| from alembic import context | |
| try: | |
| from alembic import context | |
| except ModuleNotFoundError as exc: | |
| raise ModuleNotFoundError( | |
| "Alembic is required to run the Celery database migrations. " | |
| "Please install the 'alembic' package or the appropriate optional " | |
| "dependency group for this project before invoking env.py." | |
| ) from exc |
| [alembic] | ||
| # path to migration scripts | ||
| script_location = migrations | ||
|
|
||
| # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s | ||
| # Uncomment the line below if you want the files to be prepended with date and time | ||
| # see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file | ||
| # for all available tokens | ||
| # file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s | ||
|
|
||
| # sys.path path, will be prepended to sys.path if present. | ||
| # defaults to the current working directory. | ||
| prepend_sys_path = . | ||
|
|
There was a problem hiding this comment.
script_location = migrations is interpreted relative to the current working directory unless %(here)s is used, which makes alembic -c celery/backends/database/alembic.ini ... sensitive to where it’s invoked from. Consider using script_location = %(here)s/migrations (and similarly anchoring prepend_sys_path) so the config works reliably from any CWD.
| """${message} | ||
|
|
||
| Revision ID: ${up_revision} | ||
| Revises: ${down_revision | comma,n} | ||
| Create Date: ${create_date} | ||
|
|
||
| """ | ||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| ${imports if imports else ""} |
There was a problem hiding this comment.
This PR adds non-Python migration assets (alembic.ini, migrations/script.py.mako, migrations/README). In this repo, non-.py package files are only shipped when explicitly included (e.g., via MANIFEST.in/package data). As-is, these files are likely to be missing from sdists/wheels, making migrations unusable for installed users. Please ensure these files are included in the distribution packaging.
| @@ -0,0 +1 @@ | |||
| Generic single-database configuration. No newline at end of file | |||
There was a problem hiding this comment.
The migrations directory doesn’t include a versions/ subdirectory. Alembic typically expects migrations/versions to exist when generating/applying revisions; without it, alembic revision may fail or have nowhere to place new revisions. If this is meant to be a working init, add migrations/versions/ (with an empty .gitkeep if needed) or document the required setup steps here.
| Generic single-database configuration. | |
| Generic single-database Alembic configuration. | |
| This directory is intended to host Alembic migrations for the database backend. | |
| Alembic expects a ``versions/`` subdirectory under the migrations root where | |
| revision files are stored. For this path, that means: | |
| celery/backends/database/migrations/versions/ | |
| Before running ``alembic revision`` or ``alembic upgrade`` against this | |
| environment, make sure the ``versions/`` directory exists. In a typical setup | |
| you would either: | |
| * Create the directory manually, optionally adding an empty placeholder file | |
| (for example ``.gitkeep``) so it can be tracked in version control, or | |
| * Use your Alembic configuration to initialize the environment and let it | |
| create and manage revision files inside ``migrations/versions/``. | |
| Adjust these steps as needed to match your project's Alembic configuration. |
| # add your model's MetaData object here | ||
| # for 'autogenerate' support | ||
| # from myapp import mymodel | ||
| # target_metadata = mymodel.Base.metadata | ||
| target_metadata = None | ||
|
|
There was a problem hiding this comment.
target_metadata is set to None, so Alembic autogenerate won’t see Celery’s SQLAlchemy models and alembic revision --autogenerate will produce empty migrations. If the intent is to generate migrations for the result backend tables, set target_metadata to the declarative base metadata (and ensure the model modules are imported so tables are registered).
using alembic