from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.Dashboard, models.Dashboard.created_at, 'created_at') migrator.add_column(models.Widget, models.Widget.created_at, 'created_at') db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.Query, models.Query.is_archived, 'is_archived') db.close_db(None)
import json from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': default_options = {"series": {"type": "column"}} db.connect_db() if not models.Visualization.table_exists(): print "Creating visualization table..." models.Visualization.create_table() with db.database.transaction(): migrator = Migrator(db.database) print "Adding visualization_id to widgets:" field = models.Widget.visualization field.null = True migrator.add_column(models.Widget, models.Widget.visualization, 'visualization_id') print 'Creating TABLE visualizations for all queries...' for query in models.Query.select(): vis = models.Visualization(query=query, name="Table", description=query.description or "", type="TABLE", options="{}") vis.save() print 'Creating COHORT visualizations for all queries named like %cohort%...' for query in models.Query.select().where(models.Query.name ** "%cohort%"): vis = models.Visualization(query=query, name="Cohort",
from playhouse.migrate import Migrator from redash.models import db from redash import models if __name__ == "__main__": db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.DataSource, models.DataSource.queue_name, "queue_name") migrator.add_column(models.DataSource, models.DataSource.scheduled_queue_name, "scheduled_queue_name") db.close_db(None)
import json import itertools import peewee from playhouse.migrate import Migrator from redash import db, settings from redash import models if __name__ == '__main__': db.connect_db() if not models.User.table_exists(): print "Creating user table..." models.User.create_table() migrator = Migrator(db.database) with db.database.transaction(): print "Creating user field on dashboard and queries..." try: migrator.rename_column(models.Query, '"user"', "user_email") migrator.rename_column(models.Dashboard, '"user"', "user_email") except peewee.ProgrammingError: print "Failed to rename user column -- assuming it already exists" with db.database.transaction(): models.Query.user.null = True models.Dashboard.user.null = True try: migrator.add_column(models.Query, models.Query.user, "user_id") migrator.add_column(models.Dashboard, models.Dashboard.user, "user_id") except peewee.ProgrammingError:
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.Widget, models.Widget.text, 'text') migrator.set_nullable(models.Widget, models.Widget.visualization, True) db.close_db(None)
import peewee from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) if not models.Group.table_exists(): print "Creating groups table..." models.Group.create_table() with db.database.transaction(): models.Group.insert(name='admin', permissions=['admin'], tables=['*']).execute() models.Group.insert(name='api', permissions=['view_query'], tables=['*']).execute() models.Group.insert(name='default', permissions=models.Group.DEFAULT_PERMISSIONS, tables=['*']).execute() migrator.add_column(models.User, models.User.groups, 'groups') models.User.update(groups=['admin', 'default']).where(peewee.SQL("is_admin = true")).execute() models.User.update(groups=['admin', 'default']).where(peewee.SQL("'admin' = any(permissions)")).execute() models.User.update(groups=['default']).where(peewee.SQL("is_admin = false")).execute() migrator.drop_column(models.User, 'permissions') migrator.drop_column(models.User, 'is_admin') db.close_db(None)
from playhouse.migrate import Migrator from redash.models import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.DataSource, models.DataSource.queue_name, 'queue_name') migrator.add_column(models.DataSource, models.DataSource.scheduled_queue_name, 'scheduled_queue_name') db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.User, models.User.password_hash, 'password_hash') db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.set_nullable(models.Widget, models.Widget.query_id, True) migrator.set_nullable(models.Widget, models.Widget.type, True) db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.User, models.User.permissions, 'permissions') models.User.update(permissions=['admin'] + models.User.DEFAULT_PERMISSIONS).where(models.User.is_admin == True).execute() db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.User, models.User.permissions, 'permissions') models.User.update(permissions=['admin'] + models.User.DEFAULT_PERMISSIONS).where( models.User.is_admin == True).execute() db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.set_nullable(models.Query, models.Query.description, True) db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.Dashboard, models.Dashboard.dashboard_filters_enabled, 'dashboard_filters_enabled') db.close_db(None)
from playhouse.migrate import Migrator from redash import db from redash import models if __name__ == '__main__': db.connect_db() migrator = Migrator(db.database) with db.database.transaction(): migrator.add_column(models.DataSource, models.DataSource.queue_name, 'queue_name') migrator.add_column(models.DataSource, models.DataSource.scheduled_queue_name, 'scheduled_queue_name') db.close_db(None)
import json import itertools import peewee from playhouse.migrate import Migrator from redash import db, settings from redash import models if __name__ == '__main__': db.connect_db() if not models.User.table_exists(): print "Creating user table..." models.User.create_table() migrator = Migrator(db.database) with db.database.transaction(): print "Creating user field on dashboard and queries..." try: migrator.rename_column(models.Query, '"user"', "user_email") migrator.rename_column(models.Dashboard, '"user"', "user_email") except peewee.ProgrammingError: print "Failed to rename user column -- assuming it already exists" with db.database.transaction(): models.Query.user.null = True models.Dashboard.user.null = True try: migrator.add_column(models.Query, models.Query.user, "user_id") migrator.add_column(models.Dashboard, models.Dashboard.user, "user_id")
from redash import settings if __name__ == '__main__': db.connect_db() if not models.DataSource.table_exists(): print "Creating data_sources table..." models.DataSource.create_table() default_data_source = models.DataSource.create(name="Default", type=settings.CONNECTION_ADAPTER, options=settings.CONNECTION_STRING) else: default_data_source = models.DataSource.select().first() migrator = Migrator(db.database) models.Query.data_source.null = True models.QueryResult.data_source.null = True try: with db.database.transaction(): migrator.add_column(models.Query, models.Query.data_source, "data_source_id") except peewee.ProgrammingError: print "Failed to create data_source_id column -- assuming it already exists" try: with db.database.transaction(): migrator.add_column(models.QueryResult, models.QueryResult.data_source, "data_source_id") except peewee.ProgrammingError: print "Failed to create data_source_id column -- assuming it already exists" print "Updating data source to existing one..."
if __name__ == '__main__': db.connect_db() if not models.DataSource.table_exists(): print "Creating data_sources table..." models.DataSource.create_table() default_data_source = models.DataSource.create( name="Default", type=settings.CONNECTION_ADAPTER, options=settings.CONNECTION_STRING) else: default_data_source = models.DataSource.select().first() migrator = Migrator(db.database) models.Query.data_source.null = True models.QueryResult.data_source.null = True try: with db.database.transaction(): migrator.add_column(models.Query, models.Query.data_source, "data_source_id") except peewee.ProgrammingError: print "Failed to create data_source_id column -- assuming it already exists" try: with db.database.transaction(): migrator.add_column(models.QueryResult, models.QueryResult.data_source, "data_source_id") except peewee.ProgrammingError: