intershop
An application basework built on PostGreSQL, with sprinkles of JavaScript and plPython3u
Last updated 6 months ago by loveencounterflow .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install intershop 
SYNC missed versions from official npm registry.

InterShop

An incipient application foundation built on Postgres, with sprinkles of JavaScript and plPython3u

Table of Contents generated with DocToc

Installation

Dependencies

Postgres

sudo apt install wget ca-certificates psmisc
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt install postgresql-12
sudo apt install postgresql-server-dev-12
sudo apt install postgresql-plpython3-12
sudo apt install postgresql-contrib-12
sudo apt install postgresql-12-unit
sudo apt install postgresql-12-plsh
# sudo apt install postgresql-12-pgtap
# sudo apt install postgresql-12-pldebugger
# sudo apt install postgresql-9.6-plv8
# sudo apt install postgresql-plperl-9.6

Configure Postgres

Find Configuration File Locations

In the below, adjust port; the first Postgres installation will likely listen on port 5432, the next one on port 5433 and so on; this, of course, will vary depending on whether one installed a newer PG version along an older one and so.

sudo -u postgres psql --port 5433 -c "                                                \
  select                                                                  \
      name                                                    as key,     \
      setting                                                 as value,   \
      case setting when reset_val then '' else reset_val end  as changed  \
    from pg_settings                                                      \
    where true                                                            \
      and ( category = 'File Locations' )                                 \
      order by name;"

This will output a table similar to this one:

        key        |                  value                  | changed
-------------------+-----------------------------------------+---------
 config_file       | /etc/postgresql/12/main/postgresql.conf |
 data_directory    | /var/lib/postgresql/12/main             |
 external_pid_file | /var/run/postgresql/12-main.pid         |
 hba_file          | /etc/postgresql/12/main/pg_hba.conf     |
 ident_file        | /etc/postgresql/12/main/pg_ident.conf   |

Personally, I prefer to create a git-versioned project so I can track (and, when necessary, undo) my changes to the PG configuration. Inside that project, I create one directory for each version and use hardlinks (not symlinks) so I get mirrored local versions of the pertinent files that will always be identical to the configurations as seen by Postgres.

In pg_hba.conf, add these lines below the one that reads

# Database administrative login by Unix domain socket
local   all             postgres                                peer

Do not change the above, just add these lines to indicate that connections from localhost should always be trusted:

### in pg_hba.conf ###
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     trust
host    all             all             localhost               trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust

You must restart Postgres after changing the configuration, for example with one of these lines:

sudo /etc/init.d/postgresql restart ; echo $?
sudo /etc/init.d/postgresql restart 12 ; echo $?

Statement-Level Statistics

In postgresql.conf:

shared_preload_libraries = 'pg_stat_statements'     # (change requires restart)

(must restart with sudo /etc/init.d/postgresql restart 10 or similar after change; note that errors in this settings might not lead to visible error messages, but still prevent the server from restarting).

Otherwise, comment this out in 020-extensions.sql:

create extension if not exists pg_stat_statements;

Also see here.

Peru

Peru is "a tool for including other people's code in your projects"; it is the most convenient and promising way I've yet found to compose one application by drawing together from various sources crossing languages and access methods. It can be conveniently installed via the Peru PPA:

sudo add-apt-repository ppa:buildinspace/peru
sudo apt update
sudo apt install peru

Python

sudo pip install pipenv
pipenv install tap.py pytest

InterShop Initialization and (Re-) Building

To get started with your app, create a directory for it and cd into it; then, copy the three essential configuration files using wget (curl works similar):

mkdir myapp
cd myapp
wget https://raw.githubusercontent.com/loveencounterflow/intershop/master/copy-to-host-app/rakefile
wget https://raw.githubusercontent.com/loveencounterflow/intershop/master/copy-to-host-app/peru.yaml
wget https://raw.githubusercontent.com/loveencounterflow/intershop/master/intershop.ptv

If you don't already have a .gitignore file, you may want to copy (or merge) the one from InterShop; this is to make sure your git repo won't version a gazillion dependencies under node_modules (although for some use cases this is actually the recommended way):

wget https://raw.githubusercontent.com/loveencounterflow/intershop/master/.gitignore

Edit intershop.ptv so the line intershop/host/name spells out the name of your app (let's call it myapp here), which will also become the name of the database and the Postgres user:

intershop/host/name                             ::text=               myapp
intershop/db/port                               ::integer=            5432
intershop/db/name                               ::text=               ${intershop/host/name}
intershop/db/user                               ::text=               ${intershop/host/name}
intershop/rpc/port                              ::integer=            23001
intershop/rpc/host                              ::text/ip-address=    127.0.0.1

You are now ready to start installation: peru sync will pull the latest InterShop sources; rake intershop_npm_install will run npm install inside the newly established intershop folder, and intershop rebuild will create a Postgres DB (named myapp or whatever name you chose) and a user by the same name and run all the *.sql files in intershop/db:

peru reup && peru sync
rake intershop_npm_install
intershop rebuild

To get an idea what we have by now, take a gander at the catalog:

intershop psql -c "select * from CATALOG.catalog order by schema, name;"

The intershop psql invocation is essentially nothing but psql -U $intershop_db_user -d $intershop_db_name -p $intershop_db_port ... "@$" where ... denotes a bunch of configuration values.

It's probably a good idea to add your configuration to git:

git add intershop.ptv && git commit -m'add intershop.ptv'
git add peru.yaml && git commit -m'update by peru'

Whether or not to add the intershop submodule to git is a matter of taste:

git add intershop && git commit -m'updates from upstream'

Using PTV Configuration Variables in SQL

Later on, you may want to add your own options into intershop.ptv so you can access those configuration settings from SQL; it's customary to prefix those options with the name of your app (but anything will work so long as names don't start with intershop):

myapp/fudge/use                                 ::boolean=          true
myapp/fudge/factor                              ::float=            3.14
myapp/fudge/delta                               ::integer=          12

The type annotations are currently not documented and not used programmatically; they serve at present merely as a handy reference for the type casting one has to perform explicitly when retrieving values; so, in your SQL you might want to do this:

select ¶( 'myapp/fudge/use'    )::boolean;
select ¶( 'myapp/fudge/factor' )::float;
select ¶( 'myapp/fudge/delta'  )::integer;

Variables can be used as compilation parameters:

do $$ begin
  if ¶( 'myapp/fudge/use' )::boolean then
    create function ...;
  else
    create function ...;
    end if;
  $$

Running Tests

py.test --tap-files

No More FDWs FTW

see documentation/no-more-fdws-ftw.md

The MIRAGE File Mirror Module

The Mirage module is responsible for handling all read-only linewise file access. Have a look at the docs and the demo.

Current Tags

  • 0.5.0                                ...           latest (6 months ago)

13 Versions

  • 0.5.0                                ...           6 months ago
  • 0.4.1                                ...           6 months ago
  • 0.4.0                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.4                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 11
Dependencies (13)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |