Skip to content

Commit bff2ecc

Browse files
authored
Move notification campaign push open migration (#744)
1 parent 85beca9 commit bff2ecc

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

api/v1_users_developer_apps_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ func TestV1UsersDeveloperApps(t *testing.T) {
8787

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

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

119124
status, body := testGet(t, app, "/v1/users/"+trashid.MustEncodeHashID(1)+"/developer-apps?include=metrics")

sql/migrations/20260316_notification_campaign_push_open.sql renamed to ddl/migrations/0192_notification_campaign_push_open.sql

File renamed without changes.

sql/01_schema.sql

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
--
44

55

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

99
SET statement_timeout = 0;
1010
SET lock_timeout = 0;
@@ -7140,6 +7140,17 @@ CREATE TABLE public.notification (
71407140
);
71417141

71427142

7143+
--
7144+
-- Name: notification_campaign_push_open; Type: TABLE; Schema: public; Owner: -
7145+
--
7146+
7147+
CREATE TABLE public.notification_campaign_push_open (
7148+
campaign_id uuid NOT NULL,
7149+
user_id integer NOT NULL,
7150+
opened_at timestamp with time zone DEFAULT now() NOT NULL
7151+
);
7152+
7153+
71437154
--
71447155
-- Name: notification_id_seq; Type: SEQUENCE; Schema: public; Owner: -
71457156
--
@@ -7173,18 +7184,6 @@ CREATE TABLE public.notification_seen (
71737184
);
71747185

71757186

7176-
--
7177-
-- Name: notification_campaign_push_open; Type: TABLE; Schema: public; Owner: -
7178-
-- Internal notification campaign id (e.g. Supabase announcement / engagement send UUID) + discovery user_id; first open per pair.
7179-
--
7180-
7181-
CREATE TABLE public.notification_campaign_push_open (
7182-
campaign_id uuid NOT NULL,
7183-
user_id integer NOT NULL,
7184-
opened_at timestamp with time zone DEFAULT now() NOT NULL
7185-
);
7186-
7187-
71887187
--
71897188
-- Name: oauth_authorization_codes; Type: TABLE; Schema: public; Owner: -
71907189
--
@@ -9981,6 +9980,14 @@ ALTER TABLE ONLY public.muted_users
99819980
ADD CONSTRAINT muted_users_pkey PRIMARY KEY (muted_user_id, user_id);
99829981

99839982

9983+
--
9984+
-- Name: notification_campaign_push_open notification_campaign_push_open_pkey; Type: CONSTRAINT; Schema: public; Owner: -
9985+
--
9986+
9987+
ALTER TABLE ONLY public.notification_campaign_push_open
9988+
ADD CONSTRAINT notification_campaign_push_open_pkey PRIMARY KEY (campaign_id, user_id);
9989+
9990+
99849991
--
99859992
-- Name: notification notification_pkey; Type: CONSTRAINT; Schema: public; Owner: -
99869993
--
@@ -9997,14 +10004,6 @@ ALTER TABLE ONLY public.notification_seen
999710004
ADD CONSTRAINT notification_seen_pkey PRIMARY KEY (user_id, seen_at);
999810005

999910006

10000-
--
10001-
-- Name: notification_campaign_push_open notification_campaign_push_open_pkey; Type: CONSTRAINT; Schema: public; Owner: -
10002-
--
10003-
10004-
ALTER TABLE ONLY public.notification_campaign_push_open
10005-
ADD CONSTRAINT notification_campaign_push_open_pkey PRIMARY KEY (campaign_id, user_id);
10006-
10007-
1000810007
--
1000910008
-- Name: oauth_authorization_codes oauth_authorization_codes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
1001010009
--

0 commit comments

Comments
 (0)