Ejemplo n.º 1
0
def create_db(create_tables, drop_tables):
    db.connect_db()

    for model in all_models:
        if drop_tables and model.table_exists():
            # TODO: submit PR to peewee to allow passing cascade option to drop_table.
            db.database.execute_sql('DROP TABLE %s CASCADE' % model._meta.db_table)
            #model.drop_table()

        if create_tables:
            model.create_table()

    db.close_db(None)
Ejemplo n.º 2
0
def create_db(create_tables, drop_tables):
    db.connect_db()

    for model in all_models:
        if drop_tables and model.table_exists():
            # TODO: submit PR to peewee to allow passing cascade option to drop_table.
            db.database.execute_sql('DROP TABLE %s CASCADE' % model._meta.db_table)
            #model.drop_table()

        if create_tables and not model.table_exists():
            model.create_table()

    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)
Ejemplo n.º 4
0
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")