From 98adec9ead35f0bd55febf372895789ec338267b Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 4 Mar 2017 11:29:44 -0800 Subject: [PATCH] initial database model --- .gitignore | 2 ++ manage.py | 17 +++++++++++++++++ models.py | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 manage.py create mode 100644 models.py diff --git a/.gitignore b/.gitignore index 7f7cccc..dd0fdcc 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,5 @@ docs/_build/ # PyBuilder target/ +# my other cruft +*.yaml \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..12a3128 --- /dev/null +++ b/manage.py @@ -0,0 +1,17 @@ +import yaml +from appservice import app +from models import * +from flask_script import Manager +from flask_migrate import Migrate, MigrateCommand + +migrate = Migrate(app, db) + +manager = Manager(app) +manager.add_command('db', MigrateCommand) + +if __name__ == '__main__': + with open("config.yaml", "rb") as config_file: + config = yaml.load(config_file) + + app.config['SQLALCHEMY_DATABASE_URI'] = config['SQLALCHEMY_DATABASE_URI'] + manager.run() diff --git a/models.py b/models.py new file mode 100644 index 0000000..3121343 --- /dev/null +++ b/models.py @@ -0,0 +1,19 @@ +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() + +class MatrixUser(db.Model): + id = db.Column(db.Integer, primary_key=True) + matrix_id = db.Column(db.Text, unique=True) + room_id = db.Column(db.Text) + pnut_id = db.Column(db.Text, unique=True) + pnut_token = db.Column(db.Text) + + def __init__(self, matrix_id, room_id, pnut_id, pnut_token): + self.matrix_id = matrix_id + self.room_id = room_id + self.pnut_id = pnut_id + self.pnut_token = pnut_token + + def __repr__(self): + return '