File tree Expand file tree Collapse file tree 3 files changed +587
-23
lines changed Expand file tree Collapse file tree 3 files changed +587
-23
lines changed Original file line number Diff line number Diff line change 1
1
from superset import conf , db
2
+ from superset .connectors .connector_registry import ConnectorRegistry
2
3
from superset .models import core as models
3
4
4
5
@@ -18,4 +19,30 @@ def get_or_create_metadata_db():
18
19
return dbobj
19
20
20
21
22
+ def add_metadata_tables ():
23
+ schema = conf .get ('METADATA_DB' )
24
+ dbobj = get_or_create_metadata_db ()
25
+ TBL = ConnectorRegistry .sources ['table' ]
26
+ for table in dbobj .all_table_names_in_schema (schema ):
27
+ # table_name should match the one in the datasource for fetch_metadata to work
28
+ if db .session .query (TBL ).filter_by (table_name = table ).first ():
29
+ continue
30
+ if db .session .query (TBL ).filter_by (table_name = '%s.%s' % (schema , table )).first ():
31
+ continue
32
+
33
+ # create table with original name and fetch columns
34
+ tbl = TBL (table_name = table )
35
+ tbl .database = dbobj
36
+ db .session .add (tbl )
37
+ db .session .commit ()
38
+ tbl .fetch_metadata ()
39
+
40
+ # rename with prefix and set source
41
+ tbl .table_name = '%s.%s' % (schema , table )
42
+ tbl .sql = 'select * from ' + table
43
+ db .session .add (dbobj )
44
+ db .session .commit ()
45
+
46
+
21
47
get_or_create_metadata_db ()
48
+ add_metadata_tables ()
You can’t perform that action at this time.
0 commit comments