Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-9918

Upgrading to 5.x fails if there are commit general comments in the DB

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Highest Highest
    • 5.2.2, 5.0.7, 5.1.5
    • 5.0.0, 5.1.0, 5.2.0
    • None
    • None

      When upgrading to Bitbucket Server 5.x the system will fail to migrate the schema if there are commit general comments in the DB.

      NOTE: Commit general comments are not a full feature of the system. There's no way (and there's never been a way) to create them or display them through the Bitbucket Server UI. However the REST and Java API allow for these comments to be created. Only customers who have used these APIs to create these comments will be affected by this bug.

      The new Comment API migration tasks introduced a new CommentThread entity to be at the root of a conversation and to tie all of its comments together. As part of the 5.0 DB migration tasks for each root comment a thread row is created in the bb_comment_thread table. All comments in the sta_comment table are then copied across to the new bb_comment table. However the tasks are missing a step to create threads for commit general comments so when the system tries to copy those comments across the foreign key from bb_comment to bb_comment_thread is violated and the upgrade fails.

      2017-07-03 15:28:58,425 ERROR [spring-startup]  liquibase classpath:liquibase/master.xml: liquibase/r5_0/upgrade.xml::BSERVDEV-8489-12::jpalacios: Change Set liquibase/r5_0/upgrade.xml::BSERVDEV-8489-12::jpalacios failed.  Error: ERROR: insert or update on table "bb_comment" violates foreign key constraint "fk_bb_comment_thread"
         Detail: Key (thread_id)=(12345) is not present in table "bb_comment_thread". [Failed SQL: insert into bb_comment (
                           id,
                           author_id,
                           comment_text,
                           created_timestamp,
                           entity_version,
                           thread_id,
                           updated_timestamp
                   )
                   select
                           id,
                           author_id,
                           comment_text,
                           created_timestamp,
                           entity_version,
                           id,
                           updated_timestamp
                   from sta_comment
                   where root_id is null]
      

            [BSERV-9918] Upgrading to 5.x fails if there are commit general comments in the DB

            Mathieu Mailhos added a comment - - edited

            Edit: after further investigation with Jira support team, this is unrelated.

             

            Mathieu Mailhos added a comment - - edited Edit: after further investigation with Jira support team, this is unrelated.  

            lonewulfster,

            The only other report we've had of this issue when attempting to upgrade to 5.2.2 had invalid data in their database tables. I'd recommend creating a support request so you can work with a support engineer to identify the data that's causing your upgrade to fail and remove it. When you create your request, please reference this issue. It'll help us get a jump on next steps.

            Best regards,
            Bryan Turner
            Atlassian Bitbucket

            Bryan Turner (Inactive) added a comment - lonewulfster , The only other report we've had of this issue when attempting to upgrade to 5.2.2 had invalid data in their database tables. I'd recommend creating a support request so you can work with a support engineer to identify the data that's causing your upgrade to fail and remove it. When you create your request, please reference this issue. It'll help us get a jump on next steps. Best regards, Bryan Turner Atlassian Bitbucket

            Artur Kurkov added a comment - - edited

            I think i have this problem on Bitbucket 5.2.2 and postgresql 9.5( after upgraded from v4.14.7)

            2017-8-01 13:37:59,241 WARN [spring-startup] o.s.w.c.s.XmlWebApplicationContext Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'crowdAliasDao': Unsatisfied dependency expressed through method 'setSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [stash-context.xml]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/r5_0/upgrade.xml::BSERVDEV-8489-12::jpalacios:
             Reason: liquibase.exception.DatabaseException: ERROR: insert or update on table "bb_comment" violates foreign key constraint "fk_bb_comment_thread"
             Detail: Key (thread_id)=(7986) is not present in table "bb_comment_thread". [Failed SQL: insert into bb_comment (
             id,
             author_id,
             comment_text,
             created_timestamp,
             entity_version,
             thread_id,
             updated_timestamp
             )
             select
             id,
             author_id,
             comment_text,
             created_timestamp,
             entity_version,
             id,
             updated_timestamp
             from sta_comment
             where root_id is null]
            
            

            Artur Kurkov added a comment - - edited I think i have this problem on Bitbucket 5.2.2 and postgresql 9.5( after upgraded from v4.14.7) 2017-8-01 13:37:59,241 WARN [spring-startup] o.s.w.c.s.XmlWebApplicationContext Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'crowdAliasDao' : Unsatisfied dependency expressed through method 'setSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [stash-context.xml]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/r5_0/upgrade.xml::BSERVDEV-8489-12::jpalacios: Reason: liquibase.exception.DatabaseException: ERROR: insert or update on table "bb_comment" violates foreign key constraint "fk_bb_comment_thread" Detail: Key (thread_id)=(7986) is not present in table "bb_comment_thread" . [Failed SQL: insert into bb_comment ( id, author_id, comment_text, created_timestamp, entity_version, thread_id, updated_timestamp ) select id, author_id, comment_text, created_timestamp, entity_version, id, updated_timestamp from sta_comment where root_id is null ]

            Server version: 5.5.30-log MySQL Community Server (GPL)

            Running the "SELECT c.id, ... " part of the query returns an empty set.

            Martin Wallgren added a comment - Server version: 5.5.30-log MySQL Community Server (GPL) Running the "SELECT c.id, ... " part of the query returns an empty set.

            I have the same error "Error: Field 'updated_timestamp' doesn't have a default value"
            Update from 5.1.2 to 5.2.1 failed

            Cloud Administrator added a comment - I have the same error "Error: Field 'updated_timestamp' doesn't have a default value" Update from 5.1.2 to 5.2.1 failed

            Martin,

            Just a small update. I was able to reproduce the issue with MariaDB 10.1 with STRICT_ALL_TABLES enabled. Not sure why I couldn't reproduce it with MySQL 5.7 and STRICT_ALL_TABLES. Either way, it's enough to do further verification on my end.

            Best regards,
            Bryan Turner
            Atlassian Bitbucket

            Bryan Turner (Inactive) added a comment - Martin, Just a small update. I was able to reproduce the issue with MariaDB 10.1 with STRICT_ALL_TABLES enabled. Not sure why I couldn't reproduce it with MySQL 5.7 and STRICT_ALL_TABLES . Either way, it's enough to do further verification on my end. Best regards, Bryan Turner Atlassian Bitbucket

            Martin,

            Can you share some details about your setup, like what database you're using and what version? Even if I enable STRICT_ALL_TABLES on MySQL 5.7, which was what I assumed your setup would be, I can't reproduce the insert failure unless there are rows being inserted.

            Best regards,
            Bryan Turner
            Atlassian Bitbucket

            Bryan Turner (Inactive) added a comment - Martin, Can you share some details about your setup, like what database you're using and what version? Even if I enable STRICT_ALL_TABLES on MySQL 5.7, which was what I assumed your setup would be, I can't reproduce the insert failure unless there are rows being inserted . Best regards, Bryan Turner Atlassian Bitbucket

            Martin Wallgren added a comment - - edited

            When upgrading from 5.2.0 to 5.2.1 the following error is logged. No comments have been added using API calls, only regular UI.

            2017-07-14 11:12:33,116 INFO [spring-startup] c.a.s.internal.ApplicationSettings Updated home version from 5.2.0 to 5.2.1
            2017-07-14 11:12:38,317 INFO [spring-startup] c.a.s.internal.home.HomeLockAcquirer Successfully acquired lock on home directory /var/atlassian/stash/shared
            2017-07-14 11:12:40,671 WARN [spring-startup] com.hazelcast.instance.Node [10.174.10.24]:5701 [atlassian] [3.7.4-atlassian-43] No join method is enabled! Starting standalone.
            2017-07-14 11:12:42,389 ERROR [spring-startup] liquibase Change Set liquibase/r5_0/upgrade.xml::BSERV-9918-1::jpalacios failed. Error: Field 'updated_timestamp' doesn't have a default value [Failed SQL: insert into bb_comment_thread (
            id,
            commentable_id,
            commentable_type,
            created_timestamp,
            entity_version
            )
            select
            c.id,
            discussion_activity.discussion_id,
            1,
            c.created_timestamp,
            0
            from sta_cmt_disc_comment_activity discussion_comment_activity
            inner join
            sta_cmt_disc_activity discussion_activity
            on discussion_comment_activity.activity_id = discussion_activity.activity_id
            inner join
            sta_comment c
            on discussion_comment_activity.comment_id = c.id
            where discussion_comment_activity.anchor_id is null and discussion_comment_activity.comment_action = 0]
            

            Martin Wallgren added a comment - - edited When upgrading from 5.2.0 to 5.2.1 the following error is logged. No comments have been added using API calls, only regular UI. 2017-07-14 11:12:33,116 INFO [spring-startup] c.a.s.internal.ApplicationSettings Updated home version from 5.2.0 to 5.2.1 2017-07-14 11:12:38,317 INFO [spring-startup] c.a.s.internal.home.HomeLockAcquirer Successfully acquired lock on home directory / var /atlassian/stash/shared 2017-07-14 11:12:40,671 WARN [spring-startup] com.hazelcast.instance.Node [10.174.10.24]:5701 [atlassian] [3.7.4-atlassian-43] No join method is enabled! Starting standalone. 2017-07-14 11:12:42,389 ERROR [spring-startup] liquibase Change Set liquibase/r5_0/upgrade.xml::BSERV-9918-1::jpalacios failed. Error: Field 'updated_timestamp' doesn't have a default value [Failed SQL: insert into bb_comment_thread ( id, commentable_id, commentable_type, created_timestamp, entity_version ) select c.id, discussion_activity.discussion_id, 1, c.created_timestamp, 0 from sta_cmt_disc_comment_activity discussion_comment_activity inner join sta_cmt_disc_activity discussion_activity on discussion_comment_activity.activity_id = discussion_activity.activity_id inner join sta_comment c on discussion_comment_activity.comment_id = c.id where discussion_comment_activity.anchor_id is null and discussion_comment_activity.comment_action = 0]

              jpalacios Juan Palacios (Inactive)
              jpalacios Juan Palacios (Inactive)
              Affected customers:
              1 This affects my team
              Watchers:
              17 Start watching this issue

                Created:
                Updated:
                Resolved: