redash/migrations/0026_add_access_control_tables.py

22 lines
772 B
Python
Raw Normal View History

2016-09-08 03:21:24 +00:00
from redash import settings
from redash.models import db, Change, AccessPermission, Query, Dashboard
from playhouse.migrate import PostgresqlMigrator, migrate
if __name__ == '__main__':
if not Change.table_exists():
Change.create_table()
if not AccessPermission.table_exists():
AccessPermission.create_table()
migrator = PostgresqlMigrator(db.database)
for tbl, field in (('queries', Query.version), ('dashboards', Dashboard.version)):
try:
with db.database.transaction():
migrate(
migrator.add_column(tbl, 'version', field)
)
except Exception, e:
print('WARNING: Unable to add column "version" to table "%s" - maybe it already exists?' % tbl)