Skip to content

Commit 971809b

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "db: Remove the legacy 'migration_version' table"
2 parents 6f79d63 + 2454843 commit 971809b

File tree

5 files changed

+93
-19
lines changed

5 files changed

+93
-19
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
"""Drop legacy migrate_version table
14+
15+
Revision ID: cdeec0c85668
16+
Revises: b30f573d3377
17+
Create Date: 2023-02-01 17:04:52.984703
18+
"""
19+
20+
from alembic import op
21+
from sqlalchemy.engine import reflection
22+
23+
# revision identifiers, used by Alembic.
24+
revision = 'cdeec0c85668'
25+
down_revision = 'b30f573d3377'
26+
branch_labels = None
27+
depends_on = None
28+
29+
30+
def upgrade():
31+
conn = op.get_bind()
32+
inspector = reflection.Inspector.from_engine(conn)
33+
tables = inspector.get_table_names()
34+
35+
if 'migrate_version' in tables:
36+
op.drop_table('migrate_version')

nova/db/main/api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4508,12 +4508,9 @@ def archive_deleted_rows(context=None, max_rows=None, before=None,
45084508
for table in meta.sorted_tables:
45094509
tablename = table.name
45104510
rows_archived = 0
4511-
# skip the special sqlalchemy-migrate migrate_version table and any
4512-
# shadow tables
4513-
# TODO(stephenfin): Drop 'migrate_version' once we remove support for
4514-
# the legacy sqlalchemy-migrate migrations
4511+
# skip the special alembic_version version table and any shadow tables
45154512
if (
4516-
tablename in ('migrate_version', 'alembic_version') or
4513+
tablename == 'alembic_version' or
45174514
tablename.startswith(_SHADOW_TABLE_PREFIX)
45184515
):
45194516
continue
@@ -4543,9 +4540,12 @@ def archive_deleted_rows(context=None, max_rows=None, before=None,
45434540

45444541

45454542
def _purgeable_tables(metadata):
4546-
return [t for t in metadata.sorted_tables
4547-
if (t.name.startswith(_SHADOW_TABLE_PREFIX) and not
4548-
t.name.endswith('migrate_version'))]
4543+
return [
4544+
t for t in metadata.sorted_tables if (
4545+
t.name.startswith(_SHADOW_TABLE_PREFIX) and not
4546+
t.name == 'alembic_version'
4547+
)
4548+
]
45494549

45504550

45514551
def purge_shadow_tables(context, before_date, status_fn=None):
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
"""Drop legacy migrate_version table
14+
15+
Revision ID: 1b91788ec3a6
16+
Revises: 960aac0e09ea
17+
Create Date: 2023-02-01 16:46:24.206580
18+
"""
19+
20+
from alembic import op
21+
from sqlalchemy.engine import reflection
22+
23+
# revision identifiers, used by Alembic.
24+
revision = '1b91788ec3a6'
25+
down_revision = '960aac0e09ea'
26+
branch_labels = None
27+
depends_on = None
28+
29+
30+
def upgrade():
31+
conn = op.get_bind()
32+
inspector = reflection.Inspector.from_engine(conn)
33+
tables = inspector.get_table_names()
34+
35+
if 'migrate_version' in tables:
36+
op.drop_table('migrate_version')

nova/tests/unit/db/api/test_migrations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ def get_metadata(self):
6262

6363
def include_object(self, object_, name, type_, reflected, compare_to):
6464
if type_ == 'table':
65-
# migrate_version is a sqlalchemy-migrate control table and
66-
# isn't included in the model.
67-
if name == 'migrate_version':
68-
return False
69-
7065
# Define a whitelist of tables that will be removed from the DB in
7166
# a later release and don't have a corresponding model anymore.
7267

@@ -196,6 +191,11 @@ def _check_b30f573d3377(self, connection):
196191
for removed_column in self._b30f573d3377_removed_columns:
197192
self.assertNotIn(removed_column, columns)
198193

194+
def _check_cdeec0c85668(self, connection):
195+
# the table optionally existed: there's no way to check for its
196+
# removal without creating it first, which is dumb
197+
pass
198+
199199
def test_single_base_revision(self):
200200
"""Ensure we only have a single base revision.
201201

nova/tests/unit/db/main/test_migrations.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ def get_metadata(self):
7979

8080
def include_object(self, object_, name, type_, reflected, compare_to):
8181
if type_ == 'table':
82-
# migrate_version is a sqlalchemy-migrate control table and
83-
# isn't included in the model. shadow_* are generated from
84-
# the model and have their own tests to ensure they don't
85-
# drift.
86-
if name == 'migrate_version' or name.startswith('shadow_'):
82+
# shadow_* are generated from the model and have their own tests to
83+
# ensure they don't drift.
84+
if name.startswith('shadow_'):
8785
return False
8886

8987
# Define a whitelist of tables that will be removed from the DB in
@@ -157,7 +155,6 @@ def test_innodb_tables(self):
157155
"FROM information_schema.TABLES "
158156
"WHERE TABLE_SCHEMA = :database "
159157
"AND ENGINE != 'InnoDB' "
160-
"AND TABLE_NAME != 'migrate_version'"
161158
),
162159
{'database': self.engine.url.database},
163160
)
@@ -281,6 +278,11 @@ def _check_960aac0e09ea(self, connection):
281278
connection, 'instances', 'uuid',
282279
)
283280

281+
def _check_1b91788ec3a6(self, connection):
282+
# the table optionally existed: there's no way to check for its
283+
# removal without creating it first, which is dumb
284+
pass
285+
284286
def test_single_base_revision(self):
285287
"""Ensure we only have a single base revision.
286288

0 commit comments

Comments
 (0)