Skip to content

Commit

Permalink
Add extra_json column to Query
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Nov 5, 2018
1 parent 68ffd4f commit d9bd2d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Add extra column to Query
Revision ID: 0b1f1ab473c0
Revises: 55e910a74826
Create Date: 2018-11-05 08:42:56.181012
"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '0b1f1ab473c0'
down_revision = '55e910a74826'


def upgrade():
op.add_column('query', sa.Column('extra_json', sa.Text(), nullable=True))


def downgrade():
op.drop_column('query', 'extra_json')
11 changes: 11 additions & 0 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,14 @@ def __init__( # noqa
self.duration = duration
self.status = status
self.error_message = error_message


class ExtraJSONMixin:
extra_json = sa.Column(sa.Text)

@property
def extra(self):
return json.loads(self.extra_json)

def set_extra_json(self, d):
self.extra_json = json.dumps(d)
5 changes: 3 additions & 2 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=C,R,W
"""A collection of ORM sqlalchemy models for SQL Lab"""
from datetime import datetime
import json
import re

from flask import Markup
Expand All @@ -12,11 +13,11 @@
from sqlalchemy.orm import backref, relationship

from superset import security_manager
from superset.models.helpers import AuditMixinNullable
from superset.models.helpers import AuditMixinNullable, ExtraJSONMixin
from superset.utils.core import QueryStatus, user_label


class Query(Model):
class Query(Model, ExtraJSONMixin):
"""ORM model for SQL query
Now that SQL Lab support multi-statement execution, an entry in this
Expand Down

0 comments on commit d9bd2d4

Please sign in to comment.