Confluence upgrade on SQL Server fails due to 'execute could not complete schema update' error

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

問題

Confluence upgrade fails and the an error message similar to the following appears in atlassian-confluence.log

ERROR [main] [hibernate.tool.hbm2ddl.SchemaUpdate] execute Unsuccessful: alter table SPACEPERMISSIONS add constraint FK_SPACEPERMISSIONS_CREATOR foreign key (CREATOR) references user_mapping
ERROR [main] [hibernate.tool.hbm2ddl.SchemaUpdate] execute Column 'user_mapping.user_key' is not the same data type as referencing column 'SPACEPERMISSIONS.CREATOR' in foreign key 'FK_SPACEPERMISSIONS_CREATOR'.
ERROR [main] [hibernate.tool.hbm2ddl.SchemaUpdate] execute could not complete schema update
java.sql.SQLException: Column 'user_mapping.user_key' is not the same data type as referencing column 'SPACEPERMISSIONS.CREATOR' in foreign key 'FK_SPACEPERMISSIONS_CREATOR'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)

診断

環境

  • Microsoft SQL Server

原因

To provide support for Unicode characters in Microsoft SQL Server, Confluence uses and expects nchar, nvarchar, and ntext column data types for certain tables. This error is caused when Confluence expects the column data type to be nchar, nvarchar, or ntext but sees a different data type.

ソリューション

Automated method using XML Backup/Restore functionality

Click here to expand the automated method...
  1. Follow these instructions from Manually Backup the Site to create an XML site backup
    Manually Backup the Site
    1. Go to  > General Configuration > Backup & Restore
    2. Choose Also save a copy to the backups directory to store a copy of the backup in the same folder as Confluence's backups
      If you do not archive the backup it will be made available for you to download, and then deleted from the server after 24 hours
    3. [添付ファイルを含める] を選択し、添付ファイルをバックアップに含めます。
    4. Choose Export
      The process can take some time

    一時ディレクトリを消去スケジュール ジョブによって /temp ディレクトリのコンテンツが毎日午後 4 時に削除されて、エクスポートしたファイルも削除されるため、サイトの規模が大きい場合はこのジョブを一時的に無効にする必要があります。エクスポートが完了したら、このジョブを再度有効にする必要があります。

  2. Create a new SQL Server database configured as described in Database Setup for SQL Server
  3. Confluence を停止します。
  4. Rename or move the existing <confluence-home> folder (The <confluence_home> directory is the path defined in the following file: <confluence_install>/confluence/WEB-INF/classes/confluence-init.properties)
  5. Start Confluence and follow the setup wizard to create an empty site
  6. Follow these instructions from Restoring a Site to restore the XML backup

    サイトを復元する
    小規模サイトをアップロードし、インポートするには、
    1.  > 一般設定 > バックアップと復元に移動します。 
    2. [サイトまたはスペースのエクスポート ファイルのアップロード] で、[ファイルの選択] をクリックし、スペース エクスポート ファイルを参照します。
    3. あとのステージでインデックスを作成する場合、インデックス作成 のチェックを外します。
    4. [アップロードとインポート] を選択します。

    ホーム ディレクトリからサイトをインポートするには、次の手順を実行します。 

    1. エクスポート ファイルを <confluence-home>/restore. 
       にコピーします。
      (このディレクトリが置かれている場所がわからない場合は、バックアップと復元 画面にパスが一覧表示されています)
    2.  > 一般設定 > バックアップと復元に移動します。 
    3. [ホーム ディレクトリからインポート] で、サイト エクスポート ファイルを選択します。
    4. あとのステージでインデックスを作成する場合、インデックス作成 のチェックを外します。
    5. インポートを選択します。

Manual method using SQL Server database tools

Click here to expand manual method...

データベースの変更を行う場合は必ず事前にバックアップを取得してください。可能な場合は、まずステージング サーバーで SQL コマンドの変更、挿入、更新、または削除を行うようにします。

Ensure that you are using the correct collation for your product. The following examples use the collation of SQL_Latin1_General_CP1_CS_AS. The collation required by your application version may be different. See the "Setup Guides for Microsoft SQL Server" section above for more information about your product and version.

  1. Stop Confluence (all following steps are in SQL Server Management Studio)

  2. Identify any fields that have the datatype varcharchar, or text

    select distinct object_name(object_id) from sys.columns
    where system_type_id in (35,167,175)
    and OBJECT_NAME(object_id) not like 'sys%'
    order by 1;
  3. Create a new SQL Server database configured as described in Database Setup for SQL Server

  4. Create a script to recreate the database tables
    1. Right click the old database in Object Explorer
    2. Click Tasks > Generate Scripts...
    3. If prompted select the current Confluence database
    4. On the Choose Scripting Options adjust the following options:
      1. Set Script USE DATABASE to false
      2. Set Script Full-Text Indexes to true
      3. Set Script Indexes to true
    5. In the Choose Objects Types screen, tick Tables
    6. In the Choose Tables screen, click Select All; click Next
    7. In the Output Option screen, click Script to file; click Finish
  5. Open the resulting file in a text editor and use find and replace to change varcharchar, and text to nvarcharnchar, and ntext
    1. Ensure you use the full words in find and replace, so you don't accidentally end up with values like 'nvarnchar' 
  6. Run the edited script file against the new Confluence database we created in Step 3 to populate the schema
    1. Select the new Confluence database in the Available Database dropdown
    2. Click File Open > File
    3. Select the script from the picker
    4. Click Execute
  7. Disable constraint checks before importing data
    1. Execute the following query against the new Confluence database

      EXEC sp_MSforeachtable"ALTER TABLE ? NOCHECK CONSTRAINT all"
  8. Import data from the old Confluence database into the new database
    1. Right click the old database in Object Explorer
    2. Click Tasks > Export Data... 
    3. In the Choose a Data Source screen, select the old database from the dropdown; click Next
    4. In the Choose a Destination screen, enter the server name you will be connecting to (this will most likely be the same as the original server) and select the new database from the dropdown; click Next
    5. Select Copy data from one or more tables or views; click Next
    6. In the Select Source Tables and Views screen, tick the top left box to select all tables; click Edit Mappings
    7. Ensure the Destination schema name is correct (this should most likely be set to dbo) and tick the Enabled identity insert; click OK
    8. Click Next
    9. In the Run Package screen, ensure Run immediately is ticked and click Finish
      • Depending on the size of the database, and the speed of the database server(s) being used, this process will take time
  9. Re-enable the constraint check after importing data
    1. Execute the following query against the new Confluence database to confirm all affected columns have been changed

      EXEC sp_MSforeachtable"ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
  10. Confluence を起動します。
最終更新日 2018 年 11 月 2 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.