default: &default
  adapter: mysql2
  encoding: utf8

development:
  <<: *default
  database: release_development
  username: release
  password: release
  url: <%= ENV['DATABASE_URL'] %>

test: &test
  <<: *default
  database: release_test
  username: release
  password: release
  url: <%= ENV["DATABASE_URL"].try(:sub, /([-_]development)?$/, '_test') %>

production:
  <<: *default
  # Rails reads values from DATABASE_URL env var.

default: &default
  adapter: mysql2
  encoding: utf8
  variables:
    sql_mode: TRADITIONAL

development:
  <<: *default
  database: release_development
  username: release
  password: release
  url: <%= ENV['DATABASE_URL'] %>

test: &test
  <<: *default
  database: release_test
  username: release
  password: release
  url: <%= ENV["DATABASE_URL"].try(:sub, /([-_]development)?$/, '_test') %>

production:
  <<: *default
  # Rails reads values from DATABASE_URL env var.

Use MySQL in 'traditional' mode
Use MySQL in 'traditional' mode

MySQL 5.7.5 introduced new behaviour around its
[handling of `GROUP BY` clauses][1]. This change resulted in some
previously valid SQL queries in Release to be deemed invalid and
trigger MySQL errors including this one:

```
Error:
\#per_year#test_: #per_year should return correct data. :
ActiveRecord::StatementInvalid: Mysql2::Error: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'release_test.deployments.created_at' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
    app/models/deployment_stats.rb:18:in `per_year'
    test/unit/deployment_stats_test.rb:53:in `block (2 levels) in <class:DeploymentStatsTest>'
    test/unit/deployment_stats_test.rb:39:in `instance_exec'
    test/unit/deployment_stats_test.rb:39:in `block in create_test_from_should_hash'
```

This change in behaviour can be reverted by setting the `sql_mode`
to `TRADITIONAL`, which is a special '[combination SQL mode][2]'
that excludes `ONLY_FULL_GROUP_BY`.

Some effort was made at first to refactor the problematic SQL queries
to avoid needing to deviate from MySQL's now-default behaviour. However,
the attempts were unsuccessful, and it is therefore more pragmatic to
follow the [convention established in Whitehall][3] to set the SQL
mode to 'traditional'.

[1]: https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html
[2]: https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sql-mode-combo
[3]: https://github.com/alphagov/whitehall/pull/6386
