forked from tiagoluizrs/livro_flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.py
52 lines (44 loc) · 2.25 KB
/
migrate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from config import app_active, app_config
config = app_config[app_active]
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
class Role(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(40), unique=True, nullable=False)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(40), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(200), nullable=False)
date_created = db.Column(db.DateTime(6), default=db.func.current_timestamp(), nullable=False)
last_update = db.Column(db.DateTime(6), onupdate=db.func.current_timestamp(), nullable=True)
recovery_code = db.Column(db.String(200), nullable=True)
active = db.Column(db.Boolean(), default=1, nullable=True)
role = db.Column(db.Integer, db.ForeignKey(Role.id), nullable=False)
class Category(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20), unique=True, nullable=False)
description = db.Column(db.Text(), nullable=True)
class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20), unique=True, nullable=False)
description = db.Column(db.Text(), nullable=False)
qtd = db.Column(db.Integer, nullable=True, default=0)
image = db.Column(db.Text(), nullable=True)
price = db.Column(db.Numeric(10,2), nullable=False)
date_created = db.Column(db.DateTime(6), default=db.func.current_timestamp(), nullable=False)
last_update = db.Column(db.DateTime(6), onupdate=db.func.current_timestamp(), nullable=True)
status = db.Column(db.Integer, default=1, nullable=True)
user_created = db.Column(db.Integer, db.ForeignKey(User.id), nullable=False)
category = db.Column(db.Integer, db.ForeignKey(Category.id), nullable=False)
if __name__ == '__main__':
manager.run()