Skip to content

Commit

Permalink
Add CRUD action to refresh table metadata (#3721)
Browse files Browse the repository at this point in the history
A shortcut to make it easy to refresh a table's schema
  • Loading branch information
mistercrunch authored Oct 26, 2017
1 parent a9b6d11 commit 1582fa1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
15 changes: 15 additions & 0 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1582fa1

Please sign in to comment.