Skip to content

Commit c378b64

Browse files
authored
Merge pull request #148 from src-d/progress-chart
Add progress charts
2 parents 35b662a + 62a83a3 commit c378b64

File tree

3 files changed

+587
-23
lines changed

3 files changed

+587
-23
lines changed

srcd/contrib/docker/add_metadata_db.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from superset import conf, db
2+
from superset.connectors.connector_registry import ConnectorRegistry
23
from superset.models import core as models
34

45

@@ -18,4 +19,30 @@ def get_or_create_metadata_db():
1819
return dbobj
1920

2021

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+
2147
get_or_create_metadata_db()
48+
add_metadata_tables()

0 commit comments

Comments
 (0)