diff --git a/modules/analytics/db/migrations/20240813023547_init/migration.sql b/modules/analytics/db/migrations/20240813023547_init/migration.sql new file mode 100644 index 00000000..ead4ba38 --- /dev/null +++ b/modules/analytics/db/migrations/20240813023547_init/migration.sql @@ -0,0 +1,16 @@ +-- Add timescale +CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; + +-- CreateTable +CREATE TABLE "event" ( + "id" UUID NOT NULL, + "timestamp" TIMESTAMPTZ NOT NULL, + "name" TEXT NOT NULL, + "metadata" JSONB +); + +-- CreateIndex +CREATE UNIQUE INDEX "event_id_key" ON "event"("id"); + +-- CreateIndex +CREATE INDEX "event_name_time_idx" ON "event"("name", "timestamp" DESC); \ No newline at end of file diff --git a/modules/analytics/db/migrations/migration_lock.toml b/modules/analytics/db/migrations/migration_lock.toml new file mode 100644 index 00000000..fbffa92c --- /dev/null +++ b/modules/analytics/db/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/modules/analytics/db/schema.prisma b/modules/analytics/db/schema.prisma new file mode 100644 index 00000000..989e1121 --- /dev/null +++ b/modules/analytics/db/schema.prisma @@ -0,0 +1,17 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") + +} + +model Event { + id String @db.Uuid @default(uuid()) @unique + timestamp DateTime @db.Timestamptz + name String + metadata Json? + + // in the init migration, we add the timescale extension and call create_hypertable(). + + @@index(fields: [name, timestamp(sort: Desc)], map: "event_name_time_idx") + @@map("event") +} diff --git a/modules/analytics/module.json b/modules/analytics/module.json index b1e72a23..f157a402 100644 --- a/modules/analytics/module.json +++ b/modules/analytics/module.json @@ -1,12 +1,15 @@ { - "name": "Analytics", - "description": "Track and visualize user behavior data. (Coming mid-2024)", - "icon": "chart-line", - "tags": [ - "game" - ], - "authors": [], - "status": "coming_soon", - "scripts": {}, - "errors": {} + "status": "stable", + "name": "Analytics", + "description": "Track and visualize user behavior data", + "icon": "chart-line", + "tags": [], + "authors": [ + "rivet-gg", + "ABCxFF" + ], + "scripts": { + }, + "errors": {}, + "dependencies": {} }