tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
804 stars 90 forks source link

Support altering columns in SQLite migrations by RENAME-ADD-UPDATE-DROP #333

Open Rongronggg9 opened 2 months ago

Rongronggg9 commented 2 months ago

Since 7bcf9b2fedaca4b0a7948b06daf2ff16f3fda2e3, dropping columns in SQLite migrations is possible. We may further support altering columns in SQLite by:

ALTER TABLE "foo" RENAME COLUMN "bar" TO "bar_random_string";
ALTER TABLE "foo" ADD "bar" NEW_TYPE NOT NULL  DEFAULT "baz" /* comment */;
-- Do not CAST(x as JSON): https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/2011
UPDATE "foo" SET "bar" = CAST("bar_random_string" as NEW_TYPE);
ALTER TABLE "foo" DROP COLUMN "bar_random_string";
UpstreamData commented 2 weeks ago

+1. Would love to see this, mainly for migrating fields to allow null.