Skip to content

Commit

Permalink
fix: schema
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Aug 10, 2024
1 parent f92fde0 commit 9859b89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ CREATE TABLE "Event" (
"ip" TEXT,
"city" TEXT,
"country" TEXT,
"created" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Event_pkey" PRIMARY KEY ("id")
CONSTRAINT "Event_pkey" PRIMARY KEY ("created","id")
);

-- CreateTable
CREATE TABLE "Impression" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"publication" TEXT NOT NULL,
"viewed" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"viewed" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Impression_pkey" PRIMARY KEY ("id")
CONSTRAINT "Impression_pkey" PRIMARY KEY ("viewed","id")
);

-- CreateIndex
CREATE INDEX "Event_created_idx" ON "Event"("created");

-- CreateIndex
CREATE INDEX "Impression_viewed_idx" ON "Impression"("viewed");
23 changes: 19 additions & 4 deletions packages/db/prisma/leafwatch/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource db {
}

model Event {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
id String @default(dbgenerated("gen_random_uuid()")) @db.Uuid
actor String?
fingerprint String?
name String
Expand All @@ -20,11 +20,26 @@ model Event {
ip String?
city String?
country String?
created DateTime @default(now())
created DateTime @default(now()) @db.Timestamptz(3)
@@id([created, id])
@@index([created])
}

model Impression {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
id String @default(dbgenerated("gen_random_uuid()")) @db.Uuid
publication String
viewed DateTime @default(now())
viewed DateTime @default(now()) @db.Timestamptz(3)
@@id([viewed, id])
@@index([viewed])
}

// Run the following command to create the extension
// CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
// Create the hypertables
// SELECT create_hypertable('"Event"', 'created', migrate_data => true);
// SELECT create_hypertable('"Impression"', 'viewed', migrate_data => true);
//
// Add retention policy
// SELECT add_retention_policy('"Event"', INTERVAL '1 year');

1 comment on commit 9859b89

@vercel
Copy link

@vercel vercel bot commented on 9859b89 Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./

heyxyz.vercel.app
web-heyxyz.vercel.app
web-git-main-heyxyz.vercel.app
hey.xyz

Please sign in to comment.