From 04c8056c5c4d3ff39edc9bff95625c75b099d5f3 Mon Sep 17 00:00:00 2001 From: hyochan Date: Fri, 16 Aug 2024 00:35:16 +0900 Subject: [PATCH] chore(prisma): purchase model --- .../20240815153355_purchase/migration.sql | 17 +++++++ prisma/schema.prisma | 18 +++++++ src/types/supabase.ts | 51 ++++++++++++++++++- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20240815153355_purchase/migration.sql diff --git a/prisma/migrations/20240815153355_purchase/migration.sql b/prisma/migrations/20240815153355_purchase/migration.sql new file mode 100644 index 0000000..4f4da4b --- /dev/null +++ b/prisma/migrations/20240815153355_purchase/migration.sql @@ -0,0 +1,17 @@ +-- CreateTable +CREATE TABLE "purchases" ( + "id" UUID NOT NULL DEFAULT gen_random_uuid(), + "points" INTEGER DEFAULT 0, + "receipt" TEXT NOT NULL, + "product_id" TEXT NOT NULL, + "device" TEXT, + "refunded" BOOLEAN DEFAULT false, + "created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP, + "user_id" UUID NOT NULL, + + CONSTRAINT "purchases_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "purchases" ADD CONSTRAINT "purchases_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ea0a7b5..d75b2dc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -68,10 +68,28 @@ model User { followers Follow[] followings Follow[] @relation("Following") pushTokens PushToken[] + purchases Purchase[] @@map("users") } +model Purchase { + id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid + points Int? @default(0) + receipt String + productId String @map("product_id") + device String? + refunded Boolean? @default(false) + + createdAt DateTime? @default(now()) @map("created_at") + updatedAt DateTime? @default(now()) @updatedAt @map("updated_at") + + user User @relation(fields: [userId], references: [id]) + userId String @map("user_id") @db.Uuid + + @@map("purchases") +} + model PushToken { id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid token String diff --git a/src/types/supabase.ts b/src/types/supabase.ts index 330639c..03162b6 100644 --- a/src/types/supabase.ts +++ b/src/types/supabase.ts @@ -374,6 +374,50 @@ export type Database = { }, ] } + purchases: { + Row: { + created_at: string | null + device: string | null + id: string + points: number | null + product_id: string + receipt: string + refunded: boolean | null + updated_at: string | null + user_id: string + } + Insert: { + created_at?: string | null + device?: string | null + id?: string + points?: number | null + product_id: string + receipt: string + refunded?: boolean | null + updated_at?: string | null + user_id: string + } + Update: { + created_at?: string | null + device?: string | null + id?: string + points?: number | null + product_id?: string + receipt?: string + refunded?: boolean | null + updated_at?: string | null + user_id?: string + } + Relationships: [ + { + foreignKeyName: "purchases_user_id_fkey" + columns: ["user_id"] + isOneToOne: false + referencedRelation: "users" + referencedColumns: ["id"] + }, + ] + } push_tokens: { Row: { created_at: string | null @@ -639,7 +683,12 @@ export type Database = { [_ in never]: never } Functions: { - [_ in never]: never + increment_view_count: { + Args: { + post_id: string + } + Returns: undefined + } } Enums: { activity_type: