From 136f0cf902a7d64322672318707f2ade9d9ac6d3 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 25 Oct 2017 23:43:28 +0000 Subject: [PATCH] Add CRUD action to refresh table metadata A shortcut to make it easy to refresh a table's schema --- docs/faq.rst | 8 ++++++++ superset/connectors/sqla/views.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/faq.rst b/docs/faq.rst index cee767ae96f18..f5335f9d218c6 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -213,3 +213,11 @@ How can I set a default filter on my dashboard? Easy. Simply apply the filter and save the dashboard while the filter is active. + +How do I get Superset to refresh the schema of my table? +-------------------------------------------------------- + +When adding columns to a table, you can have Superset detect and merge the +new columns in by using the "Refresh Metadata" action in the +``Source -> Tables`` page. Simply check the box next to the tables +you want the schema refreshed, and click ``Actions -> Refresh Metadata``. diff --git a/superset/connectors/sqla/views.py b/superset/connectors/sqla/views.py index 630ce522ec066..e8fdf8d3f67b2 100644 --- a/superset/connectors/sqla/views.py +++ b/superset/connectors/sqla/views.py @@ -3,6 +3,7 @@ from flask import Markup, flash, redirect from flask_appbuilder import CompactCRUDMixin, expose +from flask_appbuilder.actions import action from flask_appbuilder.models.sqla.interface import SQLAInterface from flask_babel import lazy_gettext as _ @@ -272,6 +273,20 @@ def edit(self, pk): return resp return redirect('/superset/explore/table/{}/'.format(pk)) + @action( + "refresh", + __("Refresh Metadata"), + __("Refresh column metadata"), + "fa-refresh") + def refresh(self, tables): + for t in tables: + t.fetch_metadata() + msg = _( + "Metadata refreshed for the following table(s): %(tables)s", + tables=", ".join([t.table_name for t in tables])) + flash(msg, 'info') + return redirect('/tablemodelview/list/') + appbuilder.add_view( TableModelView, "Tables",