2016-01-08 18:44:11 +00:00
|
|
|
from redash.models import db
|
2016-01-11 09:30:26 +00:00
|
|
|
import peewee
|
2016-01-08 18:44:11 +00:00
|
|
|
from playhouse.migrate import PostgresqlMigrator, migrate
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
migrator = PostgresqlMigrator(db.database)
|
|
|
|
|
|
|
|
with db.database.transaction():
|
|
|
|
# Change the uniqueness constraint on data source name to be (org, name):
|
2016-01-15 15:53:11 +00:00
|
|
|
# In some cases it's a constraint:
|
|
|
|
db.database.execute_sql('ALTER TABLE data_sources DROP CONSTRAINT IF EXISTS unique_name')
|
|
|
|
# In others only an index:
|
|
|
|
db.database.execute_sql('DROP INDEX IF EXISTS data_sources_name')
|
2016-01-11 09:30:26 +00:00
|
|
|
|
2016-01-08 18:44:11 +00:00
|
|
|
migrate(
|
|
|
|
migrator.add_index('data_sources', ('org_id', 'name'), unique=True)
|
|
|
|
)
|
|
|
|
|
|
|
|
db.close_db(None)
|