Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions api/v1_users_developer_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ func TestV1UsersDeveloperApps(t *testing.T) {

func TestV1UsersDeveloperAppsIncludeMetrics(t *testing.T) {
app := emptyTestApp(t)
now := time.Now()
// Use UTC so api_metrics row dates align with PostgreSQL CURRENT_DATE in tests.
now := time.Now().UTC()
// AddDate(0, -1, 0) from e.g. Mar 30 normalizes to Mar 2 (same month), which would
// incorrectly include prior-month metrics in month-to-date. Use last day of prev month.
firstOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
lastOfPrevMonth := firstOfMonth.AddDate(0, 0, -1)

fixtures := database.FixtureMap{
"users": []map[string]any{
Expand All @@ -113,7 +118,7 @@ func TestV1UsersDeveloperAppsIncludeMetrics(t *testing.T) {
_, err := app.pool.Exec(t.Context(), `
INSERT INTO api_metrics_apps (date, api_key, app_name, request_count)
VALUES ($1, $2, $3, $4), ($5, $6, $7, $8)
`, now, "app_address_1", "app_name_1", 7, now.AddDate(0, -1, 0), "app_address_1", "app_name_1", 3)
`, now, "app_address_1", "app_name_1", 7, lastOfPrevMonth, "app_address_1", "app_name_1", 3)
assert.NoError(t, err)

status, body := testGet(t, app, "/v1/users/"+trashid.MustEncodeHashID(1)+"/developer-apps?include=metrics")
Expand Down
43 changes: 21 additions & 22 deletions sql/01_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
--


-- Dumped from database version 17.7 (Debian 17.7-3.pgdg13+1)
-- Dumped by pg_dump version 17.7 (Debian 17.7-3.pgdg13+1)
-- Dumped from database version 17.9 (Debian 17.9-1.pgdg13+1)
-- Dumped by pg_dump version 17.9 (Debian 17.9-1.pgdg13+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down Expand Up @@ -7140,6 +7140,17 @@ CREATE TABLE public.notification (
);


--
-- Name: notification_campaign_push_open; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.notification_campaign_push_open (
campaign_id uuid NOT NULL,
user_id integer NOT NULL,
opened_at timestamp with time zone DEFAULT now() NOT NULL
);


--
-- Name: notification_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -7173,18 +7184,6 @@ CREATE TABLE public.notification_seen (
);


--
-- Name: notification_campaign_push_open; Type: TABLE; Schema: public; Owner: -
-- Internal notification campaign id (e.g. Supabase announcement / engagement send UUID) + discovery user_id; first open per pair.
--

CREATE TABLE public.notification_campaign_push_open (
campaign_id uuid NOT NULL,
user_id integer NOT NULL,
opened_at timestamp with time zone DEFAULT now() NOT NULL
);


--
-- Name: oauth_authorization_codes; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -9981,6 +9980,14 @@ ALTER TABLE ONLY public.muted_users
ADD CONSTRAINT muted_users_pkey PRIMARY KEY (muted_user_id, user_id);


--
-- Name: notification_campaign_push_open notification_campaign_push_open_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.notification_campaign_push_open
ADD CONSTRAINT notification_campaign_push_open_pkey PRIMARY KEY (campaign_id, user_id);


--
-- Name: notification notification_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand All @@ -9997,14 +10004,6 @@ ALTER TABLE ONLY public.notification_seen
ADD CONSTRAINT notification_seen_pkey PRIMARY KEY (user_id, seen_at);


--
-- Name: notification_campaign_push_open notification_campaign_push_open_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.notification_campaign_push_open
ADD CONSTRAINT notification_campaign_push_open_pkey PRIMARY KEY (campaign_id, user_id);


--
-- Name: oauth_authorization_codes oauth_authorization_codes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down
Loading