Add Job model.

This commit is contained in:
Stephan Porada 2019-08-05 16:45:38 +02:00
parent 8763e0f4db
commit 94dcaa55a3
3 changed files with 80 additions and 2 deletions

View File

@ -204,6 +204,32 @@ class AnonymousUser(AnonymousUserMixin):
return False 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 '<Job %r>' % self.title
login_manager.anonymous_user = AnonymousUser # Flask-Login is told to use the applications custom anonymous user by setting its class in the login_manager.anonymous_user attribute. login_manager.anonymous_user = AnonymousUser # Flask-Login is told to use the applications custom anonymous user by setting its class in the login_manager.anonymous_user attribute.

View File

@ -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 ###

View File

@ -1,5 +1,5 @@
from app import create_app, db 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 from flask_migrate import Migrate
import os import os
@ -10,7 +10,7 @@ migrate = Migrate(app, db)
@app.shell_context_processor @app.shell_context_processor
def make_shell_context(): 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() @app.cli.command()