mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 02:24:20 +00:00
Redesign db models.
This commit is contained in:
parent
34b87c23a7
commit
525d53a906
@ -25,10 +25,12 @@ class Role(db.Model):
|
||||
A Role can be associated with many User rows.
|
||||
"""
|
||||
__tablename__ = 'roles'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(64), unique=True)
|
||||
default = db.Column(db.Boolean, default=False, index=True)
|
||||
name = db.Column(db.String(64), unique=True)
|
||||
permissions = db.Column(db.Integer)
|
||||
# Relationships
|
||||
users = db.relationship('User', backref='role', lazy='dynamic')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@ -101,12 +103,15 @@ class User(UserMixin, db.Model):
|
||||
Model for Users that are registered to Opaque.
|
||||
"""
|
||||
__tablename__ = 'users'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
confirmed = db.Column(db.Boolean, default=False)
|
||||
email = db.Column(db.String(64), unique=True, index=True)
|
||||
username = db.Column(db.String(64), unique=True, index=True)
|
||||
password_hash = db.Column(db.String(128))
|
||||
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
|
||||
confirmed = db.Column(db.Boolean, default=False)
|
||||
username = db.Column(db.String(64), unique=True, index=True)
|
||||
# Relationships
|
||||
jobs = db.relationship('Job', backref='job', lazy='dynamic')
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
@ -204,21 +209,33 @@ class AnonymousUser(AnonymousUserMixin):
|
||||
return False
|
||||
|
||||
|
||||
class Job():
|
||||
class Job(db.Model):
|
||||
"""
|
||||
Class to define Jobs.
|
||||
"""
|
||||
__tablename__ = 'jobs'
|
||||
# Primary key
|
||||
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
|
||||
'''
|
||||
' Requested ressources.
|
||||
' Example: {"n_cores": 2,
|
||||
' "mem_mb": 4096
|
||||
' }
|
||||
'''
|
||||
ressources = db.Column(db.String(255))
|
||||
service = db.Column(db.String(64))
|
||||
'''
|
||||
' Service specific arguments in JSON format.
|
||||
' Example: {"args": ["--keep-intermediates", "skip-binarization"],
|
||||
' "lang": "eng",
|
||||
' "version": "latest"
|
||||
' }
|
||||
'''
|
||||
service_args = db.Column(db.String(255))
|
||||
status = db.Column(db.String(8))
|
||||
title = db.Column(db.String(32))
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Job, self).__init__(**kwargs)
|
||||
@ -230,7 +247,11 @@ class Job():
|
||||
return '<Job %r>' % 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.
|
||||
'''
|
||||
' Flask-Login is told to use the application’s custom anonymous user by setting
|
||||
' its class in the login_manager.anonymous_user attribute.
|
||||
'''
|
||||
login_manager.anonymous_user = AnonymousUser
|
||||
|
||||
|
||||
@login_manager.user_loader
|
||||
|
@ -1,8 +1,8 @@
|
||||
"""Initial commit
|
||||
"""initial migration
|
||||
|
||||
Revision ID: 1d405e6a9d7b
|
||||
Revision ID: 717796966c8c
|
||||
Revises:
|
||||
Create Date: 2019-08-05 16:36:07.187004
|
||||
Create Date: 2019-08-06 11:39:51.067875
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '1d405e6a9d7b'
|
||||
revision = '717796966c8c'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
@ -20,8 +20,8 @@ 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('name', sa.String(length=64), nullable=True),
|
||||
sa.Column('permissions', sa.Integer(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
@ -29,21 +29,34 @@ def upgrade():
|
||||
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('confirmed', sa.Boolean(), nullable=True),
|
||||
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.Column('username', sa.String(length=64), 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)
|
||||
op.create_table('jobs',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('description', sa.String(length=64), nullable=True),
|
||||
sa.Column('ressources', sa.String(length=255), nullable=True),
|
||||
sa.Column('service', sa.String(length=64), nullable=True),
|
||||
sa.Column('service_args', sa.String(length=255), nullable=True),
|
||||
sa.Column('status', sa.String(length=8), nullable=True),
|
||||
sa.Column('title', sa.String(length=32), nullable=True),
|
||||
sa.Column('user_id', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('jobs')
|
||||
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')
|
Loading…
Reference in New Issue
Block a user