Skip to content

Commit 19eb73b

Browse files
john-bodleyJohn Bodley
andauthored
fix(sqllab): Replace stringified 'null' schema column values with NULL (#18992)
Co-authored-by: John Bodley <john.bodley@airbnb.com>
1 parent a04f1d4 commit 19eb73b

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
"""fix query and saved_query null schema
18+
19+
Revision ID: b5a422d8e252
20+
Revises: b8d3a24d9131
21+
Create Date: 2022-03-02 09:20:02.919490
22+
23+
"""
24+
25+
from alembic import op
26+
from sqlalchemy import Column, Integer, String
27+
from sqlalchemy.ext.declarative import declarative_base
28+
29+
from superset import db
30+
31+
# revision identifiers, used by Alembic.
32+
revision = "b5a422d8e252"
33+
down_revision = "b8d3a24d9131"
34+
35+
Base = declarative_base()
36+
37+
38+
class Query(Base):
39+
__tablename__ = "query"
40+
41+
id = Column(Integer, primary_key=True)
42+
schema = Column(String(256))
43+
44+
45+
class SavedQuery(Base):
46+
__tablename__ = "saved_query"
47+
48+
id = Column(Integer, primary_key=True)
49+
schema = Column(String(128))
50+
51+
52+
def upgrade():
53+
bind = op.get_bind()
54+
session = db.Session(bind=bind)
55+
56+
for model in (Query, SavedQuery):
57+
for record in session.query(model).filter(model.schema == "null"):
58+
record.schema = None
59+
60+
session.commit()
61+
62+
session.close()
63+
64+
65+
def downgrade():
66+
pass

0 commit comments

Comments
 (0)