DBMigration failed 7.9.1 -> 8.5.1

So I tried to upgrade our version of SonarQube from version 7.9.1 to version 8.5.1, and got stuck on the first migration:

2020.12.03 17:51:19 INFO  web[][DbMigrations] Executing DB migrations...
2020.12.03 17:51:19 INFO  web[][DbMigrations] #3000 'Set Organizations#guarded column nullable'...
2020.12.03 17:51:19 ERROR web[][DbMigrations] #3000 'Set Organizations#guarded column nullable': failure | time=50ms
2020.12.03 17:51:19 ERROR web[][DbMigrations] Executed DB migrations: failure | time=52ms
2020.12.03 17:51:19 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=288ms
2020.12.03 17:51:19 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration ended with an exception
org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #3000 'Set Organizations#guarded column nullable' failed
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)
	at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)
	at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:68)
	at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)
	at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Fail to execute ALTER TABLE organizations ALTER COLUMN guarded BIT NULL
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:106)
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:86)
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:128)
	at org.sonar.server.platform.db.migration.version.v80.MakeOrganizationsGuardedNullable.execute(MakeOrganizationsGuardedNullable.java:39)
	at org.sonar.server.platform.db.migration.step.DdlChange.execute(DdlChange.java:45)
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
	... 9 common frames omitted
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot find the object "organizations" because it does not exist or you do not have permissions.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1624)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:868)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:768)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2979)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:744)
	at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:194)
	at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:194)
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:91)
	... 14 common frames omitted

Setup:
Windows Server 2019
SQL Server 2019
Running as Windows Service.

I’m happy to provide any more information if it is needed.

Hello @emiltorp,

Could you double check if organizations table exist in the database you are using?

Also this is the very first migration of 8.X version, so it is very likely that database you have configured via jdbc properties is incorrect.

Yup, that table exists. It has only one entry (Default Organization) and the guarded column is set to 1

And below is my jdbc properties, which looks fine according to the examples in the provided sonar.properties. That is all jdbc properties I have enabled.

sonar.jdbc.username=****
sonar.jdbc.password=****
sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonarqube

But it is possible that the database is not in “correct state”. We started with version 5.* a few years back and have migrated a couple of times since then.

I’m unsure if it is possible (I will check that, but it will take some time).

In order to achieve such state you would have to skip version: 6.2 of SQ, do you mind sharing schema_migrations content? The organization table has been created in migration number: 1400.

What was your usual path of upgrade?

Unfortunately I don’t remember the exact version. But I think it was like 5.6 -> 6.5 -> 6.7 -> 7.0 -> 7.1 -> … 7.9.1 (I think we did every 7 version)

Here are my dbo.schema_migrations, and 1400 is in there. So it is created.

1
10
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1017
11
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1150
1151
1152
131
14
140
151
163
169
2
200
202
211
215
217
220
222
235
237
238
239
252
257
283
285
286
300
301
320
35
350
351
353
354
355
356
358
370
387
388
391
392
398
399
401
404
405
410
411
412
413
414
415
416
417
418
419
432
433
434
441
442
460
461
463
464
465
467
480
483
486
488
492
510
511
520
53
530
532
533
535
536
538
540
541
542
544
545
548
549
552
555
580
581
59
600
601
603
604
605
61
62
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
750
752
753
754
755
756
758
759
760
761
762
763
764
765
766
768
769
770
771
772
773
775
776
777
778
779
780
781
782
783
784
786
787
788
789
79
790
791
792
793
794
795
796
80
86
87
88
900
901
902
903
904
905
906
907
908
912
913
915
916
917
918
919
920
921
922
923
924
925
926
927
929
93
930
931
932
933
934
935
936
937
938
939
940
941
95
1153
1200
1205
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1246
1247
1248
1249
1250
1251
1252
1253
1254
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1300
1301
1302
1303
1304
1307
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1814
1830
1831
1832
1833
1834
1835
1836
1837
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2300
2301
2302
2303
2304
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2400
2401
2402
2403
2404
2500
2501
2502
2503
2504
2505
2506
2507
2508
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2700
2701
2702
2703
2704
2705
2706
2707
2708
2800
2801
2802
2803
2804

Also, this was the first time I saw a schema migration fail. And I have done all the upgrades since 5.6

Okay, so it seems your data in DB is correct.

Could you check if your db user which is used in jdbc connection has a proper permissions to alter that table?

Of course that was the issue. I migrated a backup from an old server to this new server where we will run SonarQube from now on. Put db_datareader and db_datawriter and it started on 7.9.1 just fine so I didn’t think of it.

Now I added db_owner to that account and the migrations went just fine (took about 20 minutes). So this is a case of me not reading the manual completely…

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.