-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
RFC: Better migration architecture #366
Milestone
Comments
@merlinz01 thank you for sharing your ideas! A few comments/questions:
|
In answer to your questions.
# Generated by Django 5.1.3 on 2024-11-25 20:41
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="TestModel",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
("age", models.IntegerField()),
],
),
] # Generated by Django 5.1.3 on 2024-11-25 20:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("testmigrations", "0001_initial"),
]
operations = [
migrations.RenameField(
model_name="testmodel",
old_name="age",
new_name="age2",
),
] Alembic is fairly similar to what I came up with. I like the fact that it enables type-checking on the operations. """test
Revision ID: f0f068244d58
Revises: e8fa71e392c3
Create Date: 2024-11-25 16:08:05.689241
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'f0f068244d58'
down_revision: Union[str, None] = 'e8fa71e392c3'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('test_models', sa.Column('test', sa.String(length=20), nullable=False))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('test_models', 'test')
# ### end Alembic commands ### |
Dropping this link here mostly for interest's sake: https://github.com/gobuffalo/fizz/blob/main/README.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From my experience using aerich in a production system, the current migration approach leaves much to be desired.
Here are my complaints with the current architecture:
This is what I've come up with as a better approach:
I think a migration file should consist of the following items:
Benefits of this approach:
Conceptual example:
Migration pseudo-code:
The text was updated successfully, but these errors were encountered: