yammat/README.md

151 lines
4.8 KiB
Markdown
Raw Permalink Normal View History

2016-01-31 00:45:54 +01:00
# yammat
2015-04-04 06:46:33 +02:00
Yet Another MateMAT
2016-01-31 00:45:54 +01:00
## Introduction
2015-04-04 06:46:33 +02:00
2015-04-07 02:21:05 +02:00
This project aims to be an implementation for a trust based POS for hackerspaces.
2016-01-31 00:45:54 +01:00
## Installation
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
### Dependencies
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
#### Environment dependencies
2015-04-07 02:21:05 +02:00
2017-01-21 18:02:29 +01:00
A working Haskell capable environment. For that you will need `ghc` and
`cabal-install`, which can be installed with:
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
```bash
2017-01-21 18:02:29 +01:00
sudo apt-get install ghc cabal-install
2016-01-31 00:45:54 +01:00
```
2015-04-07 02:23:42 +02:00
2017-01-21 18:02:29 +01:00
After you installed `cabal-install`, let it make itself comfortable in your system with
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
```bash
2017-01-21 18:02:29 +01:00
cabal update && cabal install cabal-install
2016-01-31 00:45:54 +01:00
```
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
This might, depending on your system setup, take some time. Brew yourself some tea.
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
#### Build dependencies
2015-04-07 02:21:05 +02:00
2017-01-21 18:02:29 +01:00
Now that your Haskell environment is set up, you need to install the
dependencies for building and running yammat, which are:
2015-04-07 02:21:05 +02:00
2017-06-04 23:06:24 +02:00
* build-essential
2016-01-31 00:45:54 +01:00
* alex
* happy
* libpq-dev
* postgresql
2016-05-09 00:10:19 +02:00
* libfftw3-dev
2018-02-15 22:55:10 +01:00
* zlib1g-dev
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
Install all of them through your package management system.
2015-04-07 02:21:05 +02:00
2016-01-31 00:45:54 +01:00
### Building
2015-04-07 02:21:05 +02:00
2017-01-21 18:02:29 +01:00
First create a sandbox in the project directory with:
```bash
cabal sandbox init && cabal install --only-dependencies
```
This will take a long time, so go on a quest to find some cookies to go with
the tea.
To build this project enter `cabal build` into your command line.
2015-04-07 02:21:05 +02:00
2017-01-21 18:02:29 +01:00
Enjoy your cookies and tea while you watch your yammat being built.
2015-09-17 16:21:38 +02:00
2016-01-31 00:45:54 +01:00
## Deployment
2015-09-17 16:21:38 +02:00
2017-01-21 18:02:29 +01:00
Create a directory outside of the project directory, where you want to actually
run the application. Copy or link the executable `yammat` from
`dist/build/yammat/` to your desired run location alongside with the folders
`static` and `config` and their contenst. The Folders should be copied, or you
may get problems with your git pulls.
2015-09-17 16:21:38 +02:00
2016-01-31 00:45:54 +01:00
## Configuration
2017-06-04 23:19:49 +02:00
### Database
To set up your database, Enter the postgresql root console (change to user
`postgres` and invoke `psql` on a debian system). then create a user with
```SQL
CREATE USER <username> WITH PASSWORD '<password>':
```
and then create the database and grant all privileges to the user with
```SQL
CREATE DATABASE <databasename>;
GRANT ALL PRIVILEGES ON <databasename> to <username>;
```
### Webapp
2016-01-31 00:45:54 +01:00
Let's leave the project directory and enter your desired run location.
2017-01-21 18:02:29 +01:00
Check the configuration File `config/settings.yml` and alter its content to your
liking. Most of these settings normally don't need to be altered much, except
for `approot`. Change this setting to the root address with which you want to
connect to the application, including the scheme (http or https).
2016-01-31 00:45:54 +01:00
Additionally edit the settings `email`, `currency` and `cash_charge`.
2017-01-21 18:02:29 +01:00
* `email` is the email address, which will receive notifications from yammat,
should the stock run low.
* `currency` is your currency sign or shorthand, which will be used when
displaying prices.
2016-01-31 00:45:54 +01:00
* `cash_charge` is the extra you want to charge your users, who pay cash.
2017-01-21 18:02:29 +01:00
* *Note:* The value of this setting is in hundredths of your currency
denomination.
2016-01-31 00:45:54 +01:00
2017-01-21 18:02:29 +01:00
`cash_charge` is effectively a "guest tax". Setting it to `0` is perfectly fine,
if you don't want that.
2016-01-31 00:45:54 +01:00
2017-01-21 18:02:29 +01:00
Create a Postgresql User and Database according to the settings in the settings
file and grant the user all privileges on the database.
2016-01-31 00:45:54 +01:00
## Lift-Off
Run `./yammat config/settings.yml` in your desired run location. Finally point a reverse-proxy
(something like nginx) at `http://localhost:3000` or any other port you configured in
`config/settings.yml`.
For better control You can wrap an systemd unit file around this.
How to do this is described [in my blog][blog].
## Migrations
### 0.0.0-0.0.1
* Delete column `alt_time` from table `avatar` in your Database with
`alter table "avatar" drop column "alt_time";`
2015-09-17 21:16:10 +02:00
* Start yammat normally to fill database with dummy data and stop it again
2015-10-12 02:44:59 +02:00
* Run migration script
2016-01-31 00:45:54 +01:00
* if you have built yammat with a sandbox, run
`runghc -package-db/full/path/to/sandbox(XXX-ghc-version-packages.conf.d
/path/to/yammat/Migration/0.0.0-0.0.1/Migration.hs`
2015-10-12 02:44:59 +02:00
* Note: No space between the option `-package-db` and its argument
* without sandbox: `runghc /path/to/yammat/Migration/0.0.0-0.0.1/Migration.hs`
2015-09-17 21:16:10 +02:00
* Enjoy your freshly migrated Matemat
2016-01-31 00:45:54 +01:00
2016-03-18 00:03:09 +01:00
### 0.0.2-0.0.3
* stop old matemat
* create a view with new and old timestamps and user ids with
2016-05-23 19:25:30 +02:00
`create or replace view "user_new" as select "user".id, "user".timestamp, date 'epoch' + "user".timestamp * interval '1 second' as timestamp_new from "user";`
2016-03-18 00:03:09 +01:00
* create temporary timestamp column in user table with
2016-03-18 01:02:56 +01:00
`alter table "user" add column "timestamp_temp" date;`
2016-03-18 00:03:09 +01:00
* fill temporary timestamp column with new timestamps with
2016-03-18 01:02:56 +01:00
`update "user" set timestamp_temp = (select timestamp_new from user_new where user_new.id = "user".id);`
2016-03-18 00:03:09 +01:00
* check if new timestamps look sane
* drop old timestamp column
`alter table "user" drop column timestamp cascade;`
* rename temporary column
`alter table "user" rename column timestamp_temp to "timestamp";`
* start new matemat
2016-01-31 00:45:54 +01:00
[stackage]: http://www.stackage.org/
[blog]: https://nek0.eu/posts/2015-08-28-Daemonize-a-Yesod-application-systemd-style.html