2020-08-25 16:38:10 +00:00
|
|
|
# LocalSpend - Server
|
|
|
|
|
|
|
|
This repository contains the server for the LocalSpend system.
|
2017-04-21 22:48:37 +00:00
|
|
|
|
2017-06-12 21:03:17 +00:00
|
|
|
## Current Status
|
|
|
|
|
|
|
|
*Master:* [![Build Status](https://travis-ci.org/Pear-Trading/Foodloop-Server.svg?branch=master)](https://travis-ci.org/Pear-Trading/Foodloop-Server)
|
|
|
|
|
|
|
|
*Development:* [![Build Status](https://travis-ci.org/Pear-Trading/Foodloop-Server.svg?branch=development)](https://travis-ci.org/Pear-Trading/Foodloop-Server)
|
2017-09-26 16:03:27 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
# Test Environment
|
|
|
|
|
|
|
|
## Running Tests
|
2017-09-26 16:03:27 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
To run the main test framework, first install all the dependencies, then run
|
|
|
|
the tests:
|
2017-09-26 16:03:27 +00:00
|
|
|
|
2020-08-25 16:50:11 +00:00
|
|
|
- `cpanm --installdeps .`
|
|
|
|
- `prove -lr`
|
2017-09-26 16:03:27 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
To run the main framework against a PostgreSQL backend, assuming you have
|
|
|
|
`postgres` installed, you will need some extra dependencies first:
|
2017-09-26 16:03:27 +00:00
|
|
|
|
2020-08-25 16:50:11 +00:00
|
|
|
- `cpanm --installdeps . --with-feature postgres`
|
|
|
|
- `PEAR_TEST_PG=1 prove -lr`
|
2017-09-26 16:03:27 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
## Setting Up Minion
|
2018-03-20 19:24:48 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
To set up Minion support, you will need to create a database and user for
|
|
|
|
it to connect to.
|
|
|
|
In production his should be a PostgreSQL database, however SQLite can be used
|
|
|
|
in testing.
|
2018-03-20 19:24:48 +00:00
|
|
|
|
2020-08-25 16:50:11 +00:00
|
|
|
To use the SQLite version:
|
2018-03-20 19:24:48 +00:00
|
|
|
|
2020-08-25 16:50:11 +00:00
|
|
|
1. Install the SQLite dependencies:
|
|
|
|
- `cpanm --installdeps --with-feature sqlite .`
|
|
|
|
2. Ensure that the following is in your configuration file:
|
|
|
|
- ```
|
|
|
|
minion => {
|
|
|
|
SQLite => 'sqlite:minion.db',
|
|
|
|
},
|
|
|
|
```
|
2018-03-20 19:24:48 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
This will then use an SQLite DB for the Minion backend, using `minion.db` as
|
|
|
|
the database file.
|
2018-03-20 19:24:48 +00:00
|
|
|
|
2020-08-25 16:50:11 +00:00
|
|
|
To start the minion itself, run this command:
|
|
|
|
- `./script/pear-local_loop minion worker`
|
2019-09-09 14:37:26 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
## Importing Ward Data
|
2019-09-09 14:37:26 +00:00
|
|
|
|
2020-08-25 16:44:06 +00:00
|
|
|
To import ward data:
|
2019-09-09 14:37:26 +00:00
|
|
|
|
2020-08-25 16:44:06 +00:00
|
|
|
1. Download CSV(s) from [here](https://www.doogal.co.uk/PostcodeDownloads.php)
|
|
|
|
1. Run the following command:
|
2020-08-25 16:50:11 +00:00
|
|
|
- ```shell script
|
|
|
|
./script/pear-local_loop minion job \
|
|
|
|
--enqueue 'csv_postcode_import' \
|
|
|
|
--args '[ "⟨ path to CSV ⟩ ]'
|
|
|
|
```
|
2018-03-20 19:24:48 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
## Setting Up Entity Postcodes
|
2019-09-09 17:03:08 +00:00
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
1. Import Code-Point Open:
|
|
|
|
- included in `etc/`
|
|
|
|
- `./script/pear-local_loop codepoint_open --outcodes LA1`
|
|
|
|
1. Assign postcodes:
|
2020-08-25 16:50:11 +00:00
|
|
|
- ```shell script
|
|
|
|
./script/pear-local_loop minion job \
|
|
|
|
--enqueue entity_postcode_lookup
|
|
|
|
```
|
2019-09-09 17:03:08 +00:00
|
|
|
|
2018-03-20 19:24:48 +00:00
|
|
|
## Example PostgreSQL setup
|
|
|
|
|
|
|
|
```
|
|
|
|
# Example commands - probably not the best ones
|
|
|
|
# TODO come back and improve these with proper ownership and DDL rights
|
|
|
|
sudo -u postgres createuser minion
|
|
|
|
sudo -u postgres createdb localloop_minion
|
|
|
|
sudo -u postgres psql
|
|
|
|
psql=# alter user minion with encrypted password 'abc123';
|
|
|
|
psql=# grant all privileges on database localloop_minion to minion;
|
|
|
|
```
|
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
# Development Environment
|
2019-09-09 14:37:26 +00:00
|
|
|
|
|
|
|
There are a couple of setup steps to getting a development environment ready.
|
|
|
|
|
|
|
|
## First Time Setup
|
|
|
|
|
2020-08-25 16:38:10 +00:00
|
|
|
1. Decide if you're using SQLite or PostgreSQL locally.
|
|
|
|
- Development supports both, however production uses PostgreSQL.
|
|
|
|
- For this example we will use SQLite.
|
|
|
|
- As the default config. is set up for this, no configuration changes are
|
|
|
|
needed initially.
|
|
|
|
1. Install dependencies:
|
2020-08-25 16:52:08 +00:00
|
|
|
- ```shell script
|
|
|
|
cpanm --installdeps . \
|
|
|
|
--with-feature=sqlite \
|
|
|
|
--with-feature=codepoint-open
|
|
|
|
```
|
2020-08-25 16:38:10 +00:00
|
|
|
1. Install the database:
|
|
|
|
- `./script/deploy_db install -c 'dbi:SQLite:dbname=foodloop.db'`
|
|
|
|
1. Set up the development users:
|
|
|
|
- `./script/pear-local_loop dev_data --force`
|
|
|
|
- ***DO NOT RUN ON PROD.***
|
|
|
|
1. Start the minion:
|
|
|
|
- `./script/pear-local_loop minion worker`
|
2020-08-25 16:44:06 +00:00
|
|
|
1. Import ward data (see [instructions](#importing-ward-data) above)
|
2020-08-25 16:53:12 +00:00
|
|
|
1. Set up postcodes (see [instructions](#setting-up-entity-postcodes) above)
|
2020-08-25 16:38:10 +00:00
|
|
|
1. Start the application:
|
|
|
|
- `morbo script/pear-local_loop -l http://*:3000`
|
|
|
|
- You can modify the host and port as needed.
|
|
|
|
|
|
|
|
## Database Scripts
|
|
|
|
|
|
|
|
To upgrade the database after making changes to commit:
|
2019-07-03 16:36:36 +00:00
|
|
|
|
2020-08-25 16:52:08 +00:00
|
|
|
1. `./script/deploy_db write_ddl -c 'dbi:SQLite:dbname=foodloop.db'`
|
|
|
|
1. `./script/deploy_db upgrade -c 'dbi:SQLite:dbname=foodloop.db'`
|
2019-07-03 16:36:36 +00:00
|
|
|
|
|
|
|
To redo leaderboards:
|
|
|
|
|
2020-08-25 16:52:08 +00:00
|
|
|
1. `./script/pear-local_loop recalc_leaderboards`
|