From 0b656d3cf171b420ad8b301ac16bfbe4da6ebcca Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 26 Oct 2022 10:34:07 +0200 Subject: [PATCH] Add parallel fs changes to migration scripts and cleanup --- migrations/versions/116b4ab3ef9c_.py | 23 +-- migrations/versions/260b57d5f4e7_.py | 8 +- migrations/versions/2c4e27331ccb_.py | 9 +- migrations/versions/31dd42e5ea6f_.py | 58 +++--- migrations/versions/63b2cc26a01f_.py | 37 +--- migrations/versions/9e8d7d15d950_.py | 265 +++++++++++++++------------ migrations/versions/a3b727e3ff71_.py | 19 +- migrations/versions/f9070ff1fa4a_.py | 14 +- 8 files changed, 223 insertions(+), 210 deletions(-) diff --git a/migrations/versions/116b4ab3ef9c_.py b/migrations/versions/116b4ab3ef9c_.py index 5bc75946..77a7d9b7 100644 --- a/migrations/versions/116b4ab3ef9c_.py +++ b/migrations/versions/116b4ab3ef9c_.py @@ -17,25 +17,22 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('tokens', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('access_token', sa.String(length=64), nullable=True), - sa.Column('access_expiration', sa.DateTime(), nullable=True), - sa.Column('refresh_token', sa.String(length=64), nullable=True), - sa.Column('refresh_expiration', sa.DateTime(), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + 'tokens', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('access_token', sa.String(length=64), nullable=True), + sa.Column('access_expiration', sa.DateTime(), nullable=True), + sa.Column('refresh_token', sa.String(length=64), nullable=True), + sa.Column('refresh_expiration', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_tokens_access_token'), 'tokens', ['access_token'], unique=False) op.create_index(op.f('ix_tokens_refresh_token'), 'tokens', ['refresh_token'], unique=False) - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f('ix_tokens_refresh_token'), table_name='tokens') op.drop_index(op.f('ix_tokens_access_token'), table_name='tokens') op.drop_table('tokens') - # ### end Alembic commands ### diff --git a/migrations/versions/260b57d5f4e7_.py b/migrations/versions/260b57d5f4e7_.py index 8f5fd95b..8c9cfda6 100644 --- a/migrations/versions/260b57d5f4e7_.py +++ b/migrations/versions/260b57d5f4e7_.py @@ -17,12 +17,10 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.drop_column('transkribus_htr_models', 'transkribus_name') - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('transkribus_htr_models', sa.Column('transkribus_name', sa.VARCHAR(length=64), autoincrement=False, nullable=True)) - # ### end Alembic commands ### + op.add_column('transkribus_htr_models', + sa.Column('transkribus_name', sa.String(length=64), autoincrement=False, nullable=True) + ) diff --git a/migrations/versions/2c4e27331ccb_.py b/migrations/versions/2c4e27331ccb_.py index 302c6670..ea8aa9e1 100644 --- a/migrations/versions/2c4e27331ccb_.py +++ b/migrations/versions/2c4e27331ccb_.py @@ -17,13 +17,12 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('corpora', sa.Column('is_public', sa.Boolean(), nullable=True)) + op.add_column( + 'corpora', + sa.Column('is_public', sa.Boolean(), nullable=True) + ) op.execute('UPDATE corpora SET is_public = false;') - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.drop_column('corpora', 'is_public') - # ### end Alembic commands ### diff --git a/migrations/versions/31dd42e5ea6f_.py b/migrations/versions/31dd42e5ea6f_.py index a92ada9c..b4824c49 100644 --- a/migrations/versions/31dd42e5ea6f_.py +++ b/migrations/versions/31dd42e5ea6f_.py @@ -20,34 +20,44 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### for user in User.query.all(): - os.mkdir(os.path.join(user.path, 'spacy_nlp_pipeline_models')) - op.create_table('spacy_nlp_pipeline_models', - sa.Column('creation_date', sa.DateTime(), nullable=True), - sa.Column('filename', sa.String(length=255), nullable=True), - sa.Column('last_edited_date', sa.DateTime(), nullable=True), - sa.Column('mimetype', sa.String(length=255), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('title', sa.String(length=64), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('version', sa.String(length=16), nullable=True), - sa.Column('compatible_service_versions', sa.String(length=255), nullable=True), - sa.Column('publisher', sa.String(length=128), nullable=True), - sa.Column('publisher_url', sa.String(length=512), nullable=True), - sa.Column('publishing_url', sa.String(length=512), nullable=True), - sa.Column('publishing_year', sa.Integer(), nullable=True), - sa.Column('shared', sa.Boolean(), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') + spacy_nlp_pipeline_models_dir = os.path.join(user.path, 'spacy_nlp_pipeline_models') + if os.path.exists(spacy_nlp_pipeline_models_dir): + if not os.path.isdir(spacy_nlp_pipeline_models_dir): + raise OSError(f'Not a directory: {spacy_nlp_pipeline_models_dir}') + if not os.listdir(spacy_nlp_pipeline_models_dir): + raise OSError(f'Directory not empty: {spacy_nlp_pipeline_models_dir}') + else: + os.mkdir(spacy_nlp_pipeline_models_dir) + + + op.create_table( + 'spacy_nlp_pipeline_models', + sa.Column('creation_date', sa.DateTime(), nullable=True), + sa.Column('filename', sa.String(length=255), nullable=True), + sa.Column('last_edited_date', sa.DateTime(), nullable=True), + sa.Column('mimetype', sa.String(length=255), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('title', sa.String(length=64), nullable=True), + sa.Column('description', sa.String(length=255), nullable=True), + sa.Column('version', sa.String(length=16), nullable=True), + sa.Column('compatible_service_versions', sa.String(length=255), nullable=True), + sa.Column('publisher', sa.String(length=128), nullable=True), + sa.Column('publisher_url', sa.String(length=512), nullable=True), + sa.Column('publishing_url', sa.String(length=512), nullable=True), + sa.Column('publishing_year', sa.Integer(), nullable=True), + sa.Column('shared', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') ) - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### for user in User.query.all(): - shutil.rmtree(os.path.join(user.path, 'spacy_nlp_pipeline_models')) + spacy_nlp_pipeline_models_dir = os.path.join(user.path, 'spacy_nlp_pipeline_models') + if os.path.exists(spacy_nlp_pipeline_models_dir): + shutil.rmtree(spacy_nlp_pipeline_models_dir) + + op.drop_table('spacy_nlp_pipeline_models') - # ### end Alembic commands ### diff --git a/migrations/versions/63b2cc26a01f_.py b/migrations/versions/63b2cc26a01f_.py index 35eacc86..cd807282 100644 --- a/migrations/versions/63b2cc26a01f_.py +++ b/migrations/versions/63b2cc26a01f_.py @@ -5,8 +5,8 @@ Revises: 260b57d5f4e7 Create Date: 2022-10-11 14:32:13.227364 """ +from genericpath import isdir from alembic import op -from flask import current_app import os from app.models import User @@ -18,40 +18,19 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### for user in User.query.all(): - old_tesseract_ocr_pipeline_model_path = os.path.join( - user.path, - 'tesseract_ocr_models' - ) - new_tesseract_ocr_pipeline_model_path = os.path.join( - user.path, - 'tesseract_ocr_pipeline_models' - ) - os.rename( - old_tesseract_ocr_pipeline_model_path, - new_tesseract_ocr_pipeline_model_path - ) + old_tesseract_ocr_pipeline_model_path = os.path.join(user.path, 'tesseract_ocr_models') + new_tesseract_ocr_pipeline_model_path = os.path.join(user.path, 'tesseract_ocr_pipeline_models') + os.rename(old_tesseract_ocr_pipeline_model_path, new_tesseract_ocr_pipeline_model_path) op.rename_table('tesseract_ocr_models', 'tesseract_ocr_pipeline_models') op.rename_table('transkribus_htr_models', 'transkribus_htr_pipeline_models') - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### for user in User.query.all(): - old_tesseract_ocr_pipeline_model_path = os.path.join( - user.path, - 'tesseract_ocr_models' - ) - new_tesseract_ocr_pipeline_model_path = os.path.join( - user.path, - 'tesseract_ocr_pipeline_models' - ) - os.rename( - new_tesseract_ocr_pipeline_model_path, - old_tesseract_ocr_pipeline_model_path - ) + old_tesseract_ocr_pipeline_model_path = os.path.join(user.path, 'tesseract_ocr_models') + new_tesseract_ocr_pipeline_model_path = os.path.join(user.path, 'tesseract_ocr_pipeline_models') + os.rename(old_tesseract_ocr_pipeline_model_path, new_tesseract_ocr_pipeline_model_path) + os.rename(new_tesseract_ocr_pipeline_model_path, old_tesseract_ocr_pipeline_model_path) op.rename_table('tesseract_ocr_pipeline_models', 'tesseract_ocr_models') op.rename_table('transkribus_htr_pipeline_models', 'transkribus_htr_models') - # ### end Alembic commands ### diff --git a/migrations/versions/9e8d7d15d950_.py b/migrations/versions/9e8d7d15d950_.py index 9d59da39..bb6e9fe9 100644 --- a/migrations/versions/9e8d7d15d950_.py +++ b/migrations/versions/9e8d7d15d950_.py @@ -6,7 +6,10 @@ Create Date: 2022-04-22 09:38:49.527498 """ from alembic import op +from flask import current_app import sqlalchemy as sa +import os +import shutil # revision identifiers, used by Alembic. @@ -17,138 +20,167 @@ 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('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') + users_dir = os.path.join(current_app.config['NOPAQUE_DATA_DIR'], 'users') + if os.path.exists(users_dir): + if not os.path.isdir(users_dir): + raise OSError(f'Not a directory: {users_dir}') + if not os.listdir(users_dir): + raise OSError(f'Directory not empty: {users_dir}') + else: + os.mkdir(users_dir) + + + op.create_table( + 'roles', + sa.Column('id', sa.Integer(), nullable=False), + 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') ) 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('role_id', sa.Integer(), nullable=True), - sa.Column('confirmed', sa.Boolean(), nullable=True), - sa.Column('email', sa.String(length=254), nullable=True), - sa.Column('last_seen', sa.DateTime(), nullable=True), - sa.Column('member_since', sa.DateTime(), nullable=True), - sa.Column('password_hash', sa.String(length=128), nullable=True), - sa.Column('token', sa.String(length=32), nullable=True), - sa.Column('token_expiration', sa.DateTime(), nullable=True), - sa.Column('username', sa.String(length=64), nullable=True), - sa.Column('setting_dark_mode', sa.Boolean(), nullable=True), - sa.Column('setting_job_status_mail_notification_level', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'users', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('role_id', sa.Integer(), nullable=True), + sa.Column('confirmed', sa.Boolean(), nullable=True), + sa.Column('email', sa.String(length=254), nullable=True), + sa.Column('last_seen', sa.DateTime(), nullable=True), + sa.Column('member_since', sa.DateTime(), nullable=True), + sa.Column('password_hash', sa.String(length=128), nullable=True), + sa.Column('token', sa.String(length=32), nullable=True), + sa.Column('token_expiration', sa.DateTime(), nullable=True), + sa.Column('username', sa.String(length=64), nullable=True), + sa.Column('setting_dark_mode', sa.Boolean(), nullable=True), + sa.Column('setting_job_status_mail_notification_level', sa.Integer(), 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_token'), 'users', ['token'], unique=True) op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True) - op.create_table('corpora', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('creation_date', sa.DateTime(), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('last_edited_date', sa.DateTime(), nullable=True), - sa.Column('status', sa.Integer(), nullable=True), - sa.Column('title', sa.String(length=32), nullable=True), - sa.Column('num_analysis_sessions', sa.Integer(), nullable=True), - sa.Column('num_tokens', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'corpora', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('creation_date', sa.DateTime(), nullable=True), + sa.Column('description', sa.String(length=255), nullable=True), + sa.Column('last_edited_date', sa.DateTime(), nullable=True), + sa.Column('status', sa.Integer(), nullable=True), + sa.Column('title', sa.String(length=32), nullable=True), + sa.Column('num_analysis_sessions', sa.Integer(), nullable=True), + sa.Column('num_tokens', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') ) - op.create_table('jobs', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('creation_date', sa.DateTime(), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('end_date', sa.DateTime(), nullable=True), - sa.Column('service', sa.String(length=64), nullable=True), - sa.Column('service_args', sa.String(length=255), nullable=True), - sa.Column('service_version', sa.String(length=16), nullable=True), - sa.Column('status', sa.Integer(), nullable=True), - sa.Column('title', sa.String(length=32), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'jobs', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('creation_date', sa.DateTime(), nullable=True), + sa.Column('description', sa.String(length=255), nullable=True), + sa.Column('end_date', sa.DateTime(), nullable=True), + sa.Column('service', sa.String(length=64), nullable=True), + sa.Column('service_args', sa.String(length=255), nullable=True), + sa.Column('service_version', sa.String(length=16), nullable=True), + sa.Column('status', sa.Integer(), nullable=True), + sa.Column('title', sa.String(length=32), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') ) - op.create_table('tesseract_ocr_models', - sa.Column('creation_date', sa.DateTime(), nullable=True), - sa.Column('filename', sa.String(length=255), nullable=True), - sa.Column('last_edited_date', sa.DateTime(), nullable=True), - sa.Column('mimetype', sa.String(length=255), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('compatible_service_versions', sa.String(length=255), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('publisher', sa.String(length=128), nullable=True), - sa.Column('publisher_url', sa.String(length=512), nullable=True), - sa.Column('publishing_url', sa.String(length=512), nullable=True), - sa.Column('publishing_year', sa.Integer(), nullable=True), - sa.Column('shared', sa.Boolean(), nullable=True), - sa.Column('title', sa.String(length=64), nullable=True), - sa.Column('version', sa.String(length=16), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'tesseract_ocr_models', + sa.Column('creation_date', sa.DateTime(), nullable=True), + sa.Column('filename', sa.String(length=255), nullable=True), + sa.Column('last_edited_date', sa.DateTime(), nullable=True), + sa.Column('mimetype', sa.String(length=255), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('compatible_service_versions', sa.String(length=255), nullable=True), + sa.Column('description', sa.String(length=255), nullable=True), + sa.Column('publisher', sa.String(length=128), nullable=True), + sa.Column('publisher_url', sa.String(length=512), nullable=True), + sa.Column('publishing_url', sa.String(length=512), nullable=True), + sa.Column('publishing_year', sa.Integer(), nullable=True), + sa.Column('shared', sa.Boolean(), nullable=True), + sa.Column('title', sa.String(length=64), nullable=True), + sa.Column('version', sa.String(length=16), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') ) - op.create_table('transkribus_htr_models', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('shared', sa.Boolean(), nullable=True), - sa.Column('transkribus_model_id', sa.Integer(), nullable=True), - sa.Column('transkribus_name', sa.String(length=64), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'transkribus_htr_models', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('shared', sa.Boolean(), nullable=True), + sa.Column('transkribus_model_id', sa.Integer(), nullable=True), + sa.Column('transkribus_name', sa.String(length=64), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') ) - op.create_table('corpus_files', - sa.Column('creation_date', sa.DateTime(), nullable=True), - sa.Column('filename', sa.String(length=255), nullable=True), - sa.Column('last_edited_date', sa.DateTime(), nullable=True), - sa.Column('mimetype', sa.String(length=255), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('corpus_id', sa.Integer(), nullable=True), - sa.Column('address', sa.String(length=255), nullable=True), - sa.Column('author', sa.String(length=255), nullable=True), - sa.Column('booktitle', sa.String(length=255), nullable=True), - sa.Column('chapter', sa.String(length=255), nullable=True), - sa.Column('editor', sa.String(length=255), nullable=True), - sa.Column('institution', sa.String(length=255), nullable=True), - sa.Column('journal', sa.String(length=255), nullable=True), - sa.Column('pages', sa.String(length=255), nullable=True), - sa.Column('publisher', sa.String(length=255), nullable=True), - sa.Column('publishing_year', sa.Integer(), nullable=True), - sa.Column('school', sa.String(length=255), nullable=True), - sa.Column('title', sa.String(length=255), nullable=True), - sa.ForeignKeyConstraint(['corpus_id'], ['corpora.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'corpus_files', + sa.Column('creation_date', sa.DateTime(), nullable=True), + sa.Column('filename', sa.String(length=255), nullable=True), + sa.Column('last_edited_date', sa.DateTime(), nullable=True), + sa.Column('mimetype', sa.String(length=255), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('corpus_id', sa.Integer(), nullable=True), + sa.Column('address', sa.String(length=255), nullable=True), + sa.Column('author', sa.String(length=255), nullable=True), + sa.Column('booktitle', sa.String(length=255), nullable=True), + sa.Column('chapter', sa.String(length=255), nullable=True), + sa.Column('editor', sa.String(length=255), nullable=True), + sa.Column('institution', sa.String(length=255), nullable=True), + sa.Column('journal', sa.String(length=255), nullable=True), + sa.Column('pages', sa.String(length=255), nullable=True), + sa.Column('publisher', sa.String(length=255), nullable=True), + sa.Column('publishing_year', sa.Integer(), nullable=True), + sa.Column('school', sa.String(length=255), nullable=True), + sa.Column('title', sa.String(length=255), nullable=True), + sa.ForeignKeyConstraint(['corpus_id'], ['corpora.id'], ), + sa.PrimaryKeyConstraint('id') ) - op.create_table('job_inputs', - sa.Column('creation_date', sa.DateTime(), nullable=True), - sa.Column('filename', sa.String(length=255), nullable=True), - sa.Column('last_edited_date', sa.DateTime(), nullable=True), - sa.Column('mimetype', sa.String(length=255), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('job_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'job_inputs', + sa.Column('creation_date', sa.DateTime(), nullable=True), + sa.Column('filename', sa.String(length=255), nullable=True), + sa.Column('last_edited_date', sa.DateTime(), nullable=True), + sa.Column('mimetype', sa.String(length=255), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('job_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ), + sa.PrimaryKeyConstraint('id') ) - op.create_table('job_results', - sa.Column('creation_date', sa.DateTime(), nullable=True), - sa.Column('filename', sa.String(length=255), nullable=True), - sa.Column('last_edited_date', sa.DateTime(), nullable=True), - sa.Column('mimetype', sa.String(length=255), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('job_id', sa.Integer(), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ), - sa.PrimaryKeyConstraint('id') + + op.create_table( + 'job_results', + sa.Column('creation_date', sa.DateTime(), nullable=True), + sa.Column('filename', sa.String(length=255), nullable=True), + sa.Column('last_edited_date', sa.DateTime(), nullable=True), + sa.Column('mimetype', sa.String(length=255), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('job_id', sa.Integer(), nullable=True), + sa.Column('description', sa.String(length=255), nullable=True), + sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ), + sa.PrimaryKeyConstraint('id') ) - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### + users_dir = os.path.join(current_app.config['NOPAQUE_DATA_DIR'], 'users') + if os.path.exists(users_dir): + shutil.rmtree(users_dir) + + op.drop_table('job_results') op.drop_table('job_inputs') op.drop_table('corpus_files') @@ -162,4 +194,3 @@ def downgrade(): 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/migrations/versions/a3b727e3ff71_.py b/migrations/versions/a3b727e3ff71_.py index a2fb37fb..8dd58159 100644 --- a/migrations/versions/a3b727e3ff71_.py +++ b/migrations/versions/a3b727e3ff71_.py @@ -17,19 +17,16 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.drop_table('transkribus_htr_pipeline_models') - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('transkribus_htr_pipeline_models', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('shared', sa.BOOLEAN(), autoincrement=False, nullable=True), - sa.Column('transkribus_model_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='transkribus_htr_models_user_id_fkey'), - sa.PrimaryKeyConstraint('id', name='transkribus_htr_models_pkey') + op.create_table( + 'transkribus_htr_pipeline_models', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('user_id', sa.Integer(), autoincrement=False, nullable=True), + sa.Column('shared', sa.Boolean(), autoincrement=False, nullable=True), + sa.Column('transkribus_model_id', sa.Integer(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='transkribus_htr_models_user_id_fkey'), + sa.PrimaryKeyConstraint('id', name='transkribus_htr_models_pkey') ) - # ### end Alembic commands ### diff --git a/migrations/versions/f9070ff1fa4a_.py b/migrations/versions/f9070ff1fa4a_.py index a352ab13..87504f99 100644 --- a/migrations/versions/f9070ff1fa4a_.py +++ b/migrations/versions/f9070ff1fa4a_.py @@ -16,16 +16,18 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.drop_index('ix_users_token', table_name='users') op.drop_column('users', 'token') op.drop_column('users', 'token_expiration') - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('users', sa.Column('token_expiration', sa.DateTime(), autoincrement=False, nullable=True)) - op.add_column('users', sa.Column('token', sa.VARCHAR(length=32), autoincrement=False, nullable=True)) + op.add_column( + 'users', + sa.Column('token_expiration', sa.DateTime(), autoincrement=False, nullable=True) + ) + op.add_column( + 'users', + sa.Column('token', sa.String(length=32), autoincrement=False, nullable=True) + ) op.create_index('ix_users_token', 'users', ['token'], unique=False) - # ### end Alembic commands ###