|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
3
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
4
|
|
|
# this work for additional information regarding copyright ownership. |
|
5
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
7
|
|
|
# the License. You may obtain a copy of the License at |
|
8
|
|
|
# |
|
9
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
# |
|
11
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
# See the License for the specific language governing permissions and |
|
15
|
|
|
# limitations under the License. |
|
16
|
|
|
|
|
17
|
|
|
import traceback |
|
18
|
|
|
|
|
19
|
|
|
from pymongo import ASCENDING |
|
20
|
|
|
|
|
21
|
|
|
from st2common import config |
|
22
|
|
|
from st2common import script_setup |
|
23
|
|
|
from st2common.models.db.actionalias import ActionAliasDB |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
INDEXES_TO_DROP = [ |
|
27
|
|
|
# Dropped after v1.4 |
|
28
|
|
|
(ActionAliasDB, 'name_%d' % ASCENDING) |
|
29
|
|
|
] |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
def remove_old_indexes(): |
|
33
|
|
|
for model, index_name in INDEXES_TO_DROP: |
|
34
|
|
|
collection = model._get_collection() |
|
35
|
|
|
try: |
|
36
|
|
|
print 'Dropping index "%s" from "%s"' % (index_name, collection.name) |
|
37
|
|
|
collection.drop_index(index_name) |
|
38
|
|
|
except: |
|
39
|
|
|
# maybe unnecessary but it is better to have this info to |
|
40
|
|
|
# begin with than not. |
|
41
|
|
|
traceback.print_exc() |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def main(): |
|
45
|
|
|
try: |
|
46
|
|
|
script_setup.setup(config, register_mq_exchanges=False) |
|
47
|
|
|
remove_old_indexes() |
|
48
|
|
|
finally: |
|
49
|
|
|
script_setup.teardown() |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
if __name__ == '__main__': |
|
53
|
|
|
main() |
|
54
|
|
|
|