Skip to content

Use alembic instead of sqlalchemy-migrate for migrations#3674

Open
jcristau wants to merge 1 commit intomozilla-releng:mainfrom
jcristau:alembic
Open

Use alembic instead of sqlalchemy-migrate for migrations#3674
jcristau wants to merge 1 commit intomozilla-releng:mainfrom
jcristau:alembic

Conversation

@jcristau
Copy link
Contributor

@jcristau jcristau commented Feb 17, 2026

Existing databases are assumed to have all existing migrations applied.
On upgrade, we'll detect the presence of the migrate_version table, and set the alembic version to the initial/current schema, 0001.

Also remove the setuptools pin since it was there for sqlalchemy-migrate's benefit.

@jcristau jcristau force-pushed the alembic branch 2 times, most recently from 034a867 to a245c1d Compare February 17, 2026 15:24
Existing databases are assumed to have all existing migrations applied.
On upgrade, we'll detect the presence of the `migrate_version` table,
and set the alembic version to the initial/current schema, `0001`.

Also remove the setuptools pin since it was there for
sqlalchemy-migrate's benefit.
@jcristau jcristau marked this pull request as ready for review February 25, 2026 14:32
@jcristau jcristau requested a review from a team as a code owner February 25, 2026 14:32
Copy link
Contributor

@bhearsum bhearsum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you been able to run uv run alembic without issue locally? Any invocation I've tried ends up with an error. For example:

~/repos/balrog ❯ uv run alembic check
      Built balrog @ file:///home/bhearsum/repos/balrog
Uninstalled 1 package in 0.77ms
Installed 1 package in 1ms
Traceback (most recent call last):
  File "/home/bhearsum/repos/balrog/.venv/bin/alembic", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/bhearsum/repos/balrog/.venv/lib/python3.13/site-packages/alembic/config.py", line 1047, in main
    CommandLine(prog=prog).main(argv=argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/bhearsum/repos/balrog/.venv/lib/python3.13/site-packages/alembic/config.py", line 1037, in main
    self.run_cmd(cfg, options)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/home/bhearsum/repos/balrog/.venv/lib/python3.13/site-packages/alembic/config.py", line 971, in run_cmd
    fn(
    ~~^
        config,
        ^^^^^^^
        *[getattr(options, k, None) for k in positional],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        **{k: getattr(options, k, None) for k in kwarg},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/bhearsum/repos/balrog/.venv/lib/python3.13/site-packages/alembic/command.py", line 363, in check
    script_directory.run_env()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/bhearsum/repos/balrog/.venv/lib/python3.13/site-packages/alembic/script/base.py", line 545, in run_env
    util.load_python_file(self.dir, "env.py")
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/home/bhearsum/repos/balrog/.venv/lib/python3.13/site-packages/alembic/util/pyfiles.py", line 116, in load_python_file
    module = load_module_py(module_id, path)
  File "/home/bhearsum/repos/balrog/.venv/lib/python3.13/site-packages/alembic/util/pyfiles.py", line 136, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 1023, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/bhearsum/repos/balrog/src/auslib/alembic/env.py", line 21, in <module>
    fileConfig(config.config_file_name, disable_existing_loggers=False)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/logging/config.py", line 66, in fileConfig
    raise FileNotFoundError(f"{fname} doesn't exist")
FileNotFoundError: alembic.ini doesn't exist

Should this work? Or are we content to only interact with it through the API calls in db.py?

@jcristau
Copy link
Contributor Author

jcristau commented Mar 3, 2026

With this in alembic.ini:

[alembic]
script_location = src/auslib/alembic
sqlalchemy.url = mysql://balrogadmin:balrogadmin@127.0.0.1/balrog

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARNING
handlers = console
qualname =

[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

I can run alembic check against the database set up by the docker-compose config (the logging config above is from the template, I only touched the alembic section).

@bhearsum
Copy link
Contributor

bhearsum commented Mar 3, 2026

I guess my question was more whether or not this should work out of box.

@jcristau
Copy link
Contributor Author

jcristau commented Mar 3, 2026

Fair. I don't know TBH...

@bhearsum
Copy link
Contributor

bhearsum commented Mar 3, 2026

I guess seeing as we don't have that CLI for migration already, we probably don't need it for alembic, at least initially.

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.

2 participants