Skip to content

Commit 5637208

Browse files
committed
add table for ad impressions and migrate (includes new 'ad' grant type)
1 parent 4a89b78 commit 5637208

File tree

7 files changed

+3025
-65
lines changed

7 files changed

+3025
-65
lines changed

cli/src/hooks/use-gravity-ad.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const useGravityAd = (): GravityAdState => {
115115
}
116116

117117
// Call our web API to fire impression and grant credits
118+
// Only send impUrl - server looks up trusted ad data from database
118119
fetch(`${WEBSITE_URL}/api/v1/ads/impression`, {
119120
method: 'POST',
120121
headers: {
@@ -123,7 +124,6 @@ export const useGravityAd = (): GravityAdState => {
123124
},
124125
body: JSON.stringify({
125126
impUrl: ad.impUrl,
126-
payout: ad.payout,
127127
}),
128128
})
129129
.then((res) => res.json())
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ALTER TYPE "public"."grant_type" ADD VALUE 'ad';--> statement-breakpoint
2+
CREATE TABLE "ad_impression" (
3+
"id" text PRIMARY KEY NOT NULL,
4+
"user_id" text NOT NULL,
5+
"ad_text" text NOT NULL,
6+
"title" text NOT NULL,
7+
"url" text NOT NULL,
8+
"favicon" text NOT NULL,
9+
"click_url" text NOT NULL,
10+
"imp_url" text NOT NULL,
11+
"payout" numeric(10, 6) NOT NULL,
12+
"credits_granted" integer NOT NULL,
13+
"grant_operation_id" text,
14+
"served_at" timestamp with time zone DEFAULT now() NOT NULL,
15+
"impression_fired_at" timestamp with time zone,
16+
"clicked_at" timestamp with time zone,
17+
CONSTRAINT "ad_impression_imp_url_unique" UNIQUE("imp_url")
18+
);
19+
--> statement-breakpoint
20+
ALTER TABLE "ad_impression" ADD CONSTRAINT "ad_impression_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
21+
CREATE INDEX "idx_ad_impression_user" ON "ad_impression" USING btree ("user_id","served_at");--> statement-breakpoint
22+
CREATE INDEX "idx_ad_impression_imp_url" ON "ad_impression" USING btree ("imp_url");

0 commit comments

Comments
 (0)