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
|
10 | transpilation from ES6 in the background.
|
11 |
|
12 | * All pull requests should be made to the `master` branch.
|
13 |
|
14 | ### Development Environment Setup
|
15 |
|
16 | You'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 |
|
23 | Afterwards go to the bookshelf directory that was just created and install the dependencies:
|
24 |
|
25 | ```sh
|
26 | $ npm install
|
27 | ```
|
28 |
|
29 | At this point the only thing missing are the databases that will be used for running some of the tests of the automated
|
30 | test suite.
|
31 |
|
32 | There are two options for setting up this part. The first one is to change some configuration options of the database
|
33 | servers and the other is to use a config file in case you already have your servers configured and don't want to change
|
34 | any of their config files. The first two sections below deal with the first option and then there are instructions on
|
35 | how to use the other option.
|
36 |
|
37 | #### MySQL
|
38 |
|
39 | You can install [MySQL](https://www.mysql.com/) easily on most linux distros by using their package manager. With Ubuntu
|
40 | this should do it:
|
41 |
|
42 | ```sh
|
43 | $ sudo apt-get install mysql-server mysql-client
|
44 | ```
|
45 |
|
46 | On OSX you can download a disk image directly from the [MySQL Downloads page](http://dev.mysql.com/downloads/mysql/), or
|
47 | use one of the popular package managers like [homebrew](http://brew.sh/) or [MacPorts](https://www.macports.org/).
|
48 |
|
49 | To run the test suite you will need to make sure it is possible to connect as the user `root` without the need for a
|
50 | password.
|
51 |
|
52 | It is strongly recommended that you use the command line `mysql` client to access your MySQL instance since there can be
|
53 | problems connecting as the root user with some graphical clients like `phpMyAdmin`. To check if you can connect as root
|
54 | without needing a password use the following command:
|
55 |
|
56 | ```sh
|
57 | $ mysql -u root
|
58 | ```
|
59 |
|
60 | If you see an error like:
|
61 |
|
62 | ```sh
|
63 | ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
|
64 | ```
|
65 |
|
66 | that means you can't login as root without a password. If you do know the root user's password just login with the known
|
67 | password like this:
|
68 |
|
69 | ```sh
|
70 | $ mysql -u root -p
|
71 | ```
|
72 |
|
73 | and enter the password when asked. Then just set an empty password for root like so:
|
74 |
|
75 | ```SQL
|
76 | USE mysql;
|
77 | UPDATE user SET password = "" WHERE User = "root";
|
78 | FLUSH PRIVILEGES;
|
79 | QUIT;
|
80 | ```
|
81 |
|
82 | Note that you'll probably need to set the password to `NULL` instead of an empty string in MySQL versions 5.5 and older.
|
83 | The above example should work with versions 5.6 and newer.
|
84 |
|
85 | If 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 |
|
90 | You can install [PostgreSQL](http://www.postgresql.org/) easily on most linux distros by using their package manager.
|
91 | With Ubuntu this should do it:
|
92 |
|
93 | ```sh
|
94 | $ sudo apt-get install postgresql postgresql-client
|
95 | ```
|
96 |
|
97 | On OSX the easiest way is probably by using [PosgresApp](http://postgresapp.com/). It should also be available to
|
98 | install via [homebrew](http://brew.sh/) or [MacPorts](https://www.macports.org/) if you prefer.
|
99 |
|
100 | In the case of PostgreSQL the requirement is to be able to connect as the `postgres` user on localhost also without the
|
101 | need for a password. This can be achieved by editing or adding the following line in the `pg_hba.conf` file:
|
102 |
|
103 | ```
|
104 | host all all 127.0.0.1/32 trust
|
105 | ```
|
106 |
|
107 | This file can be found in `/etc/postgresql/9.4/main/` on most linux systems. The `9.4` part could be different depending
|
108 | on the version that is available in your distro. On OSX the location of this file will depend on the installation method
|
109 | chosen, but for the recommended PostgresApp install it will be in `/Users/[yourusername]/Library/Application
|
110 | Support/Postgres/var-9.3/`. Again, the `var-9.3` part may be different depending on the version you installed.
|
111 |
|
112 | The `trust` in the example above tells the locally running PostgreSQL server to ignore user passwords and always grant
|
113 | access on clients connecting locally. Do not use this setting in a production environment.
|
114 |
|
115 | After 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 |
|
119 | If you don't want to go to the trouble of performing the changes explained in the previous two sections you can instead
|
120 | use a config file that tells the test suite about your database setup.
|
121 |
|
122 | The tests will look for a `BOOKSHELF_TEST` environment variable that points to a `config.js` file with the connection
|
123 | details for each database server. This file must not be the same database config file you use for any other application,
|
124 | otherwise you risk data loss in that application.
|
125 |
|
126 | Example config file:
|
127 |
|
128 | ```javascript
|
129 | module.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 |
|
152 | This file can be placed anywhere on your system and can have any name that you like, as long as the environment variable
|
153 | is 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 | ```
|
157 | export BOOKSHELF_TEST='/home/myusername/.bookshelf_config.js'
|
158 | ```
|
159 |
|
160 | #### Database creation
|
161 |
|
162 | After having ensured the test suite can access both database servers just create a new database on each that will be
|
163 | used exclusively by Bookshelf.js:
|
164 |
|
165 | ```SQL
|
166 | CREATE DATABASE bookshelf_test;
|
167 | ```
|
168 |
|
169 | ### Running the Tests
|
170 |
|
171 | The test suite requires that both MySQL and PostgreSQL servers have a database named `bookshelf_test`. See the sections
|
172 | above for further instructions.
|
173 |
|
174 | Once you have done that, you can run the tests:
|
175 |
|
176 | ```sh
|
177 | $ npm test
|
178 | ```
|
179 |
|
180 | Always make sure all the tests are passing before sending a pull request.
|