Commit f37dbd4b authored by Mathis Dedial's avatar Mathis Dedial
Browse files

Implement ORM models and setup script

parent 0109f835
......@@ -8,5 +8,7 @@ MYSQL_HOST = 'localhost'
MYSQL_DB = 'amivburger'
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{}:{}@{}/{}'.format(MYSQL_USERNAME, MYSQL_PWD, MYSQL_HOST, MYSQL_DB)
# Suppress deprecation warning
SQLALCHEMY_TRACK_MODIFICATIONS = False
LDAP_KEY = 'notarealkey'
......@@ -4,4 +4,21 @@ from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Burger(db.Model):
pass
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(length=128), unique=True, nullable=False)
description = db.Column(db.Text, unique=False, nullable=False)
nethz = db.Column(db.String(64), unique=True, nullable=False)
timestamp = db.Column(db.DateTime, unique=False, nullable=False)
# Burger components
bread = db.Column(db.Integer, unique=False, nullable=False)
patty = db.Column(db.Integer, unique=False, nullable=False)
toppings = db.Column(db.String(64), unique=False, nullable=False)
side = db.Column(db.Integer, unique=False, nullable=False)
class Vote(db.Model):
id = db.Column(db.Integer, primary_key=True)
nethz = db.Column(db.String(64), unique=False, nullable=False)
burger_id = db.Column(db.Integer, db.ForeignKey('burger.id'), nullable=False)
burger = db.relationship('Burger', backref=db.backref('votes', lazy=True))
'''Script to recreate the database schema according to models.py'''
import app
# Fix for a weird bug which occurs when using db.init_app(app)
app.db.app = app.app
# Nuke current db schema
app.db.drop_all()
# Recreate schema
app.db.create_all()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment