sql-server – 无法执行从SonarQube 5.6.1 LTS到6.0的数据库迁移

前端之家收集整理的这篇文章主要介绍了sql-server – 无法执行从SonarQube 5.6.1 LTS到6.0的数据库迁移前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我最近尝试从SonarQube 5.6.1 LTS升级到6.0.

我使用了升级指南但是我遇到了数据库迁移错误.

Fail to execute database migration: org.sonar.db.version.v60.CleanUsurperRootComponents
com.microsoft.sqlserver.jdbc.sqlServerException: Cannot resolve the collation conflict between “sql_Latin1_General_CP1_CS_AS” and “Latin1_General_CS_AS” in the equal to operation.

我正在使用sql 2014和sql_Latin1_General_CP1_CS_AS.

我用于设置以下指南:

SonarQube Setup Gruide for .Net Users v.1.3

Sonar数据库中有157列具有错误的归类“Latin1_General_CS_AS”.

问候

丹尼尔

解决方法

选项1:从一个新的空数据库开始.

选项2:在再次开始升级之前,使用sql Management Studio还原SonarQube数据库并更改数据库归类(假设数据库名为SonarQube):

-- Show current collation
 USE [master]
 GO

 SELECT [collation_name]
 FROM   [sys].[databases]
 WHERE  name = 'SonarQube'
 GO

结果应该是Latin1_General_CS_AS.如果查询返回sql_Latin1_General_CP1_CS_AS,请在升级到6.0之前更改数据库排序规则:

USE [master]
GO

ALTER DATABASE [SonarQube] SET SINGLE_USER WITH ROLLBACK IMMEDIATE    
ALTER DATABASE [SonarQube] COLLATE Latin1_General_CS_AS;  
ALTER DATABASE [SonarQube] SET MULTI_USER
GO

选项3 :(最后的手段)更改数据库排序规则(请参阅选项2)并手动更改数据库(使用sql Management Studio).首先执行以下查询

USE [SonarQube]
GO

SELECT  '[' + SCHEMA_NAME(t.[schema_id]) + '].[' + t.[name] + '] -> ' + c.[name],'ALTER TABLE [' + SCHEMA_NAME(t.[schema_id]) + '].[' + t.[name] + ']
          ALTER COLUMN [' + c.[name] + '] ' + UPPER(tt.name) + 
         CASE WHEN t.name NOT IN ('ntext','text') 
             THEN '(' + 
                 CASE 
                     WHEN tt.name IN ('nchar','nvarchar') AND c.max_length != -1 
                         THEN CAST(c.max_length / 2 AS VARCHAR(10))
                     WHEN tt.name IN ('char','varchar') AND c.max_length != -1 
                         THEN CAST(c.max_length AS VARCHAR(10))
                     WHEN tt.name IN ('nchar','nvarchar','char','varchar') AND c.max_length = -1 
                         THEN 'MAX'
                     ELSE CAST(c.max_length AS VARCHAR(10)) 
                 END + ')' 
             ELSE '' 
         END + ' COLLATE Latin1_General_CS_AS' + 
         CASE WHEN c.[is_nullable] = 1 
             THEN ' NULL'
             ELSE ' NOT NULL'
         END
 FROM  [sys].[columns] c
 JOIN  [sys].[tables]  t ON c.[object_id] = t.[object_id]
 JOIN  [sys].[types]   tt ON c.[system_type_id] = tt.[system_type_id] AND c.[user_type_id] = tt.[user_type_id]
 WHERE c.[collation_name] IS NOT NULL
 AND   c.[collation_name] != 'Latin1_General_CS_AS'
 AND   t.[type] = 'U'
 GO

这将返回几行;例如:

ALTER TABLE [dbo].[resource_index] 
ALTER COLUMN [root_component_uuid] NVARCHAR(50) COLLATE Latin1_General_CS_AS NOT NULL

某些列无法以这种方式更改,因为该列用于必须首先删除的索引.例如:

-- Pay attention: generate script first!
DROP INDEX [resource_index_component] ON [dbo].[resource_index]
GO

ALTER TABLE [dbo].[resource_index] 
ALTER COLUMN [component_uuid] NVARCHAR(50) COLLATE Latin1_General_CS_AS NOT NULL
GO

-- Generate the create script in sql Management Studio...
CREATE NONCLUSTERED INDEX [resource_index_component] 
  ON [dbo].[resource_index] ([component_uuid] ASC) 
  WITH (...) ON ...
GO

重新启动SonarQube并再次开始升级.

原文链接:https://www.f2er.com/mssql/84243.html

猜你在找的MsSQL相关文章