Update clickhouse tables (#11905)

Following a discussion with @Bonapara - changing the base tables
This commit is contained in:
Félix Malfait
2025-05-07 09:39:18 +02:00
committed by GitHub
parent 8b796647f9
commit 7b78b64bca
38 changed files with 345 additions and 158 deletions

View File

@ -1,10 +0,0 @@
CREATE TABLE IF NOT EXISTS auditEvent
(
`event` LowCardinality(String),
`timestamp` DateTime64(3),
`userId` String DEFAULT '',
`workspaceId` String DEFAULT '',
`properties` JSON
)
ENGINE = MergeTree
ORDER BY (event, workspaceId, userId, timestamp);

View File

@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS workspaceEvent
(
`event` LowCardinality(String) NOT NULL,
`timestamp` DateTime64(3) NOT NULL,
`userId` String DEFAULT '',
`workspaceId` String NOT NULL,
`properties` JSON
)
ENGINE = MergeTree
ORDER BY (workspaceId, event, userId, timestamp);

View File

@ -1,10 +1,10 @@
CREATE TABLE IF NOT EXISTS pageview
(
`name` LowCardinality(String),
`timestamp` DateTime64(3),
`properties` JSON,
`name` LowCardinality(String) NOT NULL,
`timestamp` DateTime64(3) NOT NULL,
`userId` String DEFAULT '',
`workspaceId` String DEFAULT ''
`workspaceId` String DEFAULT '',
`properties` JSON
)
ENGINE = MergeTree
ORDER BY (name, workspaceId, userId, timestamp);
ORDER BY (workspaceId, name, userId, timestamp);

View File

@ -1,12 +0,0 @@
CREATE TABLE IF NOT EXISTS externalEvent
(
`event` LowCardinality(String) NOT NULL,
`timestamp` DateTime64(3) NOT NULL,
`userId` String DEFAULT '',
`workspaceId` String NOT NULL,
`objectId` String NOT NULL,
`objectType` LowCardinality(String), -- TBC if it should really be a LowCardinality given custom objects
`properties` JSON
)
ENGINE = MergeTree
ORDER BY (event, workspaceId, userId, timestamp);

View File

@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS objectEvent
(
`event` LowCardinality(String) NOT NULL,
`timestamp` DateTime64(3) NOT NULL,
`userId` String DEFAULT '',
`workspaceId` String NOT NULL,
`recordId` String NOT NULL,
`objectMetadataId` String NOT NULL,
`properties` JSON,
`isCustom` Boolean DEFAULT FALSE,
)
ENGINE = MergeTree
ORDER BY (workspaceId, event, userId, timestamp);

View File

@ -10,7 +10,7 @@ config({
override: true,
});
const clickhouseUrl = () => {
const clickHouseUrl = () => {
const url = process.env.CLICKHOUSE_URL;
if (url) return url;
@ -21,7 +21,7 @@ const clickhouseUrl = () => {
};
async function ensureDatabaseExists() {
const [url, database] = clickhouseUrl().split(/\/(?=[^/]*$)/);
const [url, database] = clickHouseUrl().split(/\/(?=[^/]*$)/);
const client = createClient({
url,
});
@ -74,7 +74,7 @@ async function runMigrations() {
await ensureDatabaseExists();
const client = createClient({
url: clickhouseUrl(),
url: clickHouseUrl(),
clickhouse_settings: {
allow_experimental_json_type: 1,
},

View File

@ -1,9 +1,9 @@
import { CUSTOM_DOMAIN_ACTIVATED_EVENT } from 'src/engine/core-modules/audit/utils/events/track/custom-domain/custom-domain-activated';
import { CUSTOM_DOMAIN_DEACTIVATED_EVENT } from 'src/engine/core-modules/audit/utils/events/track/custom-domain/custom-domain-deactivated';
import { OBJECT_RECORD_CREATED_EVENT } from 'src/engine/core-modules/audit/utils/events/track/object-record/object-record-created';
import { OBJECT_RECORD_DELETED_EVENT } from 'src/engine/core-modules/audit/utils/events/track/object-record/object-record-delete';
import { OBJECT_RECORD_UPDATED_EVENT } from 'src/engine/core-modules/audit/utils/events/track/object-record/object-record-updated';
import { GenericTrackEvent } from 'src/engine/core-modules/audit/utils/events/track/track';
import { OBJECT_RECORD_CREATED_EVENT } from 'src/engine/core-modules/audit/utils/events/object-event/object-record-created';
import { OBJECT_RECORD_DELETED_EVENT } from 'src/engine/core-modules/audit/utils/events/object-event/object-record-delete';
import { OBJECT_RECORD_UPDATED_EVENT } from 'src/engine/core-modules/audit/utils/events/object-event/object-record-updated';
import { CUSTOM_DOMAIN_ACTIVATED_EVENT } from 'src/engine/core-modules/audit/utils/events/workspace-event/custom-domain/custom-domain-activated';
import { CUSTOM_DOMAIN_DEACTIVATED_EVENT } from 'src/engine/core-modules/audit/utils/events/workspace-event/custom-domain/custom-domain-deactivated';
import { GenericTrackEvent } from 'src/engine/core-modules/audit/utils/events/workspace-event/track';
export const fixtures: Array<GenericTrackEvent> = [
{

View File

@ -18,7 +18,7 @@ async function seedEvents() {
console.log(`⚡ Seeding ${fixtures.length} events...`);
await client.insert({
table: 'auditEvent',
table: 'workspaceEvent',
values: fixtures,
format: 'JSONEachRow',
});