0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

atlas + sqlalchemy

Posted at

準備

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へ

  1. db/migrations dirを作っておく

    mkdir -p db/migrations
    
  2. 以下のコマンドで現状の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というファイルが作成される

  3. 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

Ref

  1. https://atlasgo.io/guides/orms/sqlalchemy
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?