Bitbucket Server Upgrade to 2.4.0 Fails with "Specified key was too long" Exception

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

The following exception is reported when upgrading Bitbucket Server to 2.4.x

2013-05-07 16:38:30,539 INFO  [localhost-startStop-1]  c.a.s.internal.home.HomeLockAcquirer Successfully acquired lock on home directory /home/www/data/bitbucket/instance for 158926@STASHSERVER
2013-05-07 16:38:34,276 ERROR [localhost-startStop-1]  liquibase Change Set liquibase/r2_4/upgrade.xml::BSERVDEV-3734-4::mstudman failed.  Error: Error executing SQL ALTER TABLE `bitbucket`.`bitbucket_user` ADD CONSTRAINT `uq_bitbucket_user_slug` UNIQUE (`slug`): Specified key was too long; max key length is 767 bytes
liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE `bitbucket`.`bitbucket_user` ADD CONSTRAINT `uq_bitbucket_user_slug` UNIQUE (`slug`): Specified key was too long; max key length is 767 bytes
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62) ~[liquibase-core-2.0.5.jar:na]
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:104) ~[liquibase-core-2.0.5.jar:na]
	at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1091) ~[liquibase-core-2.0.5.jar:na]
	at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:1075) ~[liquibase-core-2.0.5.jar:na]
	at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317) ~[liquibase-core-2.0.5.jar:na]
	at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27) [liquibase-core-2.0.5.jar:na]
	at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58) [liquibase-core-2.0.5.jar:na]
	at liquibase.Liquibase.update(Liquibase.java:114) [liquibase-core-2.0.5.jar:na]

Further Troubleshooting

Use a database viewer, such as DBVisualizer to connect to your current Bitbucket Server database and run the following query:

run desc bitbucket_user;

This will give an output similar to:

mysql> desc bitbucket_user;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(11)      | NO   | PRI | NULL    |       |
| name  | varchar(255) | NO   | UNI | NULL    |       |
| slug  | varchar(255) | NO   |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

This will help confirm the table schema for 'bitbucket_user' table.

Cause

If the result of the above query does not match the expected result above but is instead:

mysql> desc bitbucket_user;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(11)      | NO   | PRI | NULL    |       | 
| name  | varchar(255) | NO   | UNI | NULL    |       | 
| slug  | varchar(766) | NO   | UNI | NULL    |       | 
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

it indicates that the above schema is from the Bitbucket Server 2.4 beta, not the final official release. This can happen if Bitbucket Server was upgraded to the 2.4 beta (or attempted to) and then to 2.4 stable release.The schema in 2.4.0 and 2.4.1 is 255 characters for slug - only the beta release used 766.

The Bitbucket Server upgrade task wasn't designed to upgrade from the beta to a final release, so it will take some manual SQL to help resolve it.

Resolution

Run the following query on your Bitbucket Server database:

UPDATE DATABASECHANGELOG SET ID = 'BSERVDEV-3734-4', MD5SUM = '3:0915ae71248292c6cc8c73d79b6a5cc4' WHERE ID = 'BSERVDEV-3734-5';

and restart Bitbucket Server to complete the upgrade.

Last modified on Nov 2, 2018

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.