UNPKG

6.46 kBMarkdownView Raw
1## How to contribute to Bookshelf.js
2
3* Before sending a pull request for a feature or bug fix, be sure to have
4[tests](https://github.com/tgriesser/bookshelf/tree/master/test).
5
6* Use the same coding style as the rest of the
7[codebase](https://github.com/tgriesser/bookshelf/blob/master/src/bookshelf.js).
8
9* Make changes in the /src directory, running "npm run dev" which will kick off
10transpilation from ES6 in the background.
11
12* All pull requests should be made to the `master` branch.
13
14### Development Environment Setup
15
16You'll need to have `git` installed obviously. Begin by forking the [main
17 repository](https://github.com/tgriesser/bookshelf) and then getting the code from your forked copy:
18
19```sh
20$ git clone git@github.com:yourusername/bookshelf.git
21```
22
23Afterwards go to the bookshelf directory that was just created and install the dependencies:
24
25```sh
26$ npm install
27```
28
29At this point the only thing missing are the databases that will be used for running some of the tests of the automated
30test suite.
31
32There are two options for setting up this part. The first one is to change some configuration options of the database
33servers and the other is to use a config file in case you already have your servers configured and don't want to change
34any of their config files. The first two sections below deal with the first option and then there are instructions on
35how to use the other option.
36
37#### MySQL
38
39You can install [MySQL](https://www.mysql.com/) easily on most linux distros by using their package manager. With Ubuntu
40this should do it:
41
42```sh
43$ sudo apt-get install mysql-server mysql-client
44```
45
46On OSX you can download a disk image directly from the [MySQL Downloads page](http://dev.mysql.com/downloads/mysql/), or
47use one of the popular package managers like [homebrew](http://brew.sh/) or [MacPorts](https://www.macports.org/).
48
49To run the test suite you will need to make sure it is possible to connect as the user `root` without the need for a
50password.
51
52It is strongly recommended that you use the command line `mysql` client to access your MySQL instance since there can be
53problems connecting as the root user with some graphical clients like `phpMyAdmin`. To check if you can connect as root
54without needing a password use the following command:
55
56```sh
57$ mysql -u root
58```
59
60If you see an error like:
61
62```sh
63ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
64```
65
66that means you can't login as root without a password. If you do know the root user's password just login with the known
67password like this:
68
69```sh
70$ mysql -u root -p
71```
72
73and enter the password when asked. Then just set an empty password for root like so:
74
75```SQL
76USE mysql;
77UPDATE user SET password = "" WHERE User = "root";
78FLUSH PRIVILEGES;
79QUIT;
80```
81
82Note that you'll probably need to set the password to `NULL` instead of an empty string in MySQL versions 5.5 and older.
83The above example should work with versions 5.6 and newer.
84
85If you have forgotten the root password you'll need to take some extra steps to reset it. Take a look at
86[this Stack Overflow answer](http://stackoverflow.com/a/7825212/504930) for further details.
87
88#### PostgreSQL
89
90You can install [PostgreSQL](http://www.postgresql.org/) easily on most linux distros by using their package manager.
91With Ubuntu this should do it:
92
93```sh
94$ sudo apt-get install postgresql postgresql-client
95```
96
97On OSX the easiest way is probably by using [PosgresApp](http://postgresapp.com/). It should also be available to
98install via [homebrew](http://brew.sh/) or [MacPorts](https://www.macports.org/) if you prefer.
99
100In the case of PostgreSQL the requirement is to be able to connect as the `postgres` user on localhost also without the
101need for a password. This can be achieved by editing or adding the following line in the `pg_hba.conf` file:
102
103```
104host all all 127.0.0.1/32 trust
105```
106
107This file can be found in `/etc/postgresql/9.4/main/` on most linux systems. The `9.4` part could be different depending
108on the version that is available in your distro. On OSX the location of this file will depend on the installation method
109chosen, but for the recommended PostgresApp install it will be in `/Users/[yourusername]/Library/Application
110Support/Postgres/var-9.3/`. Again, the `var-9.3` part may be different depending on the version you installed.
111
112The `trust` in the example above tells the locally running PostgreSQL server to ignore user passwords and always grant
113access on clients connecting locally. Do not use this setting in a production environment.
114
115After editing the `pg_hba.conf` file you'll need to restart the PostgreSQL server for the changes to take effect.
116
117#### Using a config file
118
119If you don't want to go to the trouble of performing the changes explained in the previous two sections you can instead
120use a config file that tells the test suite about your database setup.
121
122The tests will look for a `BOOKSHELF_TEST` environment variable that points to a `config.js` file with the connection
123details for each database server. This file must not be the same database config file you use for any other application,
124otherwise you risk data loss in that application.
125
126Example config file:
127
128```javascript
129module.exports = {
130 mysql: {
131 database: 'bookshelf_test',
132 user: 'root',
133 encoding: 'utf8'
134 },
135
136 postgres: {
137 user: 'myusername',
138 database: 'bookshelf_test',
139 password: 'secretpassword',
140 host: 'localhost',
141 port: 5432,
142 charset: 'utf8',
143 ssl: false
144 },
145
146 sqlite3: {
147 filename: ':memory:'
148 }
149};
150```
151
152This file can be placed anywhere on your system and can have any name that you like, as long as the environment variable
153is pointing correctly to it. For convenience you can put it in your home directory and add the following line to your
154`.bashrc` or `.zshrc`:
155
156```
157export BOOKSHELF_TEST='/home/myusername/.bookshelf_config.js'
158```
159
160#### Database creation
161
162After having ensured the test suite can access both database servers just create a new database on each that will be
163used exclusively by Bookshelf.js:
164
165```SQL
166CREATE DATABASE bookshelf_test;
167```
168
169### Running the Tests
170
171The test suite requires that both MySQL and PostgreSQL servers have a database named `bookshelf_test`. See the sections
172above for further instructions.
173
174Once you have done that, you can run the tests:
175
176```sh
177$ npm test
178```
179
180Always make sure all the tests are passing before sending a pull request.