forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0017_add_organization.py
34 lines (27 loc) · 1.24 KB
/
0017_add_organization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from redash.models import db, Organization, Group
from redash import settings
from playhouse.migrate import PostgresqlMigrator, migrate
if __name__ == '__main__':
migrator = PostgresqlMigrator(db.database)
with db.database.transaction():
Organization.create_table()
default_org = Organization.create(name="Default", slug='default', settings={
Organization.SETTING_GOOGLE_APPS_DOMAINS: list(settings.GOOGLE_APPS_DOMAIN)
})
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)