diff --git a/UPDATING.md b/UPDATING.md index 5c7edbe5395a1..5a8b1bc3e4113 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -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 diff --git a/superset/migrations/versions/1be0344d4b76_slice_non_nullable.py b/superset/migrations/versions/1be0344d4b76_slice_non_nullable.py new file mode 100644 index 0000000000000..fd2cd80ce94fd --- /dev/null +++ b/superset/migrations/versions/1be0344d4b76_slice_non_nullable.py @@ -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, + ) diff --git a/superset/models/core.py b/superset/models/core.py index b848604a46d64..9c34e82144800 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -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)