@socialgouv/matomo-postgres 1.5.1 → 1.5.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/bin/index.js +1 -1
- package/package.json +24 -12
- package/.github/workflows/release.yml +0 -33
- package/.github/workflows/test.yml +0 -27
- package/docker/Dockerfile +0 -43
- package/docker/initdb.sh +0 -13
- package/docker-compose.yml +0 -18
- package/header.png +0 -0
- package/initial.sql +0 -73
- package/jsconfig.json +0 -10
- package/renovate.json +0 -6
- package/src/__tests__/__snapshots__/importDate.test.js.snap +0 -389
- package/src/__tests__/__snapshots__/importEvent.test.js.snap +0 -359
- package/src/__tests__/__snapshots__/index.test.js.snap +0 -56
- package/src/__tests__/importDate.test.js +0 -133
- package/src/__tests__/importEvent.test.js +0 -22
- package/src/__tests__/index.test.js +0 -194
- package/src/__tests__/visit.json +0 -103
- package/src/config.js +0 -9
- package/src/createTable.js +0 -83
- package/src/importDate.js +0 -105
- package/src/importEvent.js +0 -108
- package/src/index.js +0 -79
- package/types/index.d.ts +0 -31
- package/types/matomo.d.ts +0 -214
package/README.md
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
Extract matomo data from [`Live.getLastVisitsDetails`](https://developer.matomo.org/api-reference/reporting-api) API and push events and visits informations to Postgres.
|
|
6
6
|
|
|
7
|
-
Use [pg_partman](https://github.com/pgpartman/pg_partman) to partition data by month.
|
|
8
|
-
|
|
9
7
|
## Usage
|
|
10
8
|
|
|
11
9
|
Create the [initial table](./initial.sql) database table then run the following job with correct environment variables.
|
|
@@ -16,16 +14,16 @@ npx @socialgouv/matomo-postgres
|
|
|
16
14
|
|
|
17
15
|
### Environment variables Deployment
|
|
18
16
|
|
|
19
|
-
| name | value
|
|
20
|
-
| ----------------- |
|
|
21
|
-
| MATOMO_KEY\* | matomo api token
|
|
22
|
-
| MATOMO_SITE\* | matomo site id
|
|
23
|
-
| MATOMO_URL\* | matomo url
|
|
24
|
-
| PGDATABASE\* | Postgres connection string
|
|
25
|
-
| DESTINATION_TABLE | `matomo`
|
|
26
|
-
| STARTDATE | default to today()
|
|
27
|
-
| RESULTPERPAGE | matomo pagination
|
|
28
|
-
|
|
|
17
|
+
| name | value |
|
|
18
|
+
| ----------------- | -------------------------------------------------------- |
|
|
19
|
+
| MATOMO_KEY\* | matomo api token |
|
|
20
|
+
| MATOMO_SITE\* | matomo site id |
|
|
21
|
+
| MATOMO_URL\* | matomo url |
|
|
22
|
+
| PGDATABASE\* | Postgres connection string |
|
|
23
|
+
| DESTINATION_TABLE | `matomo` |
|
|
24
|
+
| STARTDATE | default to today() |
|
|
25
|
+
| RESULTPERPAGE | matomo pagination (defaults to 500) |
|
|
26
|
+
| INITIAL_OFFSET | How many days to fetch on initialisation (defaults to 3) |
|
|
29
27
|
|
|
30
28
|
## Dev
|
|
31
29
|
|
|
@@ -43,3 +41,6 @@ yarn start
|
|
|
43
41
|
|
|
44
42
|
Use `yarn test -u` to update the snapshots
|
|
45
43
|
|
|
44
|
+
## Database migrations
|
|
45
|
+
|
|
46
|
+
`yarn migrate` is run on each `yarn start` with Kysely migrations at [./src/migrations](./src/migrations/)
|
package/bin/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socialgouv/matomo-postgres",
|
|
3
3
|
"description": "Extract visitor events from Matomo API and push to Postgres",
|
|
4
|
-
"version": "1.5.1",
|
|
4
|
+
"version": "1.5.2-beta.1",
|
|
5
5
|
"types": "types/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"main": "
|
|
7
|
+
"main": "dist/index.js",
|
|
8
8
|
"preferGlobal": true,
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
@@ -12,25 +12,37 @@
|
|
|
12
12
|
"bin": {
|
|
13
13
|
"matomo-postgres": "./bin/index.js"
|
|
14
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
15
19
|
"scripts": {
|
|
16
|
-
"start": "node ./
|
|
20
|
+
"start": "yarn migrate && node ./dist/index.js",
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"prepublish": "yarn build",
|
|
23
|
+
"migrate": "node ./dist/migrate-latest.js",
|
|
17
24
|
"test": "jest --verbose"
|
|
18
25
|
},
|
|
19
26
|
"prettier": {
|
|
20
27
|
"printWidth": 120
|
|
21
28
|
},
|
|
22
29
|
"dependencies": {
|
|
23
|
-
"date-fns": "^2.
|
|
24
|
-
"debug": "^4.3.
|
|
25
|
-
"dotenv": "^
|
|
26
|
-
"
|
|
27
|
-
"
|
|
30
|
+
"date-fns": "^2.29.3",
|
|
31
|
+
"debug": "^4.3.4",
|
|
32
|
+
"dotenv": "^16.0.3",
|
|
33
|
+
"kysely": "^0.23.4",
|
|
34
|
+
"p-all": "^3",
|
|
35
|
+
"pg": "^8.9.0",
|
|
28
36
|
"piwik-client": "^0.2.2"
|
|
29
37
|
},
|
|
30
38
|
"devDependencies": {
|
|
31
|
-
"@types/
|
|
32
|
-
"@types/
|
|
33
|
-
"
|
|
34
|
-
"
|
|
39
|
+
"@types/debug": "^4.1.7",
|
|
40
|
+
"@types/jest": "^29.4.0",
|
|
41
|
+
"@types/node": "^18.14.4",
|
|
42
|
+
"@types/pg": "^8.6.6",
|
|
43
|
+
"jest": "^29.4.3",
|
|
44
|
+
"ts-jest": "^29.0.5",
|
|
45
|
+
"ts-node": "^10.9.1",
|
|
46
|
+
"typescript": "^4.9.5"
|
|
35
47
|
}
|
|
36
48
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch:
|
|
5
|
-
push:
|
|
6
|
-
branches: [master, alpha, beta, next]
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
release:
|
|
10
|
-
name: Release
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
steps:
|
|
13
|
-
- name: Checkout repository
|
|
14
|
-
uses: actions/checkout@v2
|
|
15
|
-
with:
|
|
16
|
-
fetch-depth: 0
|
|
17
|
-
persist-credentials: false
|
|
18
|
-
|
|
19
|
-
- name: Semantic Release
|
|
20
|
-
uses: cycjimmy/semantic-release-action@v2
|
|
21
|
-
with:
|
|
22
|
-
semantic_version: 17
|
|
23
|
-
extra_plugins: |
|
|
24
|
-
@semantic-release/changelog@5.0.1
|
|
25
|
-
@semantic-release/git@9.0.0
|
|
26
|
-
|
|
27
|
-
env:
|
|
28
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
29
|
-
GIT_AUTHOR_EMAIL: ${{ secrets.SOCIALGROOVYBOT_EMAIL }}
|
|
30
|
-
GIT_AUTHOR_NAME: ${{ secrets.SOCIALGROOVYBOT_NAME }}
|
|
31
|
-
GIT_COMMITTER_EMAIL: ${{ secrets.SOCIALGROOVYBOT_EMAIL }}
|
|
32
|
-
GIT_COMMITTER_NAME: ${{ secrets.SOCIALGROOVYBOT_NAME }}
|
|
33
|
-
NPM_TOKEN: ${{ secrets.SOCIALGROOVYBOT_NPM_TOKEN }}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
name: Test
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: ["*"]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
test:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v2
|
|
13
|
-
|
|
14
|
-
- name: Set up Node.js
|
|
15
|
-
uses: actions/setup-node@v2
|
|
16
|
-
with:
|
|
17
|
-
node-version: lts/*
|
|
18
|
-
cache: yarn
|
|
19
|
-
|
|
20
|
-
- name: Installing
|
|
21
|
-
run: yarn --frozen-lockfile --perfer-offline --link-duplicates
|
|
22
|
-
|
|
23
|
-
# - name: Lint
|
|
24
|
-
# run: yarn lint
|
|
25
|
-
|
|
26
|
-
- name: Unit tests
|
|
27
|
-
run: yarn test
|
package/docker/Dockerfile
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
FROM postgres:13-alpine
|
|
2
|
-
|
|
3
|
-
ENV PG_PARTMAN_VERSION v4.7.0
|
|
4
|
-
|
|
5
|
-
# Install pg_jobmon
|
|
6
|
-
RUN set -ex \
|
|
7
|
-
\
|
|
8
|
-
&& apk add --no-cache --virtual .fetch-deps \
|
|
9
|
-
ca-certificates \
|
|
10
|
-
openssl \
|
|
11
|
-
tar \
|
|
12
|
-
\
|
|
13
|
-
&& apk add --no-cache --virtual .build-deps \
|
|
14
|
-
autoconf \
|
|
15
|
-
automake \
|
|
16
|
-
g++ \
|
|
17
|
-
clang \
|
|
18
|
-
llvm \
|
|
19
|
-
libtool \
|
|
20
|
-
libxml2-dev \
|
|
21
|
-
make \
|
|
22
|
-
perl
|
|
23
|
-
# Install pg_partman
|
|
24
|
-
RUN set -ex \
|
|
25
|
-
&& wget -O pg_partman.tar.gz "https://github.com/pgpartman/pg_partman/archive/$PG_PARTMAN_VERSION.tar.gz" \
|
|
26
|
-
&& mkdir -p /usr/src/pg_partman \
|
|
27
|
-
&& tar \
|
|
28
|
-
--extract \
|
|
29
|
-
--file pg_partman.tar.gz \
|
|
30
|
-
--directory /usr/src/pg_partman \
|
|
31
|
-
--strip-components 1 \
|
|
32
|
-
&& rm pg_partman.tar.gz \
|
|
33
|
-
&& cd /usr/src/pg_partman \
|
|
34
|
-
&& make \
|
|
35
|
-
&& make install \
|
|
36
|
-
&& cd / \
|
|
37
|
-
&& rm -rf /usr/src/pg_partman \
|
|
38
|
-
&& apk del .fetch-deps .build-deps
|
|
39
|
-
|
|
40
|
-
# Copy the init script
|
|
41
|
-
# The Docker Postgres initd script will run anything
|
|
42
|
-
# in the directory /docker-entrypoint-initdb.d
|
|
43
|
-
COPY initdb.sh /docker-entrypoint-initdb.d/initdb.sh
|
package/docker/initdb.sh
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/bin/bash -e
|
|
2
|
-
|
|
3
|
-
echo "Creating partman extension"
|
|
4
|
-
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
|
5
|
-
CREATE SCHEMA partman;
|
|
6
|
-
CREATE EXTENSION pg_partman SCHEMA partman;
|
|
7
|
-
EOSQL
|
|
8
|
-
|
|
9
|
-
echo "ADDING pg_partman_bgw TO postgresql.conf"
|
|
10
|
-
echo "shared_preload_libraries = 'pg_partman_bgw'" >> $PGDATA/postgresql.conf
|
|
11
|
-
echo "pg_partman_bgw.interval = 3600" >> $PGDATA/postgresql.conf
|
|
12
|
-
echo "pg_partman_bgw.role = '$POSTGRES_USER'" >> $PGDATA/postgresql.conf
|
|
13
|
-
echo "pg_partman_bgw.dbname = '$POSTGRES_DB'" >> $PGDATA/postgresql.conf
|
package/docker-compose.yml
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
version: "3.0"
|
|
2
|
-
services:
|
|
3
|
-
postgres:
|
|
4
|
-
build:
|
|
5
|
-
context: ./docker
|
|
6
|
-
dockerfile: ./Dockerfile
|
|
7
|
-
volumes:
|
|
8
|
-
- postgres_data:/var/lib/postgresql/data
|
|
9
|
-
environment:
|
|
10
|
-
POSTGRES_PASSWORD: postgres
|
|
11
|
-
POSTGRES_USERNAME: postgres
|
|
12
|
-
TZ: "Europe/Paris"
|
|
13
|
-
ports:
|
|
14
|
-
- 5455:5432
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
volumes:
|
|
18
|
-
postgres_data:
|
package/header.png
DELETED
|
Binary file
|
package/initial.sql
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
-- converting existing matomo table to partitioned witg pg_partman
|
|
2
|
-
-- usage : ON_ERROR_STOP=1 psql < partition.sql
|
|
3
|
-
|
|
4
|
-
--- pg_partman setup
|
|
5
|
-
|
|
6
|
-
CREATE SCHEMA IF NOT EXISTS partman;
|
|
7
|
-
CREATE EXTENSION IF NOT EXISTS pg_partman SCHEMA partman;
|
|
8
|
-
|
|
9
|
-
--- backup and recreate a new partionned matomo table
|
|
10
|
-
|
|
11
|
-
CREATE TABLE IF NOT EXISTS matomo_tmp as (select * from matomo);
|
|
12
|
-
|
|
13
|
-
ALTER TABLE IF EXISTS matomo RENAME TO matomo_backup;
|
|
14
|
-
|
|
15
|
-
CREATE TABLE IF NOT EXISTS matomo
|
|
16
|
-
(
|
|
17
|
-
idsite text,
|
|
18
|
-
idvisit text,
|
|
19
|
-
actions text,
|
|
20
|
-
country text,
|
|
21
|
-
region text,
|
|
22
|
-
city text,
|
|
23
|
-
operatingsystemname text,
|
|
24
|
-
devicemodel text,
|
|
25
|
-
devicebrand text,
|
|
26
|
-
visitduration text,
|
|
27
|
-
dayssincefirstvisit text,
|
|
28
|
-
visitortype text,
|
|
29
|
-
sitename text,
|
|
30
|
-
userid text,
|
|
31
|
-
serverdateprettyfirstaction date,
|
|
32
|
-
action_id text,
|
|
33
|
-
action_type text,
|
|
34
|
-
action_eventcategory text,
|
|
35
|
-
action_eventaction text,
|
|
36
|
-
action_eventname text,
|
|
37
|
-
action_eventvalue decimal,
|
|
38
|
-
action_timespent text,
|
|
39
|
-
action_timestamp timestamp with time zone DEFAULT now(),
|
|
40
|
-
usercustomproperties json,
|
|
41
|
-
usercustomdimensions json,
|
|
42
|
-
dimension1 text,
|
|
43
|
-
dimension2 text,
|
|
44
|
-
dimension3 text,
|
|
45
|
-
dimension4 text,
|
|
46
|
-
dimension5 text,
|
|
47
|
-
dimension6 text,
|
|
48
|
-
dimension7 text,
|
|
49
|
-
dimension8 text,
|
|
50
|
-
dimension9 text,
|
|
51
|
-
dimension10 text,
|
|
52
|
-
action_url text,
|
|
53
|
-
sitesearchkeyword text,
|
|
54
|
-
action_title text
|
|
55
|
-
) PARTITION BY RANGE (action_timestamp);
|
|
56
|
-
|
|
57
|
-
ALTER TABLE IF EXISTS matomo ADD CONSTRAINT unique_action_id UNIQUE (action_id, action_timestamp);
|
|
58
|
-
ALTER TABLE IF EXISTS matomo ALTER COLUMN action_eventvalue TYPE decimal USING action_eventvalue::decimal;
|
|
59
|
-
CREATE INDEX IF NOT EXISTS idx_action_timestamp_matomo ON matomo (action_timestamp);
|
|
60
|
-
CREATE INDEX IF NOT EXISTS idx_idvisit_matomo ON matomo(idvisit);
|
|
61
|
-
CREATE INDEX IF NOT EXISTS idx_action_eventcategory_matomo ON matomo(action_eventcategory);
|
|
62
|
-
CREATE INDEX IF NOT EXISTS idx_action_type_matomo ON matomo(action_type);
|
|
63
|
-
CREATE INDEX IF NOT EXISTS idx_action_eventaction_matomo ON matomo(action_eventaction);
|
|
64
|
-
|
|
65
|
-
SELECT partman.create_parent('public.matomo', 'action_timestamp', 'native', 'monthly');
|
|
66
|
-
|
|
67
|
-
-- Import des données depuis la table standard vers la table partitionnée
|
|
68
|
-
CALL partman.partition_data_proc('public.matomo', p_source_table := 'public.matomo_tmp', p_order:= 'DESC');
|
|
69
|
-
|
|
70
|
-
VACUUM ANALYZE public.matomo;
|
|
71
|
-
|
|
72
|
-
DROP TABLE if exists matomo_tmp;
|
|
73
|
-
|
package/jsconfig.json
DELETED