Make sure to use git clone --recursive on this repository to get the submodule. See [here](https://github.com/pg-redis-fdw/redis_fdw)
for instructions on installing the Redis foreign data wrapper. See [here](https://github.com/postgis/postgis/blob/master/README.postgis) for instructions on installing PostGIS.
In both cases you can also check your systems package repositories.

    sudo apt install postgresql-11 postgresql-client
    sudo -u postgres psql
    CREATE DATABASE jmp;
    GRANT ALL ON DATABASE jmp TO unix_user;
    GRANT CREATE ON SCHEMA public TO unix_user;
    \c jmp
    CREATE EXTENSION btree_gist;
    CREATE EXTENSION citext;
    CREATE EXTENSION pgcrypto;
    CREATE EXTENSION redis_fdw;
    CREATE EXTENSION postgis;
    CREATE SERVER redis_server
        FOREIGN DATA WRAPPER redis_fdw
        OPTIONS (
          address '127.0.0.1',
          port '6379'
    );
    GRANT USAGE ON FOREIGN SERVER redis_server TO unix_user;
    CREATE USER MAPPING
        FOR PUBLIC
            SERVER redis_server
            OPTIONS (user 'default');

    exit
    sudo apt install sqitch
    cd schemas
    sqitch deploy
    bundle install --path=.gems
    cp config.dhall.sample config.dhall
    $EDITOR config.dhall # Set up appropriately for local prosody, braintree, etc
    bundle exec ruby sgx_jmp.rb ./config.dhall


## Helpful keys for registration

If you want to register with the backend without going through braintree or electrum, you can set the following two keys in Redis:

	SET "jmp_customer_id-<USER>\\40<DOMAIN>@cheogram" 0001
	SET "jmp_customer_jid-0001" "jmp_customer_id-<USER>\\40<DOMAIN>@cheogram"

Where cheogram is whatever the component is called, and 0001 is whatever you want the user's customer ID to be.

And then in psql:
	INSERT INTO plan_log (customer_id, plan_name, date_range) VALUES ('0001', 'plan_name', tsrange('1990-01-01', '2023-01-01'));

These together will ensure that the customer already has an ID, and so braintree doesn't need to be asked to create one, and the plan is activated, so we don't need to attempt to accept payment.

Then when you run "register" from cheogram, it will skip right to the end and allow you to begin routing to this component.
