Skip to content

Commit

Permalink
Add doc for running plots2 with MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefanni committed Sep 25, 2018
1 parent 4610d1f commit 52ee7ea
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion doc/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Client-side tests (for JavaScript functions) are run using [teaspoon-mocha](http

****

If you get stuck on testing at any point, you can _open a pull request with your changes_ -- please add the prefix `[testing]` to the title -- which will then be automatically tested by our TravisCI service -- which runs **all tests**. If your additions are pretty basic, and you write tests against them, this may be sufficient without actually running the whole environment yourself!
If you get stuck on testing at any point, you can _open a pull request with your changes_ -- please add the prefix `[testing]` to the title -- which will then be automatically tested by our TravisCI service -- which runs **all tests**. If your additions are pretty basic, and you write tests against them, this may be sufficient without actually running the whole environment yourself!

## Running just one type of test

Expand Down Expand Up @@ -68,3 +68,83 @@ them to production.
If you need to use the stable or the unstable branch,
please ask in the chatroom (https://publiclab.org/chat) if someone else is
already using it.

## How to run plots2 with MySQL on development and test environments

In development and test environments, the project uses SQLite3, but in production
it uses [MySQL](https://github.com/publiclab/plots2/blob/master/containers/docker-compose-production.yml).

If you need to test something that SQLite3 doesn't support, like a full-text
search, for example, you need to add more steps to your configuration:

1 - Install MySQL on your machine;
2 - Update your `mysql` group on Gemfile to:

```
group :mysql, :production, :development, :test do
gem 'mysql2', '>= 0.4.4'
# mysql 0.4.3+ causes a version mismatch, apparently, and demands 'activerecord-mysql2-adapter'
end
```

3 - Comment this group:

```
group :sqlite, :development do
gem 'sqlite3'
end
```

4 - Copy the file `config/database.yml.mysql.example` to your `config/database.yml`
You may need to add a password and a username. If you don't remember them when
you installed MySQL, run `mysql_secure_installation` to set a new password.

You may also need to create a database, it depends on which OS you're using.

This is an example of a config/database.yml file after those steps:

```
development:
adapter: mysql2
encoding: utf8
pool: 5
username: yourusername
password: yourpassword
database: plots2_development
strict: false
production:
adapter: mysql2
encoding: utf8
pool: 5
username: yourusername
password: yourpassword
database: plots2_production
test:
adapter: mysql2
encoding: utf8
pool: 5
username: yourusername
password: yourpassword
database: plots2_test
strict: false
```

5 - Run `bundle install`

6 - Run rake `db:setup`

If everything run smoothly, this will avoid some weird errors (like passing the
tests locally but not on travis). Remember *not to add* those to your commits.

## Tests with MySQL features

It may be a good practice to add the tests that use MySQL features in a different
file and use a skip method for SQLite3 adapter:

`skip "full text search only works on mysql/mariadb" if ActiveRecord::Base.connection.adapter_name == 'sqlite3'`

Check this test [search_service_full_text_search_test.rb](https://github.com/publiclab/plots2/blob/master/test/unit/api/search_service_full_text_search_test.rb) for more details.

This way we don't have errors either using SQLite3 or MySQL.

0 comments on commit 52ee7ea

Please sign in to comment.