Added SQLAlchemy

This commit is contained in:
Pünkösd Marcell 2021-04-18 15:58:13 +02:00
parent bee6ccf09c
commit 998658c148
6 changed files with 38 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask
from model import db
from utils import register_all_error_handlers, k8s
# import views
@ -24,10 +25,14 @@ if Config.SENTRY_DSN:
app = Flask(__name__)
app.config.from_object(Config)
# init stuffs
k8s.init_app(app)
register_all_error_handlers(app)
@app.before_first_request
def init_db():
db.create_all()
# register views
for view in [JobView]:
view.register(app, trailing_slash=False)

View File

@ -7,6 +7,9 @@ Configuration
class Config:
SQLALCHEMY_DATABASE_URI = os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite://")
SQLALCHEMY_TRACK_MODIFICATIONS = False
SECRET_KEY = os.environ.get("SECRET_KEY", os.urandom(12))
SENTRY_DSN = os.environ.get("SENTRY_DSN")

View File

@ -0,0 +1 @@
from .db import db

View File

@ -0,0 +1,3 @@
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()

View File

@ -7,10 +7,29 @@ import uuid
class ControlConfigurationSchema(Schema):
pod_id = fields.UUID(required=False, missing=uuid.uuid4)
robot_address = fields.Str(required=True)
program_url = fields.Str(required=True)
class Meta:
unknown = RAISE
class ControlStatusConfigurationSchema(Schema):
cluster_ip = fields.IP(required=False, dump_only=True)
running = fields.Boolean(required=False, dump_only=True)
class Meta:
unknown = RAISE
class ControllerSchema(Schema):
pod_id = fields.UUID(required=False, missing=uuid.uuid4)
configuration = fields.Nested(ControlConfigurationSchema, many=False, required=True)
status = fields.Nested(ControlStatusConfigurationSchema, required=False, dump_only=True)
class Meta:
unknown = RAISE
class JobSchema(Schema):
id = fields.UUID(required=False, missing=uuid.uuid4)

View File

@ -5,4 +5,8 @@ Flask
marshmallow
Flask-Classful
sentry-sdk
kubernetes
kubernetes
sqlalchemy
Flask-SQLAlchemy
psycopg2
mysqlclient