diff --git a/.gitignore b/.gitignore index 53d298f..2c2d98b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ db/labertasche.db-wal output /output/ *.sql +*.old diff --git a/migrations/versions/3f3046e1c83c_.py b/migrations/versions/3f3046e1c83c_.py new file mode 100644 index 0000000..2589ca0 --- /dev/null +++ b/migrations/versions/3f3046e1c83c_.py @@ -0,0 +1,56 @@ +"""empty message + +Revision ID: 3f3046e1c83c +Revises: +Create Date: 2020-12-07 21:57:21.057956 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '3f3046e1c83c' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('t_comments', schema=None) as batch_op: + batch_op.add_column(sa.Column('project_id', sa.Integer(), nullable=False, default=1)) + batch_op.create_unique_constraint(batch_op.f('uq_t_comments_content'), ['content']) + batch_op.create_foreign_key(batch_op.f('fk_t_comments_project_id_t_projects'), 't_projects', ['project_id'], ['id_project']) + + with op.batch_alter_table('t_email', schema=None) as batch_op: + batch_op.add_column(sa.Column('project_id', sa.Integer(), nullable=False, default=1)) + batch_op.create_unique_constraint(batch_op.f('uq_t_email_email'), ['email']) + batch_op.create_foreign_key(batch_op.f('fk_t_email_project_id_t_projects'), 't_projects', ['project_id'], ['id_project']) + + with op.batch_alter_table('t_location', schema=None) as batch_op: + batch_op.add_column(sa.Column('project_id', sa.Integer(), nullable=False, default=1)) + batch_op.create_unique_constraint(batch_op.f('uq_t_location_location'), ['location']) + batch_op.create_foreign_key(batch_op.f('fk_t_location_project_id_t_projects'), 't_projects', ['project_id'], ['id_project']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('t_location', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_t_location_project_id_t_projects'), type_='foreignkey') + batch_op.drop_constraint(batch_op.f('uq_t_location_location'), type_='unique') + batch_op.drop_column('project_id') + + with op.batch_alter_table('t_email', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_t_email_project_id_t_projects'), type_='foreignkey') + batch_op.drop_constraint(batch_op.f('uq_t_email_email'), type_='unique') + batch_op.drop_column('project_id') + + with op.batch_alter_table('t_comments', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_t_comments_project_id_t_projects'), type_='foreignkey') + batch_op.drop_constraint(batch_op.f('uq_t_comments_content'), type_='unique') + batch_op.drop_column('project_id') + + # ### end Alembic commands ### diff --git a/server.py b/server.py index 812d867..445bad2 100644 --- a/server.py +++ b/server.py @@ -15,6 +15,7 @@ from sqlalchemy.engine import Engine from labertasche.settings import Settings from labertasche.database import labertasche_db from labertasche.blueprints import bp_comments, bp_login, bp_dashboard +from labertasche.models import TProjects from labertasche.helper import User from flask_login import LoginManager from flask_migrate import Migrate @@ -35,13 +36,20 @@ laberflask.config.update(dict( )) # Flask migrate - migrate = Migrate(laberflask, labertasche_db, render_as_batch=True) # Initialize ORM labertasche_db.init_app(laberflask) with laberflask.app_context(): labertasche_db.create_all() + project = labertasche_db.session.query(TProjects).filter(TProjects.id_project == 1).first() + if not project: + default_project = { + "id_project": 1, + "name": "default" + } + labertasche_db.session.add(TProjects(**default_project)) + labertasche_db.session.commit() # CORS CORS(laberflask, resources={r"/comments": {"origins": settings.system['blog_url']}})