Cannot delete a Stash repository due to 'HT_sta_pr_activity does not exist' error
症状
Delete repository action fails with a similar exception in the Stash logs:
2013-02-06 16:12:32,589 WARN [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 1044, SQLState: 42000
2013-02-06 16:12:32,590 ERROR [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper Access denied for user 'stash'@'10.1.3.32' to database 'stash'
2013-02-06 16:12:32,590 WARN [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 1146, SQLState: 42S02
2013-02-06 16:12:32,590 ERROR [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper Table 'stash.HT_sta_pr_activity' doesn't exist
2013-02-06 16:12:32,591 WARN [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 1051, SQLState: 42S02
2013-02-06 16:12:32,591 ERROR [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper Unknown table 'HT_sta_pr_activity'
2013-02-06 16:12:32,591 WARN [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" o.h.h.s.TemporaryTableBulkIdStrategy unable to drop temporary id table after use [Unknown table 'HT_sta_pr_activity']
2013-02-06 16:12:32,629 ERROR [http-bio-7990-exec-226] <username> 972x1856x1 1oyb6d9 10.41.5.17,127.0.0.1 "DELETE /projects/SANDBOX/repos/random HTTP/1.1" c.a.e.i.AsynchronousAbleEventDispatcher There was an exception thrown trying to dispatch event 'com.atlassian.stash.event.RepositoryDeletionRequestedEvent[source=com.atlassian.stash.internal.repository.RepositoryStateManagerImpl@71bf6746]' from the invoker 'SingleParameterMethodListenerInvoker{method=public void com.atlassian.stash.internal.pull.PullRequestRescopeListener.onRepositoryDeleteRequested(com.atlassian.stash.event.RepositoryDeletionRequestedEvent), listener=com.atlassian.stash.internal.pull.PullRequestRescopeListener@63b8dba5}'.
java.lang.RuntimeException: A database error has occurred.
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'stash.HT_sta_pr_activity' doesn't exist
at sun.reflect.GeneratedConstructorAccessor447.newInstance(Unknown Source) ~[na:na]
原因
'stash.HT_sta_pr_activity' is not a table created by Stash.
As per this blog, this behaviour is related to temporary tables Hibernate creates (or is supposed to create) for some operations around the inheritance hierarchy for activity tables. That suggests that the user Stash is using to connect to MySQL does not have the right permissions. Specifically, from MySQL's reference:
Temporary Tables
You can use the TEMPORARY keyword when creating a table. A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed. This means that two different connections can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.) To create temporary tables, you must have the CREATE TEMPORARY TABLES privilege.
さらなるトラブルシューティング
Use the Show Grants command to confirm the permissions for the Stash user and ensure they have the CREATE TEMPORARY TABLES permission on the Stash database.
ソリューション
To create temporary tables, you must have the CREATE TEMPORARY TABLES privilege. Ensure'GRANT ALL PRIVILEGES
' has been used when creating the Stash database as mentioned in the MySQL setup guide.