Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
feat: add sql views for current and next week (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
sralloza authored Nov 6, 2021
1 parent 3dab1e0 commit 14b161f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions alembic/versions/032390abe0c6_create_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Create views
Revision ID: 032390abe0c6
Revises: f2b0ccdc9f11
Create Date: 2021-11-06 21:00:05.760482
"""
import sqlalchemy as sa

from alembic import op


# revision identifiers, used by Alembic.
revision = "032390abe0c6"
down_revision = "f2b0ccdc9f11"
branch_labels = None
depends_on = None


def upgrade():
currentWeek = "CREATE OR REPLACE VIEW currentWeek AS SELECT * FROM meal WHERE YEARWEEK(id,1) = yearweek(curdate(),1);"
nextWeek = "CREATE OR REPLACE VIEW nextWeek AS SELECT * FROM meal WHERE YEARWEEK(id,1) = yearweek(CURDATE()+7,1);"
op.execute(currentWeek)
op.execute(nextWeek)


def downgrade():
currentWeek = "DROP VIEW currentWeek"
nextWeek = "DROP VIEW nextWeek"
op.execute(currentWeek)
op.execute(nextWeek)

0 comments on commit 14b161f

Please sign in to comment.