Skip to content

Commit

Permalink
feature db migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
tsengyushiang authored Mar 28, 2024
1 parent a4f787e commit 73e091b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions backend/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ db.session.delete(target)
db.session.commit()
```

## Flask-Migrate

- Install package `pip install Flask-Migrate cryptography`

- Setup flask app

```diff
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
+ from flask_migrate import Migrate

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'

db = SQLAlchemy(app)
+ migrate = Migrate(app, db)
```

- Create Version Control `flask db init`
- Commit schema to files `flask db migrate -m "some changelogs"`
- Apply schema of files to database `flask db upgrade`

## Docker-compose

Expand Down

0 comments on commit 73e091b

Please sign in to comment.