Browse Source

Fix db migration for mariadb >= 10.2.8

Starting with mariadb 10.2.8, removing a column
that is part of a primary key requires that the
primary key constraint be dropped and recreated.

Change-Id: I43e4dae325dd6561a9fe0fd4ce595cea4c2ef7a6
Closes-Bug: #1749184
(cherry picked from commit 2beb7ac13a)
Stefan Nica 1 year ago
parent
commit
4a40da15fe

+ 7
- 0
manila/db/migrations/alembic/versions/e8ea58723178_remove_host_from_driver_private_data.py View File

@@ -38,10 +38,17 @@ COLUMN_HOST = 'host'
38 38
 DEFAULT_HOST = 'unknown'
39 39
 COLUMN_ENTITY = 'entity_uuid'
40 40
 COLUMN_KEY = 'key'
41
+MYSQL_ENGINE = 'mysql'
41 42
 
42 43
 
43 44
 def upgrade():
45
+    bind = op.get_bind()
46
+    engine = bind.engine
44 47
     try:
48
+        if (engine.name == MYSQL_ENGINE):
49
+            op.drop_constraint('PRIMARY', TABLE_NAME, type_='primary')
50
+            op.create_primary_key('DRIVERS_PRIVATE_PK', TABLE_NAME,
51
+                                  ['entity_uuid', 'key'])
45 52
         op.drop_column(TABLE_NAME, COLUMN_HOST)
46 53
     except Exception:
47 54
         LOG.error("Column '%s' could not be dropped", COLUMN_HOST)

+ 5
- 0
releasenotes/notes/bug-1749184-eb06929e76a14fce.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+fixes:
3
+  - The database migration has been adjusted to work with mariadb >= 10.2.8
4
+    by ensuring that a primary key constraint is first dropped and re-added
5
+    when a column is removed that is part of it

Loading…
Cancel
Save