This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sql views for current and next week (#20)
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |