Add CRUD action to refresh table metadata (#3721)

A shortcut to make it easy to refresh a table's schema
This commit is contained in:
Maxime Beauchemin 2017-10-26 16:17:56 -07:00 committed by GitHub
parent a9b6d11ade
commit 1582fa1964
2 changed files with 23 additions and 0 deletions

View File

@ -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 Easy. Simply apply the filter and save the dashboard while the filter
is active. 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``.

View File

@ -3,6 +3,7 @@ from past.builtins import basestring
from flask import Markup, flash, redirect from flask import Markup, flash, redirect
from flask_appbuilder import CompactCRUDMixin, expose from flask_appbuilder import CompactCRUDMixin, expose
from flask_appbuilder.actions import action
from flask_appbuilder.models.sqla.interface import SQLAInterface from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_babel import lazy_gettext as _ from flask_babel import lazy_gettext as _
@ -272,6 +273,20 @@ class TableModelView(DatasourceModelView, DeleteMixin): # noqa
return resp return resp
return redirect('/superset/explore/table/{}/'.format(pk)) 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( appbuilder.add_view(
TableModelView, TableModelView,
"Tables", "Tables",