Skip to content
  • Richard Clamp's avatar
    Extract BasePgHelper#extension_can_be_enabled? · f7b296d6
    Richard Clamp authored
    When gitlab_rails['enable'] = false, the database won't be created for
    the load to happen, causing an error from the
    postgresql_extension[pg_trgm] resource:
    
      postgresql_extension[pg_trgm] (gitlab::postgresql line 213) had an error: Mixlib::ShellOut::ShellCommandFailed: postgresql_query[enable pg_trgm extension] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/postgresql/resources/extension.rb line 6) had an error: Mixlib::ShellOut::ShellCommandFailed: execute[enable pg_trgm extension (gitlab-psql)] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/postgresql/resources/query.rb line 11) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '2'
      ---- Begin output of /opt/gitlab/bin/gitlab-psql -d gitlabhq_production -c "CREATE EXTENSION IF NOT EXISTS pg_trgm" ----
      STDOUT:
      STDERR: psql: FATAL:  database "gitlabhq_production" does not exist
      ---- End output of /opt/gitlab/bin/gitlab-psql -d gitlabhq_production -c "CREATE EXTENSION IF NOT EXISTS pg_trgm" ----
      Ran /opt/gitlab/bin/gitlab-psql -d gitlabhq_production -c "CREATE EXTENSION IF NOT EXISTS pg_trgm" returned 2
    
    Looking at the postgresql_extension LWRP we see that the logic around
    whether to enable the extension is a quite hairy not_if expression,
    which is hard to follow and debug.  To improve this here we extract the
    existing BasePgHelper#extension_can_be_enabled? and use that to simplify
    the flow of the `postgresql_extension` LWRP and `recipes/postgresql_spec`
    f7b296d6