Add parallel fs changes to migration scripts and cleanup

This commit is contained in:
Patrick Jentsch
2022-10-26 10:34:07 +02:00
parent cbf3abb424
commit 0b656d3cf1
8 changed files with 223 additions and 210 deletions

View File

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