Skip to content

Commit 807d41e

Browse files
authored
Internally Managed Migrations (#438)
This PR replaces Alembic-based system database migrations with a simpler internal system. Migrations are now an array of SQL strings in `_migration.py`. There is a new table `dbos.dbos_migrations` in the system database that keeps track of which has run. When initializing the system database, it looks up that table to see which migrations have already run and then runs the rest. This new scheme is fully backwards-compatible with the old (Alembic-based) migrations, as this PR also adds a final Alembic migration that creates the `dbos.dbos_migrations` table and inserts an initial version into it. We will move all DBOS languages (TypeScript, Go, Java) to this system and use exactly the same migrations for each to ensure system database compatibility across languages.
1 parent 231a336 commit 807d41e

23 files changed

+333
-100
lines changed

DEVELOPING.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,6 @@ on the changes in the project since this was written):
8686
Success: no issues found in 64 source files
8787
```
8888

89-
We use alembic to manage system table schema migrations.
90-
To generate a new migration, run:
91-
92-
```
93-
pdm run alembic revision -m "<new migration name>"
94-
```
95-
96-
This command will add a new file under the `dbos/migrations/versions/` folder.
97-
For more information,
98-
read [alembic tutorial](https://alembic.sqlalchemy.org/en/latest/tutorial.html).
99-
10089
### Creating a Release
10190

10291
To cut a new release, run:

alembic.ini

Lines changed: 0 additions & 8 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""dbos_migrations
2+
3+
Revision ID: 471b60d64126
4+
Revises: 01ce9f07bd10
5+
Create Date: 2025-08-21 14:22:31.455266
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
import sqlalchemy as sa
12+
from alembic import op
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = "471b60d64126"
16+
down_revision: Union[str, None] = "01ce9f07bd10"
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
# Create dbos_migrations table
23+
op.create_table(
24+
"dbos_migrations",
25+
sa.Column("version", sa.BigInteger(), nullable=False),
26+
sa.PrimaryKeyConstraint("version"),
27+
schema="dbos",
28+
)
29+
30+
# Insert initial version 1
31+
op.execute("INSERT INTO dbos.dbos_migrations (version) VALUES (1)")
32+
33+
34+
def downgrade() -> None:
35+
op.drop_table("dbos_migrations", schema="dbos")

0 commit comments

Comments
 (0)