準備
poetry add atlas-provider-sqlalchemy # or pip install atlas-provider-sqlalchemy
poetry でinstallした場合は
PATH=$(poetry env info --path)/bin:$PATH
でatlas-provider-sqlalchemy
が使えるようにしておく
sqlalchemy管理からatlasへ
-
db/migrations
dirを作っておくmkdir -p db/migrations
-
以下のコマンドで現状のsqlalchemyでの定義をSQLに落とせる
poetry run atlas-provider-sqlalchemy --path ./db --dialect postgresql >> db/migrations/$(date -u '+%Y%m%d%H%M%S')_init.sql
db/migrations/20240907044849_init.sql
というファイルが作成される -
applyで確認
atlas migrate apply --env sqlalchemy
2回目は実行しても変更なし
atlas migrate apply --env sqlalchemy No migration files to execute
Error connected database is not clean
Error: sql/migrate: taking database snapshot: sql/migrate: connected database is not clean: found table "xxx" in connected schema