From 94dcaa55a3c15bc99434bd1197d0553b9f05be4a Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Mon, 5 Aug 2019 16:45:38 +0200 Subject: [PATCH] Add Job model. --- app/models.py | 26 ++++++++++ .../versions/1d405e6a9d7b_initial_commit.py | 52 +++++++++++++++++++ opaque.py | 4 +- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 migrations/versions/1d405e6a9d7b_initial_commit.py diff --git a/app/models.py b/app/models.py index 6d6474c0..e053387a 100644 --- a/app/models.py +++ b/app/models.py @@ -204,6 +204,32 @@ class AnonymousUser(AnonymousUserMixin): return False +class Job(): + """ + Class to define Jobs. + """ + __tablename__ = 'jobs' + id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String(32)) + description = db.Column(db.String(64)) + service = db.Column(db.String(64), index=True) + user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True) + requested_cpus = db.Column(db.Integer, default=None) + requested_memory = db.Column(db.Integer, default=None) + service_args = db.Column(db.String(255)) # JSON string representation {'lang': new_ocr_job_form.language.data, 'version': new_ocr_job_form.version. } + status = db.Column(db.String(64)) + cmd_args = db.Column(db.String(255)) # For extra cmd arguments + + def __init__(self, **kwargs): + super(Job, self).__init__(**kwargs) + + def __repr__(self): + """ + String representation of the Job. For human readability. + """ + return '' % self.title + + login_manager.anonymous_user = AnonymousUser # Flask-Login is told to use the application’s custom anonymous user by setting its class in the login_manager.anonymous_user attribute. diff --git a/migrations/versions/1d405e6a9d7b_initial_commit.py b/migrations/versions/1d405e6a9d7b_initial_commit.py new file mode 100644 index 00000000..515c3de0 --- /dev/null +++ b/migrations/versions/1d405e6a9d7b_initial_commit.py @@ -0,0 +1,52 @@ +"""Initial commit + +Revision ID: 1d405e6a9d7b +Revises: +Create Date: 2019-08-05 16:36:07.187004 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '1d405e6a9d7b' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('roles', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=64), nullable=True), + sa.Column('default', sa.Boolean(), nullable=True), + sa.Column('permissions', sa.Integer(), nullable=True), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) + op.create_index(op.f('ix_roles_default'), 'roles', ['default'], unique=False) + op.create_table('users', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('email', sa.String(length=64), nullable=True), + sa.Column('username', sa.String(length=64), nullable=True), + sa.Column('password_hash', sa.String(length=128), nullable=True), + sa.Column('role_id', sa.Integer(), nullable=True), + sa.Column('confirmed', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True) + op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_users_username'), table_name='users') + op.drop_index(op.f('ix_users_email'), table_name='users') + op.drop_table('users') + op.drop_index(op.f('ix_roles_default'), table_name='roles') + op.drop_table('roles') + # ### end Alembic commands ### diff --git a/opaque.py b/opaque.py index c06c59d3..25e69257 100644 --- a/opaque.py +++ b/opaque.py @@ -1,5 +1,5 @@ from app import create_app, db -from app.models import User, Role, Permission +from app.models import User, Role, Permission, Job from flask_migrate import Migrate import os @@ -10,7 +10,7 @@ migrate = Migrate(app, db) @app.shell_context_processor def make_shell_context(): - return dict(db=db, User=User, Role=Role, Permission=Permission) + return dict(db=db, User=User, Role=Role, Permission=Permission, Job=Job) @app.cli.command()