john-bodley commented on a change in pull request #17323:
URL: https://github.com/apache/superset/pull/17323#discussion_r741209734



##########
File path: superset/migrations/versions/b92d69a6643c_rename_csv_to_file.py
##########
@@ -15,23 +15,54 @@
 # specific language governing permissions and limitations
 # under the License.
 """rename_csv_to_file
-
 Revision ID: b92d69a6643c
 Revises: 32646df09c64
 Create Date: 2021-09-19 14:42:20.130368
-
 """
 
 # revision identifiers, used by Alembic.
 revision = "b92d69a6643c"
 down_revision = "32646df09c64"
 
-import sqlalchemy as sa
+import json
+import logging
+
 from alembic import op
+import sqlalchemy as sa
+from sqlalchemy import Column, Integer, Text
 from sqlalchemy.engine.reflection import Inspector
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Database(Base):
+
+    __tablename__ = "dbs"
+    id = Column(Integer, primary_key=True)
+    extra = Column(Text)
 
 
 def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    for database in session.query(Database).all():
+        try:
+            extra = json.loads(database.extra)
+        except json.decoder.JSONDecodeError as ex:
+            logging.warning(str(ex))
+            continue
+
+        if "schemas_allowed_for_csv_upload" in extra:
+            extra["schemas_allowed_for_file_upload"] = extra.pop(
+                "schemas_allowed_for_csv_upload"
+            )
+
+        database.extra = json.dumps(extra)

Review comment:
       ```suggestion
               database.extra = json.dumps(extra)
   ```

##########
File path: superset/migrations/versions/b92d69a6643c_rename_csv_to_file.py
##########
@@ -15,23 +15,54 @@
 # specific language governing permissions and limitations
 # under the License.
 """rename_csv_to_file
-
 Revision ID: b92d69a6643c
 Revises: 32646df09c64
 Create Date: 2021-09-19 14:42:20.130368
-
 """
 
 # revision identifiers, used by Alembic.
 revision = "b92d69a6643c"
 down_revision = "32646df09c64"
 
-import sqlalchemy as sa
+import json
+import logging
+
 from alembic import op
+import sqlalchemy as sa
+from sqlalchemy import Column, Integer, Text
 from sqlalchemy.engine.reflection import Inspector
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Database(Base):
+
+    __tablename__ = "dbs"
+    id = Column(Integer, primary_key=True)
+    extra = Column(Text)
 
 
 def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    for database in session.query(Database).all():
+        try:
+            extra = json.loads(database.extra)
+        except json.decoder.JSONDecodeError as ex:

Review comment:
       Just to confirm is this the only exception that `json.loads(…)` can 
raise?

##########
File path: superset/migrations/versions/b92d69a6643c_rename_csv_to_file.py
##########
@@ -59,11 +89,34 @@ def upgrade():
                 existing_type=sa.Boolean(),
             )
 
+    session.commit()
+    session.close()
+
 
 def downgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    for database in session.query(Database).all():
+        try:
+            extra = json.loads(database.extra)
+        except json.decoder.JSONDecodeError as ex:
+            logging.warning(str(ex))
+            continue
+
+        if "schemas_allowed_for_file_upload" in extra:
+            extra["schemas_allowed_for_csv_upload"] = extra.pop(
+                "schemas_allowed_for_file_upload"
+            )
+
+        database.extra = json.dumps(extra)

Review comment:
       ```suggestion
               database.extra = json.dumps(extra)
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to