-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use None as "not scheduled" default value of a query (#3277)
* Use null as the default scheduled value. * Don't serialize None to json, so we can use SQL is not null predicate. * Fix warning about unicode in tests * Handling empty query.schedule in UI (#3283) * Add migration to convert empty schedules to null and drop the not null contraint.
- Loading branch information
Showing
13 changed files
with
123 additions
and
75 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
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
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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
migrations/versions/73beceabb948_bring_back_null_schedule.py
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,56 @@ | ||
"""bring_back_null_schedule | ||
Revision ID: 73beceabb948 | ||
Revises: e7f8a917aa8e | ||
Create Date: 2019-01-17 13:22:21.729334 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
from sqlalchemy.sql import table | ||
|
||
from redash.models import MutableDict, PseudoJSON | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '73beceabb948' | ||
down_revision = 'e7f8a917aa8e' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def is_empty_schedule(schedule): | ||
if schedule is None: | ||
return False | ||
|
||
if schedule == {}: | ||
return True | ||
|
||
if schedule.get('interval') is None and schedule.get('until') is None and schedule.get('day_of_week') is None and schedule.get('time') is None: | ||
return True | ||
|
||
return False | ||
|
||
|
||
def upgrade(): | ||
op.alter_column('queries', 'schedule', | ||
nullable=True, | ||
server_default=None) | ||
|
||
queries = table( | ||
'queries', | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('schedule', MutableDict.as_mutable(PseudoJSON))) | ||
|
||
conn = op.get_bind() | ||
for query in conn.execute(queries.select()): | ||
if is_empty_schedule(query.schedule): | ||
conn.execute( | ||
queries | ||
.update() | ||
.where(queries.c.id == query.id) | ||
.values(schedule=None)) | ||
|
||
|
||
def downgrade(): | ||
pass |
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
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
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
Oops, something went wrong.