2016-10-05 14:15:46 +00:00
|
|
|
import os
|
2015-12-01 13:44:08 +00:00
|
|
|
from redash.models import db, Organization, Group
|
|
|
|
from redash import settings
|
|
|
|
from playhouse.migrate import PostgresqlMigrator, migrate
|
|
|
|
|
2016-10-05 14:15:46 +00:00
|
|
|
# The following is deprecated and should be defined with the Organization object
|
|
|
|
GOOGLE_APPS_DOMAIN = settings.set_from_string(os.environ.get("REDASH_GOOGLE_APPS_DOMAIN", ""))
|
|
|
|
|
2015-12-01 13:44:08 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
migrator = PostgresqlMigrator(db.database)
|
|
|
|
|
|
|
|
with db.database.transaction():
|
|
|
|
Organization.create_table()
|
|
|
|
|
2016-01-03 14:05:29 +00:00
|
|
|
default_org = Organization.create(name="Default", slug='default', settings={
|
2016-10-05 14:15:46 +00:00
|
|
|
Organization.SETTING_GOOGLE_APPS_DOMAINS: list(GOOGLE_APPS_DOMAIN)
|
2015-12-01 13:44:08 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
column = Group.org
|
|
|
|
column.default = default_org
|
|
|
|
|
|
|
|
migrate(
|
|
|
|
migrator.add_column('groups', 'org_id', column),
|
|
|
|
migrator.add_column('events', 'org_id', column),
|
|
|
|
migrator.add_column('data_sources', 'org_id', column),
|
|
|
|
migrator.add_column('users', 'org_id', column),
|
|
|
|
migrator.add_column('dashboards', 'org_id', column),
|
|
|
|
migrator.add_column('queries', 'org_id', column),
|
|
|
|
migrator.add_column('query_results', 'org_id', column),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Change the uniqueness constraint on user email to be (org, email):
|
|
|
|
migrate(
|
|
|
|
migrator.drop_index('users', 'users_email'),
|
|
|
|
migrator.add_index('users', ('org_id', 'email'), unique=True)
|
|
|
|
)
|
|
|
|
|
|
|
|
db.close_db(None)
|