Skip to content

Commit

Permalink
add a cause column, run migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkarimoff committed Feb 5, 2024
1 parent 8c9d7dd commit 874a5e9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export const getColumns = (
<DataTableColumnHeader column={column} title="Message" />
),
},
{
accessorKey: "cause",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Cause" />
),
},
{
accessorKey: "stack",
header: "",
Expand Down
1 change: 1 addition & 0 deletions apps/analytics-web/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const eventsTable = pgTable(
message: text("message"),
name: text("name"),
stack: text("stack"),
cause: text("cause"),
metadata: json("metadata"),
},
(events) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS "events" (
"message" text,
"name" text,
"stack" text,
"cause" text,
"metadata" json
);
--> statement-breakpoint
Expand Down
8 changes: 7 additions & 1 deletion apps/analytics-web/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "13cbb638-62c2-4e6a-aef8-a17910f27456",
"id": "dd5e2f22-a389-41cc-98a4-d6b3a7a3feee",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
Expand Down Expand Up @@ -56,6 +56,12 @@
"primaryKey": false,
"notNull": false
},
"cause": {
"name": "cause",
"type": "text",
"primaryKey": false,
"notNull": false
},
"metadata": {
"name": "metadata",
"type": "json",
Expand Down
4 changes: 2 additions & 2 deletions apps/analytics-web/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1706803795839,
"tag": "0000_uneven_madame_hydra",
"when": 1707131657461,
"tag": "0000_overconfident_zzzax",
"breakpoints": true
}
]
Expand Down
21 changes: 17 additions & 4 deletions apps/analytics-web/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function seedEvents() {

try {
for (let i = 0; i < 100; i++) {
const type = faker.helpers.arrayElement(eventTypes);
const type = faker.helpers.arrayElement([...eventTypes, "Error"]);
const installationId = faker.helpers.arrayElement(installationIds);
const timestamp = faker.date.recent();
const metadata = {
Expand All @@ -27,19 +27,32 @@ async function seedEvents() {
const message = faker.lorem.sentence();
const name = faker.lorem.sentence();
const stack = faker.lorem.sentence();
const cause = faker.lorem.sentence();

const event: EventInsertType = {
const noneErrorEvent: EventInsertType = {
type,
metadata,
installationId,
timestamp,
metadata,
countryISOCode,
};

const errorEvent: EventInsertType = {
type,
installationId,
timestamp,
metadata,
countryISOCode,
message,
name,
stack,
cause,
};

await db.insert(eventsTable).values(event).returning();
await db
.insert(eventsTable)
.values(type === "Error" ? errorEvent : noneErrorEvent)
.returning();
}
} catch (error) {
console.error("Error seeding events", error);
Expand Down

0 comments on commit 874a5e9

Please sign in to comment.