From b7126374c752a14a2ae656a46563543032350312 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Mon, 18 Oct 2021 18:37:24 -0300 Subject: [PATCH] Usar flask_migrate --- README.md | 19 +++++++++++++++---- api/app.py | 2 ++ create_db.py | 3 --- 3 files changed, 17 insertions(+), 7 deletions(-) delete mode 100755 create_db.py diff --git a/README.md b/README.md index 557e8d7..7e80cc6 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,22 @@ # Rodando As dependências (Python) do projeto estão listadas em `requirements.txt`. -Crie o banco de dados: -```python3 create_db.py``` +Vá para o diretório `api`: +``` +cd api +``` -Depois, no diretório `api`: -```flask run``` +Crie o banco de dados: +``` +flask db init +flask db migrate +flask db upgrade +``` + +Inicie o servidor de desenvolvimento: +``` +flask run +``` Por padrão o servidor tem sua interface em `http://localhost:5000`. diff --git a/api/app.py b/api/app.py index 3213595..b8fb2e2 100755 --- a/api/app.py +++ b/api/app.py @@ -2,11 +2,13 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_marshmallow import Marshmallow +from flask_migrate import Migrate app = Flask(__name__) app.config.from_object('api.config') db = SQLAlchemy(app) ma = Marshmallow(app) +Migrate(app, db) import api.models.trainer import api.models.pokemon_owned diff --git a/create_db.py b/create_db.py deleted file mode 100755 index d24f94e..0000000 --- a/create_db.py +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/python3 -from api.app import db -db.create_all()