If there are any clients connected to the DB, PostgreSQL won't let you
drop the database. It's possible that Sidekiq, Unicorn, or some other
client will be hanging onto a connection, preventing the DROP DATABASE
from working. To workaround this problem, this method cancels all the
connections so that the db:reset command will work.
Note that there's still a slight possibility a client connects after its
connection is terminated. If this is an issue, we could solve it by
revoking CONNECT access, but for now it seems this works.
Closes https://gitlab.com/gitlab-org/gitlab-development-kit/issues/450
Before this change, trying to setup dev environment could be tried
without having at least one Gitaly running. Cloning the repositories
would fail, but not stop the setup.
Given this would lead to an inconsistent state, a check was added if we
could connect to the server.
Output when it fails:
```
$ rake dev:setup
Failed to connect to Gitaly...
Error: 14:Connect Failed
```
Using db:reset ensures existing tables are first dropped. This in turn
ensures that we can drop tables regardless of any foreign key
constraints. While CE currently doesn't have any foreign keys EE defines
the following relation:
remote_mirrors.project_id -> projects.id
MySQL will complain whenever you try to drop the "projects" table first
even when using "DROP TABLE ... CASCADE".