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 Back up a Site to create an XML site backup
    サイトをバックアップする
    1. [管理] > [一般設定] > [バックアップとリストア] に移動します。
    2. [サイトまたはスペースをバックアップ] を選択します。
    3. [バックアップを作成] 画面で、次の手順を実行します。
      1. [サイト] を選択します。
      2. XML エクスポートにファイル名のプレフィックスを付けます。Confluence によって、このファイル名の末尾にタイムスタンプと一意の識別子が追加されます。このフィールドを空白のままにすると、既定のプレフィックスとタイムスタンプがファイルに割り当てられます (例: Confluence-site-export-2015-04-14-11-07-36-639.xml.zip)。
      3. ファイルを <confluence-home>/restore/site フォルダに残しておく場合は、[永続的に保存] を選択します。これを選択しない場合、既定ではストレージ容量を維持するため 72 時間後にバックアップが削除されます。confluence.backuprestore.backup.ttl-in-hours システム プロパティを設定することで、この保管時間を変更できます。その方法については、「システム プロパティの設定」を参照してください。
      4. 添付ファイルをバックアップに含めるには、[添付ファイルを含める] を選択します。
    4. [バックアップ] を選択します。
    5. 確認メッセージが表示されるので、[今すぐバックアップ] を選択してタスクを開始します。

    大規模なサイトの場合、このプロセスには時間がかかることがあります。

  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

    サイトを復元する

    バックアップを以前のバージョンの Confluence に復元することはできません。 

    たとえば、Confluence 8.3 で XML バックアップが生成された場合、これを Confluence 7.19 にインポートすることはできません。


    バックアップを正常に復元できるかどうかを確認するには、次の操作を実行します。

    • [管理] > [一般設定] > [システム情報] で、使用している Confluence のバージョンを確認します。バージョンは [Confluence バージョン] の横に表示されます。
    • XML バックアップが生成された Confluence バージョンを確認します。「XML バックアップの Confluence バージョンを確認する方法」を参照してください。

    (tick) バックアップを新しいバージョンに復元する場合、バックアップを正常に復元できます。

    (error) バックアップを以前のバージョンに復元する場合、この操作はサポートされていないため、インポートに失敗する可能性があります。

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.