From 6046c2600fce0a7faef521e2ef4a0932eed5d816 Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Mon, 6 Jun 2022 16:23:00 +0200 Subject: [PATCH] fix: add alter table for existing setups --- src/__tests__/index.test.js | 5 +---- src/createTable.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index 4ad8528..4417241 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -12,7 +12,7 @@ const matomoVisit = require("./visit.json"); const run = require("../index"); -const NB_REQUEST_TO_INIT_DB = 10; // Number of query to init DB (createTable.js) +const NB_REQUEST_TO_INIT_DB = 20; // Number of query to init DB (createTable.js) const TEST_DATE = new Date(); // @ts-ignore @@ -130,8 +130,6 @@ test("run: should resume using latest event date - offset if no date provided", expect(mock_matomoApi.mock.calls.length).toEqual(daysCount); // check db queries - console.log("daysCount", daysCount); - //console.log("mock_pgQuery.mock.calls", mock_pgQuery.mock.calls); expect(mock_pgQuery.mock.calls.length).toEqual(NB_REQUEST_TO_INIT_DB + 1 + daysCount * 7); // NB_REQUEST_TO_INIT_DB + select queries + days offset }); @@ -152,7 +150,6 @@ test("run: should use today date if nothing in DB", async () => { // check matomo requests expect(mock_matomoApi.mock.calls.length).toEqual(1); - console.log(TEST_DATE, isoDate(TEST_DATE)); expect(mock_matomoApi.mock.calls[0][0].date).toEqual(isoDate(TEST_DATE)); // check the 4 events inserted diff --git a/src/createTable.js b/src/createTable.js index 58eb2e3..4aa63ab 100644 --- a/src/createTable.js +++ b/src/createTable.js @@ -58,6 +58,16 @@ async function createTable(client) { `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "sitesearchkeyword" text;`, `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "action_title" text;`, `ALTER TABLE IF EXISTS ${table} ALTER COLUMN action_eventvalue TYPE decimal USING action_eventvalue::decimal;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension1" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension2" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension3" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension4" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension5" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension6" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension7" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension8" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension9" text;`, + `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "dimension10" text;`, `CREATE INDEX IF NOT EXISTS idx_action_timestamp ON ${table} (action_timestamp);`, `CREATE INDEX IF NOT EXISTS idx_idvisit ON ${table}(idvisit);`, `CREATE INDEX IF NOT EXISTS idx_action_eventcategory ON ${table}(action_eventcategory);`,