Upgrade db to branch projects

projects
Domeniko Gentner 4 years ago
parent 3df5f74ec3
commit 76cf02a1f0
  1. 1
      .gitignore
  2. 56
      migrations/versions/3f3046e1c83c_.py
  3. 10
      server.py

1
.gitignore vendored

@ -6,3 +6,4 @@ db/labertasche.db-wal
output
/output/
*.sql
*.old

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

@ -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']}})

Loading…
Cancel
Save