Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add alter table for existing setups #37

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
});

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/createTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);`,
Expand Down