Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 1, 2016
1 parent 029957f commit 2c3a193
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ engines:
pep8:
enabled: true
fixme:
enabled: true
enabled: false
radon:
enabled: true
ratings:
Expand Down
14 changes: 7 additions & 7 deletions caravel/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def load_energy():
tbl = TBL(table_name=tbl_name)
tbl.description = "Energy consumption"
tbl.is_featured = True
tbl.database = utils.get_or_create_db(caravel)
tbl.database = utils.get_or_create_main_db(caravel)
db.session.merge(tbl)
db.session.commit()
tbl.fetch_metadata()
Expand Down Expand Up @@ -191,7 +191,7 @@ def load_world_bank_health_n_pop():
tbl.description = utils.readfile(os.path.join(DATA_FOLDER, 'countries.md'))
tbl.main_dttm_col = 'year'
tbl.is_featured = True
tbl.database = utils.get_or_create_db(caravel)
tbl.database = utils.get_or_create_main_db(caravel)
db.session.merge(tbl)
db.session.commit()
tbl.fetch_metadata()
Expand Down Expand Up @@ -582,7 +582,7 @@ def load_birth_names():
if not obj:
obj = TBL(table_name='birth_names')
obj.main_dttm_col = 'ds'
obj.database = utils.get_or_create_db(caravel)
obj.database = utils.get_or_create_main_db(caravel)
obj.is_featured = True
db.session.merge(obj)
db.session.commit()
Expand Down Expand Up @@ -830,7 +830,7 @@ def load_unicode_test_data():
if not obj:
obj = TBL(table_name='unicode_test')
obj.main_dttm_col = 'date'
obj.database = utils.get_or_create_db(caravel)
obj.database = utils.get_or_create_main_db(caravel)
obj.is_featured = False
db.session.merge(obj)
db.session.commit()
Expand Down Expand Up @@ -909,7 +909,7 @@ def load_random_time_series_data():
if not obj:
obj = TBL(table_name='random_time_series')
obj.main_dttm_col = 'ds'
obj.database = utils.get_or_create_db(caravel)
obj.database = utils.get_or_create_main_db(caravel)
obj.is_featured = False
db.session.merge(obj)
db.session.commit()
Expand Down Expand Up @@ -977,7 +977,7 @@ def load_long_lat_data():
if not obj:
obj = TBL(table_name='long_lat')
obj.main_dttm_col = 'date'
obj.database = utils.get_or_create_db(caravel)
obj.database = utils.get_or_create_main_db(caravel)
obj.is_featured = False
db.session.merge(obj)
db.session.commit()
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def load_multiformat_time_series_data():
if not obj:
obj = TBL(table_name='multiformat_time_series')
obj.main_dttm_col = 'ds'
obj.database = utils.get_or_create_db(caravel)
obj.database = utils.get_or_create_main_db(caravel)
obj.is_featured = False
dttm_and_expr_dict = {
'ds': [None, None],
Expand Down
3 changes: 3 additions & 0 deletions caravel/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def get_sql_results(query_id, return_results=True):
data = result_proxy.fetchall()
df = pd.DataFrame(data, columns=columns)
df = df.where((pd.notnull(df)), None)
# TODO consider generating tuples instead of dicts to send
# less data through the wire. The command bellow does that,
# but we'd need to align on the client side.
# data = df.values.tolist()
data = df.to_dict(orient='records')

Expand Down
8 changes: 4 additions & 4 deletions caravel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ def __get__(self, obj, objtype):
return functools.partial(self.__call__, obj)


def get_or_create_db(caravel):
def get_or_create_main_db(caravel):
db = caravel.db
config = caravel.app.config
DB = caravel.models.Database
print("Creating database reference")
logging.info("Creating database reference")
dbobj = db.session.query(DB).filter_by(database_name='main').first()
if not dbobj:
dbobj = DB(database_name="main")
print(config.get("SQLALCHEMY_DATABASE_URI"))
logging.info(config.get("SQLALCHEMY_DATABASE_URI"))
dbobj.sqlalchemy_uri = config.get("SQLALCHEMY_DATABASE_URI")
dbobj.expose_in_sqllab = True
db.session.add(dbobj)
Expand Down Expand Up @@ -213,7 +213,7 @@ def init(caravel):
sm = caravel.appbuilder.sm
alpha = sm.add_role("Alpha")
admin = sm.add_role("Admin")
get_or_create_db(caravel)
get_or_create_main_db(caravel)

merge_perm(sm, 'all_datasource_access', 'all_datasource_access')

Expand Down

0 comments on commit 2c3a193

Please sign in to comment.