1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 OpenStack LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
from sqlalchemy import Index, MetaData, Table
19
from sqlalchemy.exc import IntegrityError
22
def upgrade(migrate_engine):
24
meta.bind = migrate_engine
26
t = Table('instances', meta, autoload=True)
28
# Based on service_get_all_compute_sorted
29
# from: nova/db/sqlalchemy/api.py
30
i = Index('instances_host_deleted_idx',
31
t.c.host, t.c.deleted)
33
i.create(migrate_engine)
34
except IntegrityError:
37
# Based on instance_get_all_by_reservation
38
# from: nova/db/sqlalchemy/api.py
39
i = Index('instances_reservation_id_idx', t.c.reservation_id)
41
i.create(migrate_engine)
42
except IntegrityError:
45
# Based on instance_get_active_by_window
46
# from: nova/db/sqlalchemy/api.py
47
i = Index('instances_terminated_at_launched_at_idx',
48
t.c.terminated_at, t.c.launched_at)
50
i.create(migrate_engine)
51
except IntegrityError:
54
# Based on security_group_in_use
55
# from: nova/db/sqlalchemy/api.py
56
i = Index('instances_uuid_deleted_idx',
57
t.c.uuid, t.c.deleted)
59
i.create(migrate_engine)
60
except IntegrityError:
63
# Based on instance_get_all_hung_in_rebooting
64
# from: nova/db/sqlalchemy/api.py
65
i = Index('instances_task_state_updated_at_idx',
66
t.c.task_state, t.c.updated_at)
68
i.create(migrate_engine)
69
except IntegrityError:
73
def downgrade(migrate_engine):
75
meta.bind = migrate_engine
77
t = Table('instances', meta, autoload=True)
79
i = Index('instances_host_deleted_idx',
80
t.c.host, t.c.deleted)
81
i.drop(migrate_engine)
83
i = Index('instances_reservation_id_idx', t.c.reservation_id)
84
i.drop(migrate_engine)
86
i = Index('instances_terminated_at_launched_at_idx',
87
t.c.terminated_at, t.c.launched_at)
88
i.drop(migrate_engine)
90
i = Index('instances_uuid_deleted_idx',
91
t.c.uuid, t.c.deleted)
92
i.drop(migrate_engine)
94
i = Index('instances_task_state_updated_at_idx',
95
t.c.task_state, t.c.updated_at)
96
i.drop(migrate_engine)