Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[schema] Ensuring that the slice datasource fields are non-nullable #7114

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ assists people when migrating to a new version.
run `pip install superset[presto]` and/or `pip install superset[hive]` as
required.

* [5445](https://github.com/apache/incubator-superset/pull/5445) : a change
which prevents encoding of empty string from form data in the datanbase.
* [5445](https://github.com/apache/incubator-superset/pull/5445) : a change
which prevents encoding of empty string from form data in the database.
This involves a non-schema changing migration which does potentially impact
a large number of records. Scheduled downtime may be advised.

* [7114](https://github.com/apache/incubator-superset/pull/7114): a change
which adds missing non-nullable fields to the slices table. Depending on the
integrity of the data, manual intervention may be required.

## Superset 0.31.0
* boto3 / botocore was removed from the dependency list. If you use s3
as a place to store your SQL Lab result set or Hive uploads, you may
Expand Down
78 changes: 78 additions & 0 deletions superset/migrations/versions/1be0344d4b76_slice_non_nullable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""slice non-nullable

Revision ID: 1be0344d4b76
Revises: c82ee8a39623
Create Date: 2019-03-25 10:02:38.055193

"""

# revision identifiers, used by Alembic.
revision = '1be0344d4b76'
down_revision = 'c82ee8a39623'

from alembic import op
from sqlalchemy import Integer, String


def upgrade():

# Enforce that the slices.datasource_id, slices.datasource_name, and
# slices.datasource_type columns be non-nullable.
with op.batch_alter_table('slices') as batch_op:
batch_op.alter_column(
'slice_id',
existing_type=Integer,
nullable=False,
)

batch_op.alter_column(
'datasource_name',
existing_type=String(2000),
nullable=False,
)

batch_op.alter_column(
'datasource_type',
existing_type=String(200),
nullable=False,
)


def downgrade():

# Forego that the slices.datasource_id, slices.datasource_name, and
# slices.datasource_type columns be non-nullable.
with op.batch_alter_table('slices') as batch_op:
batch_op.alter_column(
'slice_id',
existing_type=Integer,
nullable=True,
)

batch_op.alter_column(
'datasource_name',
existing_type=String(2000),
nullable=True,
)

batch_op.alter_column(
'datasource_type',
existing_type=String(200),
nullable=True,
)
6 changes: 3 additions & 3 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ class Slice(Model, AuditMixinNullable, ImportMixin):
__tablename__ = 'slices'
id = Column(Integer, primary_key=True)
slice_name = Column(String(250))
datasource_id = Column(Integer)
datasource_type = Column(String(200))
datasource_name = Column(String(2000))
datasource_id = Column(Integer, nullable=False)
datasource_type = Column(String(200), nullable=False)
datasource_name = Column(String(2000), nullable=False)
viz_type = Column(String(250))
params = Column(Text)
description = Column(Text)
Expand Down