mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
migrate.py: Add function for conditionally creating an index
(imported from commit f0ca7cc83e334d4210d21d33afa2e0196172176e)
This commit is contained in:
@@ -65,3 +65,15 @@ def add_bool_columns(db, table, cols):
|
||||
stmt = ('ALTER TABLE %s ' % (table,)) \
|
||||
+ ', '.join(['ALTER %s SET NOT NULL' % (col,) for col in cols])
|
||||
timed_ddl(db, stmt)
|
||||
|
||||
def create_index_if_nonexistant(db, table, col, index):
|
||||
validate(table)
|
||||
validate(col)
|
||||
validate(index)
|
||||
test = """SELECT relname FROM pg_class
|
||||
WHERE relname = %s"""
|
||||
if len(db.execute(test, params=[index])) != 0:
|
||||
print "Not creating index '%s' because it already exists" % (index,)
|
||||
else:
|
||||
stmt = "CREATE INDEX %s ON %s (%s)" % (index, table, col)
|
||||
timed_ddl(db, stmt)
|
||||
|
||||
Reference in New Issue
Block a user