Fixing mysql install

This commit is contained in:
Maxime Beauchemin 2016-03-27 21:49:35 -07:00
parent 4a0ea5fff7
commit 26c725171b
3 changed files with 290 additions and 284 deletions

View File

@ -267,10 +267,10 @@ def load_world_bank_health_n_pop():
dash_name = "World's Health Bank Dashboard"
dash = db.session.query(Dash).filter_by(dashboard_title=dash_name).first()
if dash:
db.session.delete(dash)
js = """\
[
if not dash:
dash = Dash()
js = textwrap.dedent("""\
[
{
"size_y": 2,
"size_x": 3,
@ -327,18 +327,18 @@ def load_world_bank_health_n_pop():
"slice_id": "8",
"row": 9
}
]
"""
]
""")
l = json.loads(js)
for i, pos in enumerate(l):
pos['slice_id'] = str(slices[i].id)
dash = Dash(
dashboard_title=dash_name,
position_json=json.dumps(l, indent=4),
slug="world_health",
)
for s in slices:
dash.slices.append(s)
dash.dashboard_title = dash_name
dash.position_json = json.dumps(l, indent=4)
dash.slug = "world_health"
dash.slices = slices
db.session.merge(dash)
db.session.commit()
@ -600,10 +600,10 @@ def load_birth_names():
print("Creating a dashboard")
dash = db.session.query(Dash).filter_by(dashboard_title="Births").first()
if dash:
db.session.delete(dash)
js = """
[
if not dash:
dash = Dash()
js = textwrap.dedent("""\
[
{
"size_y": 4,
"size_x": 2,
@ -667,16 +667,14 @@ def load_birth_names():
"slice_id": "93",
"row": 3
}
]
"""
]
""")
l = json.loads(js)
for i, pos in enumerate(l):
pos['slice_id'] = str(slices[i].id)
dash = Dash(
dashboard_title="Births",
position_json=json.dumps(l, indent=4),
slug="births",
)
for s in slices:
dash.slices.append(s)
dash.dashboard_title = "Births"
dash.position_json = json.dumps(l, indent=4)
dash.slug = "births"
dash.slices = slices
db.session.merge(dash)
db.session.commit()

View File

@ -15,48 +15,47 @@ import sqlalchemy as sa
def upgrade():
op.alter_column('columns', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('columns', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('css_templates', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('css_templates', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dashboards', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dashboards', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('datasources', 'changed_by_fk',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column('datasources', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('datasources', 'created_by_fk',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column('datasources', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dbs', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dbs', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.add_column('metrics', sa.Column('changed_by_fk', sa.Integer(), nullable=True))
op.add_column('metrics', sa.Column('changed_on', sa.DateTime(), nullable=True))
op.add_column('metrics', sa.Column('created_by_fk', sa.Integer(), nullable=True))
op.add_column('metrics', sa.Column('created_on', sa.DateTime(), nullable=True))
op.create_foreign_key(None, 'metrics', 'ab_user', ['changed_by_fk'], ['id'])
op.create_foreign_key(None, 'metrics', 'ab_user', ['created_by_fk'], ['id'])
try:
op.alter_column('columns', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('columns', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('css_templates', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('css_templates', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dashboards', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dashboards', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('datasources', 'changed_by_fk',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column('datasources', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('datasources', 'created_by_fk',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column('datasources', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dbs', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('dbs', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.alter_column('slices', 'changed_on',
existing_type=sa.DATETIME(),
nullable=True)
@ -87,45 +86,50 @@ def upgrade():
op.alter_column('url', 'created_on',
existing_type=sa.DATETIME(),
nullable=True)
op.create_foreign_key(None, 'metrics', 'ab_user', ['changed_by_fk'], ['id'])
op.create_foreign_key(None, 'metrics', 'ab_user', ['created_by_fk'], ['id'])
except:
pass
def downgrade():
op.alter_column('url', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('url', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('tables', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('tables', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('table_columns', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('table_columns', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('sql_metrics', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('sql_metrics', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('slices', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('slices', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.drop_constraint(None, 'metrics', type_='foreignkey')
op.drop_constraint(None, 'metrics', type_='foreignkey')
op.drop_column('metrics', 'created_on')
op.drop_column('metrics', 'created_by_fk')
op.drop_column('metrics', 'changed_on')
op.drop_column('metrics', 'changed_by_fk')
try:
op.alter_column('url', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('url', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('tables', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('tables', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('table_columns', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('table_columns', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('sql_metrics', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('sql_metrics', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('slices', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
op.alter_column('slices', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
op.drop_constraint(None, 'metrics', type_='foreignkey')
op.drop_constraint(None, 'metrics', type_='foreignkey')
op.alter_column('dbs', 'created_on',
existing_type=sa.DATETIME(),
nullable=False)
@ -162,3 +166,5 @@ def downgrade():
op.alter_column('columns', 'changed_on',
existing_type=sa.DATETIME(),
nullable=False)
except:
pass

View File

@ -634,13 +634,14 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
db.session.flush()
if not dbcol:
dbcol = TableColumn(column_name=col.name)
num_types = ('DOUBLE', 'FLOAT', 'INT', 'BIGINT')
datatype = str(datatype).upper()
if (
str(datatype).startswith('VARCHAR') or
str(datatype).startswith('STRING')):
dbcol.groupby = True
dbcol.filterable = True
elif str(datatype).upper() in ('DOUBLE', 'FLOAT', 'INT', 'BIGINT'):
elif any([t in datatype for t in num_types]):
dbcol.sum = True
db.session.merge(self)
self.columns.append(dbcol)
@ -746,7 +747,8 @@ class TableColumn(Model, AuditMixinNullable):
@property
def isnum(self):
return self.type in ('LONG', 'DOUBLE', 'FLOAT')
types = ('LONG', 'DOUBLE', 'FLOAT', 'BIGINT', 'INT')
return any([t in self.type.upper() for t in types])
class DruidCluster(Model, AuditMixinNullable):