From c07ca82b4f0f5460681c9b47bad4d382b7986829 Mon Sep 17 00:00:00 2001 From: Jeremy <87028711+jgoldberger26@users.noreply.github.com> Date: Sat, 28 Mar 2026 13:42:29 -0400 Subject: [PATCH] Add and use event with orgids view Tests still need to be updated --- Makefile | 6 + docs/schema/schema.json | 1324 ++++++++++++++--- internal/database/models.go | 39 +- internal/database/querier.go | 10 +- internal/database/queries.sql | 36 +- internal/database/queries.sql.go | 85 +- internal/dto/dto.go | 15 +- internal/handler/events.go | 18 +- .../20260327180817_add_event_view.down.sql | 1 + .../20260327180817_add_event_view.up.sql | 8 + 10 files changed, 1265 insertions(+), 277 deletions(-) create mode 100644 migrations/20260327180817_add_event_view.down.sql create mode 100644 migrations/20260327180817_add_event_view.up.sql diff --git a/Makefile b/Makefile index 9003174..4d96c9e 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,12 @@ migrate-version: test -n "$$db_url" || (echo "Set MIGRATE_DATABASE_URL or DATABASE_URL (or add DATABASE_URL to .env)" && exit 1); \ docker run --rm --network $(COMPOSE_NETWORK) -v "$(CURDIR)/$(MIGRATIONS_DIR):/migrations" $(MIGRATE_DOCKER_IMAGE) -path /migrations -database "$$db_url" version +migrate-force: + @test -n "$(version)" || (echo "Usage: make migrate-version version=20260327180817" && exit 1) + @db_url="$${MIGRATE_DATABASE_URL:-$${DATABASE_URL:-$$(grep -E '^DATABASE_URL=' .env 2>/dev/null | head -n1 | cut -d= -f2-)}}"; \ + test -n "$$db_url" || (echo "Set MIGRATE_DATABASE_URL or DATABASE_URL (or add DATABASE_URL to .env)" && exit 1); \ + docker run --rm --network $(COMPOSE_NETWORK) -v "$(CURDIR)/$(MIGRATIONS_DIR):/migrations" $(MIGRATE_DOCKER_IMAGE) -path /migrations -database "$$db_url" force $(version) + # Build build: generate go build -o bin/capy-server ./cmd/server diff --git a/docs/schema/schema.json b/docs/schema/schema.json index 7fa7e7d..c0ec31e 100644 --- a/docs/schema/schema.json +++ b/docs/schema/schema.json @@ -584,7 +584,7 @@ "array_dims": 0 }, { - "name": "title", + "name": "location", "not_null": false, "is_array": false, "comment": "", @@ -610,7 +610,7 @@ "array_dims": 0 }, { - "name": "location", + "name": "event_time", "not_null": false, "is_array": false, "comment": "", @@ -626,8 +626,8 @@ "table_alias": "", "type": { "catalog": "", - "schema": "", - "name": "text" + "schema": "pg_catalog", + "name": "timestamp" }, "is_sqlc_slice": false, "embed_table": null, @@ -636,7 +636,7 @@ "array_dims": 0 }, { - "name": "event_time", + "name": "description", "not_null": false, "is_array": false, "comment": "", @@ -652,8 +652,8 @@ "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, @@ -662,7 +662,7 @@ "array_dims": 0 }, { - "name": "description", + "name": "date_created", "not_null": false, "is_array": false, "comment": "", @@ -679,7 +679,7 @@ "type": { "catalog": "", "schema": "", - "name": "text" + "name": "date" }, "is_sqlc_slice": false, "embed_table": null, @@ -688,7 +688,7 @@ "array_dims": 0 }, { - "name": "date_created", + "name": "date_modified", "not_null": false, "is_array": false, "comment": "", @@ -714,7 +714,7 @@ "array_dims": 0 }, { - "name": "date_modified", + "name": "title", "not_null": false, "is_array": false, "comment": "", @@ -731,7 +731,7 @@ "type": { "catalog": "", "schema": "", - "name": "date" + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, @@ -1162,6 +1162,546 @@ ], "comment": "" }, + { + "rel": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "columns": [ + { + "name": "id", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "bigserial" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "correlation_id", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "timestamp", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "timestamptz" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "received_at", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "timestamptz" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "interaction_type", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "user_id", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "int8" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "command_name", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "guild_id", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "int8" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "guild_name", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "channel_id", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "int8" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "options", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "jsonb" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "bot_version", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_interactions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + } + ], + "comment": "" + }, + { + "rel": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "columns": [ + { + "name": "id", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "bigserial" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "correlation_id", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "timestamp", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "timestamptz" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "received_at", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "timestamptz" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "command_name", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "status", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "duration_ms", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "numeric" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "error_type", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "telemetry_completions" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "varchar" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + } + ], + "comment": "" + }, { "rel": { "catalog": "", @@ -1196,8 +1736,86 @@ "array_dims": 0 }, { - "name": "endpoint_url", - "not_null": true, + "name": "endpoint_url", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "links" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "text" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "dest_url", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "links" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "text" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "oid", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "links" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "created_at", + "not_null": false, "is_array": false, "comment": "", "length": -1, @@ -1211,9 +1829,45 @@ }, "table_alias": "", "type": { + "catalog": "", + "schema": "pg_catalog", + "name": "timestamp" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + } + ], + "comment": "" + }, + { + "rel": { + "catalog": "", + "schema": "", + "name": "link_visits" + }, + "columns": [ + { + "name": "lvid", + "not_null": true, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { "catalog": "", "schema": "", - "name": "text" + "name": "link_visits" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" }, "is_sqlc_slice": false, "embed_table": null, @@ -1222,7 +1876,7 @@ "array_dims": 0 }, { - "name": "dest_url", + "name": "lid", "not_null": true, "is_array": false, "comment": "", @@ -1233,13 +1887,13 @@ "table": { "catalog": "", "schema": "", - "name": "links" + "name": "link_visits" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "uuid" }, "is_sqlc_slice": false, "embed_table": null, @@ -1248,8 +1902,8 @@ "array_dims": 0 }, { - "name": "oid", - "not_null": true, + "name": "uid", + "not_null": false, "is_array": false, "comment": "", "length": -1, @@ -1259,7 +1913,7 @@ "table": { "catalog": "", "schema": "", - "name": "links" + "name": "link_visits" }, "table_alias": "", "type": { @@ -1285,7 +1939,7 @@ "table": { "catalog": "", "schema": "", - "name": "links" + "name": "link_visits" }, "table_alias": "", "type": { @@ -1306,11 +1960,11 @@ "rel": { "catalog": "", "schema": "", - "name": "link_visits" + "name": "events_with_org_ids" }, "columns": [ { - "name": "lvid", + "name": "eid", "not_null": true, "is_array": false, "comment": "", @@ -1321,7 +1975,7 @@ "table": { "catalog": "", "schema": "", - "name": "link_visits" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -1336,8 +1990,8 @@ "array_dims": 0 }, { - "name": "lid", - "not_null": true, + "name": "location", + "not_null": false, "is_array": false, "comment": "", "length": -1, @@ -1347,13 +2001,13 @@ "table": { "catalog": "", "schema": "", - "name": "link_visits" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "uuid" + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, @@ -1362,7 +2016,7 @@ "array_dims": 0 }, { - "name": "uid", + "name": "event_time", "not_null": false, "is_array": false, "comment": "", @@ -1373,13 +2027,13 @@ "table": { "catalog": "", "schema": "", - "name": "link_visits" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "uuid" + "name": "pg_catalog.timestamp" }, "is_sqlc_slice": false, "embed_table": null, @@ -1388,7 +2042,7 @@ "array_dims": 0 }, { - "name": "created_at", + "name": "description", "not_null": false, "is_array": false, "comment": "", @@ -1399,19 +2053,123 @@ "table": { "catalog": "", "schema": "", - "name": "link_visits" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, "original_name": "", "unsigned": false, "array_dims": 0 + }, + { + "name": "date_created", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "date" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "date_modified", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "date" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "title", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "text" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "org_ids", + "not_null": true, + "is_array": true, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "", + "unsigned": false, + "array_dims": 1 } ], "comment": "" @@ -69741,7 +70499,7 @@ "insert_into_table": null }, { - "text": "SELECT eid, title, location, event_time, description, date_created, date_modified FROM events WHERE eid = $1", + "text": "SELECT eid, location, event_time, description, date_created, date_modified, title, org_ids FROM events_with_org_ids WHERE eid = $1", "name": "GetEventByID", "cmd": ":one", "columns": [ @@ -69757,7 +70515,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -69772,7 +70530,7 @@ "array_dims": 0 }, { - "name": "title", + "name": "location", "not_null": false, "is_array": false, "comment": "", @@ -69783,7 +70541,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -69793,12 +70551,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "title", + "original_name": "location", "unsigned": false, "array_dims": 0 }, { - "name": "location", + "name": "event_time", "not_null": false, "is_array": false, "comment": "", @@ -69809,22 +70567,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "pg_catalog.timestamp" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "location", + "original_name": "event_time", "unsigned": false, "array_dims": 0 }, { - "name": "event_time", + "name": "description", "not_null": false, "is_array": false, "comment": "", @@ -69835,22 +70593,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "event_time", + "original_name": "description", "unsigned": false, "array_dims": 0 }, { - "name": "description", + "name": "date_created", "not_null": false, "is_array": false, "comment": "", @@ -69861,22 +70619,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "date" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "description", + "original_name": "date_created", "unsigned": false, "array_dims": 0 }, { - "name": "date_created", + "name": "date_modified", "not_null": false, "is_array": false, "comment": "", @@ -69887,7 +70645,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -69897,12 +70655,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_created", + "original_name": "date_modified", "unsigned": false, "array_dims": 0 }, { - "name": "date_modified", + "name": "title", "not_null": false, "is_array": false, "comment": "", @@ -69913,19 +70671,45 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "date" + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_modified", + "original_name": "title", "unsigned": false, "array_dims": 0 + }, + { + "name": "org_ids", + "not_null": true, + "is_array": true, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "org_ids", + "unsigned": false, + "array_dims": 1 } ], "params": [ @@ -69943,7 +70727,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -69964,7 +70748,7 @@ "insert_into_table": null }, { - "text": "SELECT eid, title, location, event_time, description, date_created, date_modified FROM events ORDER BY event_time DESC LIMIT $1 OFFSET $2", + "text": "SELECT eid, location, event_time, description, date_created, date_modified, title, org_ids FROM events_with_org_ids ORDER BY event_time DESC LIMIT $1 OFFSET $2", "name": "ListEvents", "cmd": ":many", "columns": [ @@ -69980,7 +70764,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -69994,32 +70778,6 @@ "unsigned": false, "array_dims": 0 }, - { - "name": "title", - "not_null": false, - "is_array": false, - "comment": "", - "length": -1, - "is_named_param": false, - "is_func_call": false, - "scope": "", - "table": { - "catalog": "", - "schema": "", - "name": "events" - }, - "table_alias": "", - "type": { - "catalog": "", - "schema": "", - "name": "text" - }, - "is_sqlc_slice": false, - "embed_table": null, - "original_name": "title", - "unsigned": false, - "array_dims": 0 - }, { "name": "location", "not_null": false, @@ -70032,7 +70790,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70058,13 +70816,13 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "pg_catalog.timestamp" }, "is_sqlc_slice": false, "embed_table": null, @@ -70084,7 +70842,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70110,7 +70868,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70136,7 +70894,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70149,6 +70907,58 @@ "original_name": "date_modified", "unsigned": false, "array_dims": 0 + }, + { + "name": "title", + "not_null": false, + "is_array": false, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "text" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "title", + "unsigned": false, + "array_dims": 0 + }, + { + "name": "org_ids", + "not_null": true, + "is_array": true, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "org_ids", + "unsigned": false, + "array_dims": 1 } ], "params": [ @@ -70208,7 +71018,7 @@ "insert_into_table": null }, { - "text": "SELECT e.eid, e.title, e.location, e.event_time, e.description, e.date_created, e.date_modified\nFROM events e\nJOIN event_hosting eh ON e.eid = eh.eid\nWHERE eh.oid = $1\nORDER BY e.event_time DESC\nLIMIT $2 OFFSET $3", + "text": "SELECT e.eid, e.location, e.event_time, e.description, e.date_created, e.date_modified, e.title, e.org_ids\nFROM events_with_org_ids e\nJOIN event_hosting eh ON e.eid = eh.eid\nWHERE eh.oid = $1\nORDER BY e.event_time DESC\nLIMIT $2 OFFSET $3", "name": "ListEventsByOrg", "cmd": ":many", "columns": [ @@ -70224,7 +71034,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70239,7 +71049,7 @@ "array_dims": 0 }, { - "name": "title", + "name": "location", "not_null": false, "is_array": false, "comment": "", @@ -70250,7 +71060,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70260,12 +71070,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "title", + "original_name": "location", "unsigned": false, "array_dims": 0 }, { - "name": "location", + "name": "event_time", "not_null": false, "is_array": false, "comment": "", @@ -70276,22 +71086,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "pg_catalog.timestamp" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "location", + "original_name": "event_time", "unsigned": false, "array_dims": 0 }, { - "name": "event_time", + "name": "description", "not_null": false, "is_array": false, "comment": "", @@ -70302,22 +71112,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "event_time", + "original_name": "description", "unsigned": false, "array_dims": 0 }, { - "name": "description", + "name": "date_created", "not_null": false, "is_array": false, "comment": "", @@ -70328,22 +71138,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "date" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "description", + "original_name": "date_created", "unsigned": false, "array_dims": 0 }, { - "name": "date_created", + "name": "date_modified", "not_null": false, "is_array": false, "comment": "", @@ -70354,7 +71164,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70364,12 +71174,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_created", + "original_name": "date_modified", "unsigned": false, "array_dims": 0 }, { - "name": "date_modified", + "name": "title", "not_null": false, "is_array": false, "comment": "", @@ -70380,19 +71190,45 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "date" + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_modified", + "original_name": "title", "unsigned": false, "array_dims": 0 + }, + { + "name": "org_ids", + "not_null": true, + "is_array": true, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "org_ids", + "unsigned": false, + "array_dims": 1 } ], "params": [ @@ -70481,7 +71317,7 @@ "insert_into_table": null }, { - "text": "INSERT INTO events (title, location, event_time, description)\nVALUES ($1, $2, $3, $4)\nRETURNING eid, title, location, event_time, description, date_created, date_modified", + "text": "WITH updated AS (\n INSERT INTO events (title, location, event_time, description)\n VALUES ($1, $2, $3, $4)\n RETURNING eid, location, event_time, description, date_created, date_modified, title\n)\nSELECT v.eid, v.location, v.event_time, v.description, v.date_created, v.date_modified, v.title, v.org_ids FROM events_with_org_ids v\nWHERE v.eid = (SELECT eid FROM updated)", "name": "CreateEvent", "cmd": ":one", "columns": [ @@ -70497,7 +71333,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70512,7 +71348,7 @@ "array_dims": 0 }, { - "name": "title", + "name": "location", "not_null": false, "is_array": false, "comment": "", @@ -70523,7 +71359,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70533,12 +71369,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "title", + "original_name": "location", "unsigned": false, "array_dims": 0 }, { - "name": "location", + "name": "event_time", "not_null": false, "is_array": false, "comment": "", @@ -70549,22 +71385,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "pg_catalog.timestamp" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "location", + "original_name": "event_time", "unsigned": false, "array_dims": 0 }, { - "name": "event_time", + "name": "description", "not_null": false, "is_array": false, "comment": "", @@ -70575,22 +71411,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "event_time", + "original_name": "description", "unsigned": false, "array_dims": 0 }, { - "name": "description", + "name": "date_created", "not_null": false, "is_array": false, "comment": "", @@ -70601,22 +71437,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "date" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "description", + "original_name": "date_created", "unsigned": false, "array_dims": 0 }, { - "name": "date_created", + "name": "date_modified", "not_null": false, "is_array": false, "comment": "", @@ -70627,7 +71463,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70637,12 +71473,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_created", + "original_name": "date_modified", "unsigned": false, "array_dims": 0 }, { - "name": "date_modified", + "name": "title", "not_null": false, "is_array": false, "comment": "", @@ -70653,19 +71489,45 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "date" + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_modified", + "original_name": "title", "unsigned": false, "array_dims": 0 + }, + { + "name": "org_ids", + "not_null": true, + "is_array": true, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "org_ids", + "unsigned": false, + "array_dims": 1 } ], "params": [ @@ -70788,14 +71650,10 @@ ], "comments": [], "filename": "queries.sql", - "insert_into_table": { - "catalog": "", - "schema": "", - "name": "events" - } + "insert_into_table": null }, { - "text": "UPDATE events\nSET title = COALESCE($2, title),\n location = COALESCE($3, location),\n event_time = COALESCE($4, event_time),\n description = COALESCE($5, description)\nWHERE eid = $1\nRETURNING eid, title, location, event_time, description, date_created, date_modified", + "text": "WITH updated AS (\n UPDATE events\n SET title = COALESCE($2, title),\n location = COALESCE($3, location),\n event_time = COALESCE($4, event_time),\n description = COALESCE($5, description)\n WHERE eid = $1\n RETURNING eid, location, event_time, description, date_created, date_modified, title\n)\nSELECT v.eid, v.location, v.event_time, v.description, v.date_created, v.date_modified, v.title, v.org_ids FROM events_with_org_ids v\nWHERE v.eid = $1", "name": "UpdateEvent", "cmd": ":one", "columns": [ @@ -70811,7 +71669,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70826,7 +71684,7 @@ "array_dims": 0 }, { - "name": "title", + "name": "location", "not_null": false, "is_array": false, "comment": "", @@ -70837,7 +71695,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70847,12 +71705,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "title", + "original_name": "location", "unsigned": false, "array_dims": 0 }, { - "name": "location", + "name": "event_time", "not_null": false, "is_array": false, "comment": "", @@ -70863,22 +71721,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "pg_catalog.timestamp" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "location", + "original_name": "event_time", "unsigned": false, "array_dims": 0 }, { - "name": "event_time", + "name": "description", "not_null": false, "is_array": false, "comment": "", @@ -70889,22 +71747,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "event_time", + "original_name": "description", "unsigned": false, "array_dims": 0 }, { - "name": "description", + "name": "date_created", "not_null": false, "is_array": false, "comment": "", @@ -70915,22 +71773,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "date" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "description", + "original_name": "date_created", "unsigned": false, "array_dims": 0 }, { - "name": "date_created", + "name": "date_modified", "not_null": false, "is_array": false, "comment": "", @@ -70941,7 +71799,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -70951,12 +71809,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_created", + "original_name": "date_modified", "unsigned": false, "array_dims": 0 }, { - "name": "date_modified", + "name": "title", "not_null": false, "is_array": false, "comment": "", @@ -70967,19 +71825,45 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "date" + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_modified", + "original_name": "title", "unsigned": false, "array_dims": 0 + }, + { + "name": "org_ids", + "not_null": true, + "is_array": true, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "org_ids", + "unsigned": false, + "array_dims": 1 } ], "params": [ @@ -70997,7 +71881,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -71026,7 +71910,7 @@ "table": { "catalog": "", "schema": "public", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -71055,7 +71939,7 @@ "table": { "catalog": "", "schema": "public", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -71084,7 +71968,7 @@ "table": { "catalog": "", "schema": "public", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -71113,7 +71997,7 @@ "table": { "catalog": "", "schema": "public", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -71889,7 +72773,7 @@ "insert_into_table": null }, { - "text": "SELECT e.eid, e.title, e.location, e.event_time, e.description, e.date_created, e.date_modified, er.is_attending, er.is_admin, er.date_registered\nFROM events e\nJOIN event_registrations er ON e.eid = er.eid\nWHERE er.uid = $1\nORDER BY e.event_time DESC", + "text": "SELECT e.eid, e.location, e.event_time, e.description, e.date_created, e.date_modified, e.title, e.org_ids, er.is_attending, er.is_admin, er.date_registered\nFROM events_with_org_ids e\nJOIN event_registrations er ON e.eid = er.eid\nWHERE er.uid = $1\nORDER BY e.event_time DESC", "name": "GetUserEvents", "cmd": ":many", "columns": [ @@ -71905,7 +72789,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -71920,7 +72804,7 @@ "array_dims": 0 }, { - "name": "title", + "name": "location", "not_null": false, "is_array": false, "comment": "", @@ -71931,7 +72815,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -71941,12 +72825,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "title", + "original_name": "location", "unsigned": false, "array_dims": 0 }, { - "name": "location", + "name": "event_time", "not_null": false, "is_array": false, "comment": "", @@ -71957,22 +72841,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "pg_catalog.timestamp" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "location", + "original_name": "event_time", "unsigned": false, "array_dims": 0 }, { - "name": "event_time", + "name": "description", "not_null": false, "is_array": false, "comment": "", @@ -71983,22 +72867,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", - "schema": "pg_catalog", - "name": "timestamp" + "schema": "", + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "event_time", + "original_name": "description", "unsigned": false, "array_dims": 0 }, { - "name": "description", + "name": "date_created", "not_null": false, "is_array": false, "comment": "", @@ -72009,22 +72893,22 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "text" + "name": "date" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "description", + "original_name": "date_created", "unsigned": false, "array_dims": 0 }, { - "name": "date_created", + "name": "date_modified", "not_null": false, "is_array": false, "comment": "", @@ -72035,7 +72919,7 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { @@ -72045,12 +72929,12 @@ }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_created", + "original_name": "date_modified", "unsigned": false, "array_dims": 0 }, { - "name": "date_modified", + "name": "title", "not_null": false, "is_array": false, "comment": "", @@ -72061,20 +72945,46 @@ "table": { "catalog": "", "schema": "", - "name": "events" + "name": "events_with_org_ids" }, "table_alias": "", "type": { "catalog": "", "schema": "", - "name": "date" + "name": "text" }, "is_sqlc_slice": false, "embed_table": null, - "original_name": "date_modified", + "original_name": "title", "unsigned": false, "array_dims": 0 }, + { + "name": "org_ids", + "not_null": true, + "is_array": true, + "comment": "", + "length": -1, + "is_named_param": false, + "is_func_call": false, + "scope": "", + "table": { + "catalog": "", + "schema": "", + "name": "events_with_org_ids" + }, + "table_alias": "", + "type": { + "catalog": "", + "schema": "", + "name": "uuid" + }, + "is_sqlc_slice": false, + "embed_table": null, + "original_name": "org_ids", + "unsigned": false, + "array_dims": 1 + }, { "name": "is_attending", "not_null": false, diff --git a/internal/database/models.go b/internal/database/models.go index a264815..9e8e147 100644 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -70,12 +70,12 @@ type BotToken struct { type Event struct { Eid uuid.UUID `json:"eid"` - Title pgtype.Text `json:"title"` Location pgtype.Text `json:"location"` EventTime pgtype.Timestamp `json:"event_time"` Description pgtype.Text `json:"description"` DateCreated pgtype.Date `json:"date_created"` DateModified pgtype.Date `json:"date_modified"` + Title pgtype.Text `json:"title"` } type EventHosting struct { @@ -91,6 +91,17 @@ type EventRegistration struct { DateRegistered pgtype.Date `json:"date_registered"` } +type EventsWithOrgID struct { + Eid uuid.UUID `json:"eid"` + Location pgtype.Text `json:"location"` + EventTime pgtype.Timestamp `json:"event_time"` + Description pgtype.Text `json:"description"` + DateCreated pgtype.Date `json:"date_created"` + DateModified pgtype.Date `json:"date_modified"` + Title pgtype.Text `json:"title"` + OrgIds []uuid.UUID `json:"org_ids"` +} + type Link struct { Lid uuid.UUID `json:"lid"` EndpointUrl string `json:"endpoint_url"` @@ -121,6 +132,32 @@ type Organization struct { DateModified pgtype.Date `json:"date_modified"` } +type TelemetryCompletion struct { + ID int64 `json:"id"` + CorrelationID string `json:"correlation_id"` + Timestamp pgtype.Timestamptz `json:"timestamp"` + ReceivedAt pgtype.Timestamptz `json:"received_at"` + CommandName string `json:"command_name"` + Status string `json:"status"` + DurationMs pgtype.Numeric `json:"duration_ms"` + ErrorType pgtype.Text `json:"error_type"` +} + +type TelemetryInteraction struct { + ID int64 `json:"id"` + CorrelationID string `json:"correlation_id"` + Timestamp pgtype.Timestamptz `json:"timestamp"` + ReceivedAt pgtype.Timestamptz `json:"received_at"` + InteractionType string `json:"interaction_type"` + UserID int64 `json:"user_id"` + CommandName pgtype.Text `json:"command_name"` + GuildID pgtype.Int8 `json:"guild_id"` + GuildName pgtype.Text `json:"guild_name"` + ChannelID int64 `json:"channel_id"` + Options []byte `json:"options"` + BotVersion string `json:"bot_version"` +} + type User struct { Uid uuid.UUID `json:"uid"` FirstName string `json:"first_name"` diff --git a/internal/database/querier.go b/internal/database/querier.go index 7284a32..ce2f4d6 100644 --- a/internal/database/querier.go +++ b/internal/database/querier.go @@ -15,7 +15,7 @@ type Querier interface { AddEventHost(ctx context.Context, arg AddEventHostParams) error AddOrgMember(ctx context.Context, arg AddOrgMemberParams) error CreateBotToken(ctx context.Context, arg CreateBotTokenParams) (BotToken, error) - CreateEvent(ctx context.Context, arg CreateEventParams) (Event, error) + CreateEvent(ctx context.Context, arg CreateEventParams) (EventsWithOrgID, error) // Link Queries CreateLink(ctx context.Context, arg CreateLinkParams) (Link, error) CreateOrganization(ctx context.Context, name string) (Organization, error) @@ -26,7 +26,7 @@ type Querier interface { DeleteUser(ctx context.Context, uid uuid.UUID) error // Bot Token Queries GetBotTokenByID(ctx context.Context, tokenID uuid.UUID) (BotToken, error) - GetEventByID(ctx context.Context, eid uuid.UUID) (Event, error) + GetEventByID(ctx context.Context, eid uuid.UUID) (EventsWithOrgID, error) GetEventRegistrations(ctx context.Context, eid uuid.UUID) ([]GetEventRegistrationsRow, error) GetLinkByEndpointURL(ctx context.Context, endpointUrl string) (Link, error) GetLinkByLID(ctx context.Context, lid uuid.UUID) (Link, error) @@ -40,8 +40,8 @@ type Querier interface { IsEventAdmin(ctx context.Context, arg IsEventAdminParams) (pgtype.Bool, error) IsOrgAdmin(ctx context.Context, arg IsOrgAdminParams) (pgtype.Bool, error) ListBotTokens(ctx context.Context) ([]ListBotTokensRow, error) - ListEvents(ctx context.Context, arg ListEventsParams) ([]Event, error) - ListEventsByOrg(ctx context.Context, arg ListEventsByOrgParams) ([]Event, error) + ListEvents(ctx context.Context, arg ListEventsParams) ([]EventsWithOrgID, error) + ListEventsByOrg(ctx context.Context, arg ListEventsByOrgParams) ([]EventsWithOrgID, error) ListLinksByOrg(ctx context.Context, oid uuid.UUID) ([]Link, error) ListOrganizations(ctx context.Context, arg ListOrganizationsParams) ([]Organization, error) ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error) @@ -51,7 +51,7 @@ type Querier interface { RevokeBotToken(ctx context.Context, tokenID uuid.UUID) error UnregisterFromEvent(ctx context.Context, arg UnregisterFromEventParams) error UpdateBotTokenLastUsed(ctx context.Context, tokenID uuid.UUID) error - UpdateEvent(ctx context.Context, arg UpdateEventParams) (Event, error) + UpdateEvent(ctx context.Context, arg UpdateEventParams) (EventsWithOrgID, error) UpdateLink(ctx context.Context, arg UpdateLinkParams) (Link, error) UpdateOrganization(ctx context.Context, arg UpdateOrganizationParams) (Organization, error) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) diff --git a/internal/database/queries.sql b/internal/database/queries.sql index b47282a..5159491 100644 --- a/internal/database/queries.sql +++ b/internal/database/queries.sql @@ -73,32 +73,40 @@ WHERE om.uid = $1 ORDER BY o.name; -- name: GetEventByID :one -SELECT * FROM events WHERE eid = $1; +SELECT * FROM events_with_org_ids WHERE eid = $1; -- name: ListEvents :many -SELECT * FROM events ORDER BY event_time DESC LIMIT $1 OFFSET $2; +SELECT * FROM events_with_org_ids ORDER BY event_time DESC LIMIT $1 OFFSET $2; -- name: ListEventsByOrg :many SELECT e.* -FROM events e +FROM events_with_org_ids e JOIN event_hosting eh ON e.eid = eh.eid WHERE eh.oid = $1 ORDER BY e.event_time DESC LIMIT $2 OFFSET $3; -- name: CreateEvent :one -INSERT INTO events (title, location, event_time, description) -VALUES ($1, $2, $3, $4) -RETURNING *; +WITH updated AS ( + INSERT INTO events (title, location, event_time, description) + VALUES ($1, $2, $3, $4) + RETURNING * +) +SELECT v.* FROM events_with_org_ids v +WHERE v.eid = (SELECT eid FROM updated); -- name: UpdateEvent :one -UPDATE events -SET title = COALESCE(sqlc.narg('title'), title), - location = COALESCE(sqlc.narg('location'), location), - event_time = COALESCE(sqlc.narg('event_time'), event_time), - description = COALESCE(sqlc.narg('description'), description) -WHERE eid = $1 -RETURNING *; +WITH updated AS ( + UPDATE events + SET title = COALESCE(sqlc.narg('title'), title), + location = COALESCE(sqlc.narg('location'), location), + event_time = COALESCE(sqlc.narg('event_time'), event_time), + description = COALESCE(sqlc.narg('description'), description) + WHERE eid = $1 + RETURNING * +) +SELECT v.* FROM events_with_org_ids v +WHERE v.eid = $1; -- name: DeleteEvent :exec DELETE FROM events WHERE eid = $1; @@ -142,7 +150,7 @@ OR EXISTS ( -- name: GetUserEvents :many SELECT e.*, er.is_attending, er.is_admin, er.date_registered -FROM events e +FROM events_with_org_ids e JOIN event_registrations er ON e.eid = er.eid WHERE er.uid = $1 ORDER BY e.event_time DESC; diff --git a/internal/database/queries.sql.go b/internal/database/queries.sql.go index 6150227..9fbc29d 100644 --- a/internal/database/queries.sql.go +++ b/internal/database/queries.sql.go @@ -80,9 +80,13 @@ func (q *Queries) CreateBotToken(ctx context.Context, arg CreateBotTokenParams) } const createEvent = `-- name: CreateEvent :one -INSERT INTO events (title, location, event_time, description) -VALUES ($1, $2, $3, $4) -RETURNING eid, title, location, event_time, description, date_created, date_modified +WITH updated AS ( + INSERT INTO events (title, location, event_time, description) + VALUES ($1, $2, $3, $4) + RETURNING eid, location, event_time, description, date_created, date_modified, title +) +SELECT v.eid, v.location, v.event_time, v.description, v.date_created, v.date_modified, v.title, v.org_ids FROM events_with_org_ids v +WHERE v.eid = (SELECT eid FROM updated) ` type CreateEventParams struct { @@ -92,22 +96,23 @@ type CreateEventParams struct { Description pgtype.Text `json:"description"` } -func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Event, error) { +func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (EventsWithOrgID, error) { row := q.db.QueryRow(ctx, createEvent, arg.Title, arg.Location, arg.EventTime, arg.Description, ) - var i Event + var i EventsWithOrgID err := row.Scan( &i.Eid, - &i.Title, &i.Location, &i.EventTime, &i.Description, &i.DateCreated, &i.DateModified, + &i.Title, + &i.OrgIds, ) return i, err } @@ -258,20 +263,21 @@ func (q *Queries) GetBotTokenByID(ctx context.Context, tokenID uuid.UUID) (BotTo } const getEventByID = `-- name: GetEventByID :one -SELECT eid, title, location, event_time, description, date_created, date_modified FROM events WHERE eid = $1 +SELECT eid, location, event_time, description, date_created, date_modified, title, org_ids FROM events_with_org_ids WHERE eid = $1 ` -func (q *Queries) GetEventByID(ctx context.Context, eid uuid.UUID) (Event, error) { +func (q *Queries) GetEventByID(ctx context.Context, eid uuid.UUID) (EventsWithOrgID, error) { row := q.db.QueryRow(ctx, getEventByID, eid) - var i Event + var i EventsWithOrgID err := row.Scan( &i.Eid, - &i.Title, &i.Location, &i.EventTime, &i.Description, &i.DateCreated, &i.DateModified, + &i.Title, + &i.OrgIds, ) return i, err } @@ -498,8 +504,8 @@ func (q *Queries) GetUserByID(ctx context.Context, uid uuid.UUID) (User, error) } const getUserEvents = `-- name: GetUserEvents :many -SELECT e.eid, e.title, e.location, e.event_time, e.description, e.date_created, e.date_modified, er.is_attending, er.is_admin, er.date_registered -FROM events e +SELECT e.eid, e.location, e.event_time, e.description, e.date_created, e.date_modified, e.title, e.org_ids, er.is_attending, er.is_admin, er.date_registered +FROM events_with_org_ids e JOIN event_registrations er ON e.eid = er.eid WHERE er.uid = $1 ORDER BY e.event_time DESC @@ -507,12 +513,13 @@ ORDER BY e.event_time DESC type GetUserEventsRow struct { Eid uuid.UUID `json:"eid"` - Title pgtype.Text `json:"title"` Location pgtype.Text `json:"location"` EventTime pgtype.Timestamp `json:"event_time"` Description pgtype.Text `json:"description"` DateCreated pgtype.Date `json:"date_created"` DateModified pgtype.Date `json:"date_modified"` + Title pgtype.Text `json:"title"` + OrgIds []uuid.UUID `json:"org_ids"` IsAttending pgtype.Bool `json:"is_attending"` IsAdmin pgtype.Bool `json:"is_admin"` DateRegistered pgtype.Date `json:"date_registered"` @@ -529,12 +536,13 @@ func (q *Queries) GetUserEvents(ctx context.Context, uid uuid.UUID) ([]GetUserEv var i GetUserEventsRow if err := rows.Scan( &i.Eid, - &i.Title, &i.Location, &i.EventTime, &i.Description, &i.DateCreated, &i.DateModified, + &i.Title, + &i.OrgIds, &i.IsAttending, &i.IsAdmin, &i.DateRegistered, @@ -684,7 +692,7 @@ func (q *Queries) ListBotTokens(ctx context.Context) ([]ListBotTokensRow, error) } const listEvents = `-- name: ListEvents :many -SELECT eid, title, location, event_time, description, date_created, date_modified FROM events ORDER BY event_time DESC LIMIT $1 OFFSET $2 +SELECT eid, location, event_time, description, date_created, date_modified, title, org_ids FROM events_with_org_ids ORDER BY event_time DESC LIMIT $1 OFFSET $2 ` type ListEventsParams struct { @@ -692,23 +700,24 @@ type ListEventsParams struct { Offset int32 `json:"offset"` } -func (q *Queries) ListEvents(ctx context.Context, arg ListEventsParams) ([]Event, error) { +func (q *Queries) ListEvents(ctx context.Context, arg ListEventsParams) ([]EventsWithOrgID, error) { rows, err := q.db.Query(ctx, listEvents, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() - items := []Event{} + items := []EventsWithOrgID{} for rows.Next() { - var i Event + var i EventsWithOrgID if err := rows.Scan( &i.Eid, - &i.Title, &i.Location, &i.EventTime, &i.Description, &i.DateCreated, &i.DateModified, + &i.Title, + &i.OrgIds, ); err != nil { return nil, err } @@ -721,8 +730,8 @@ func (q *Queries) ListEvents(ctx context.Context, arg ListEventsParams) ([]Event } const listEventsByOrg = `-- name: ListEventsByOrg :many -SELECT e.eid, e.title, e.location, e.event_time, e.description, e.date_created, e.date_modified -FROM events e +SELECT e.eid, e.location, e.event_time, e.description, e.date_created, e.date_modified, e.title, e.org_ids +FROM events_with_org_ids e JOIN event_hosting eh ON e.eid = eh.eid WHERE eh.oid = $1 ORDER BY e.event_time DESC @@ -735,23 +744,24 @@ type ListEventsByOrgParams struct { Offset int32 `json:"offset"` } -func (q *Queries) ListEventsByOrg(ctx context.Context, arg ListEventsByOrgParams) ([]Event, error) { +func (q *Queries) ListEventsByOrg(ctx context.Context, arg ListEventsByOrgParams) ([]EventsWithOrgID, error) { rows, err := q.db.Query(ctx, listEventsByOrg, arg.Oid, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() - items := []Event{} + items := []EventsWithOrgID{} for rows.Next() { - var i Event + var i EventsWithOrgID if err := rows.Scan( &i.Eid, - &i.Title, &i.Location, &i.EventTime, &i.Description, &i.DateCreated, &i.DateModified, + &i.Title, + &i.OrgIds, ); err != nil { return nil, err } @@ -954,13 +964,17 @@ func (q *Queries) UpdateBotTokenLastUsed(ctx context.Context, tokenID uuid.UUID) } const updateEvent = `-- name: UpdateEvent :one -UPDATE events -SET title = COALESCE($2, title), - location = COALESCE($3, location), - event_time = COALESCE($4, event_time), - description = COALESCE($5, description) -WHERE eid = $1 -RETURNING eid, title, location, event_time, description, date_created, date_modified +WITH updated AS ( + UPDATE events + SET title = COALESCE($2, title), + location = COALESCE($3, location), + event_time = COALESCE($4, event_time), + description = COALESCE($5, description) + WHERE eid = $1 + RETURNING eid, location, event_time, description, date_created, date_modified, title +) +SELECT v.eid, v.location, v.event_time, v.description, v.date_created, v.date_modified, v.title, v.org_ids FROM events_with_org_ids v +WHERE v.eid = $1 ` type UpdateEventParams struct { @@ -971,7 +985,7 @@ type UpdateEventParams struct { Description pgtype.Text `json:"description"` } -func (q *Queries) UpdateEvent(ctx context.Context, arg UpdateEventParams) (Event, error) { +func (q *Queries) UpdateEvent(ctx context.Context, arg UpdateEventParams) (EventsWithOrgID, error) { row := q.db.QueryRow(ctx, updateEvent, arg.Eid, arg.Title, @@ -979,15 +993,16 @@ func (q *Queries) UpdateEvent(ctx context.Context, arg UpdateEventParams) (Event arg.EventTime, arg.Description, ) - var i Event + var i EventsWithOrgID err := row.Scan( &i.Eid, - &i.Title, &i.Location, &i.EventTime, &i.Description, &i.DateCreated, &i.DateModified, + &i.Title, + &i.OrgIds, ) return i, err } diff --git a/internal/dto/dto.go b/internal/dto/dto.go index 4563dca..6b1781f 100644 --- a/internal/dto/dto.go +++ b/internal/dto/dto.go @@ -98,13 +98,14 @@ type UpdateEventRequest struct { } type EventResponse struct { - EID uuid.UUID `json:"eid"` - Title *string `json:"title,omitempty"` - Location *string `json:"location,omitempty"` - EventTime *time.Time `json:"event_time,omitempty"` - Description *string `json:"description,omitempty"` - DateCreated *time.Time `json:"date_created,omitempty"` - DateModified *time.Time `json:"date_modified,omitempty"` + EID uuid.UUID `json:"eid"` + Organizations []uuid.UUID `json:"oids"` + Title *string `json:"title,omitempty"` + Location *string `json:"location,omitempty"` + EventTime *time.Time `json:"event_time,omitempty"` + Description *string `json:"description,omitempty"` + DateCreated *time.Time `json:"date_created,omitempty"` + DateModified *time.Time `json:"date_modified,omitempty"` } type EventRegistrationResponse struct { diff --git a/internal/handler/events.go b/internal/handler/events.go index 46d6a5d..b237796 100644 --- a/internal/handler/events.go +++ b/internal/handler/events.go @@ -417,14 +417,16 @@ func (h *Handler) ListEventsByOrg(w http.ResponseWriter, r *http.Request) { } // Helper functions -func toEventResponse(event database.Event) dto.EventResponse { +func toEventResponse(event database.EventsWithOrgID) dto.EventResponse { + return dto.EventResponse{ - EID: event.Eid, - Title: fromPgText(event.Title), - Location: fromPgText(event.Location), - EventTime: fromPgTimestamp(event.EventTime), - Description: fromPgText(event.Description), - DateCreated: fromPgDate(event.DateCreated), - DateModified: fromPgDate(event.DateModified), + EID: event.Eid, + Organizations: event.OrgIds, + Title: fromPgText(event.Title), + Location: fromPgText(event.Location), + EventTime: fromPgTimestamp(event.EventTime), + Description: fromPgText(event.Description), + DateCreated: fromPgDate(event.DateCreated), + DateModified: fromPgDate(event.DateModified), } } diff --git a/migrations/20260327180817_add_event_view.down.sql b/migrations/20260327180817_add_event_view.down.sql new file mode 100644 index 0000000..bdeb469 --- /dev/null +++ b/migrations/20260327180817_add_event_view.down.sql @@ -0,0 +1 @@ +DROP VIEW events_with_org_ids \ No newline at end of file diff --git a/migrations/20260327180817_add_event_view.up.sql b/migrations/20260327180817_add_event_view.up.sql new file mode 100644 index 0000000..3bd1bc4 --- /dev/null +++ b/migrations/20260327180817_add_event_view.up.sql @@ -0,0 +1,8 @@ +CREATE VIEW events_with_org_ids AS + SELECT + e.*, + ARRAY_AGG(eh.oid)::uuid[] AS org_ids + FROM events e + LEFT JOIN event_hosting eh ON e.eid = eh.eid + GROUP BY + e.eid;