feat: create community suggestions table
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
CREATE TYPE "public"."suggestion_status" AS ENUM('pending', 'approved', 'rejected');--> statement-breakpoint
|
||||
CREATE TABLE "community_suggestions" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"game_id" text NOT NULL,
|
||||
"user_id" text NOT NULL,
|
||||
"field_name" text NOT NULL,
|
||||
"current_value" text,
|
||||
"proposed_value" text NOT NULL,
|
||||
"reason" text,
|
||||
"status" "suggestion_status" DEFAULT 'pending' NOT NULL,
|
||||
"reviewed_by" text,
|
||||
"reviewed_at" timestamp,
|
||||
"review_note" text,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "community_suggestions" ADD CONSTRAINT "community_suggestions_game_id_games_id_fk" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "community_suggestions" ADD CONSTRAINT "community_suggestions_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "community_suggestions" ADD CONSTRAINT "community_suggestions_reviewed_by_user_id_fk" FOREIGN KEY ("reviewed_by") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "community_suggestions_game_field_user" ON "community_suggestions" USING btree ("game_id","field_name","user_id");
|
||||
File diff suppressed because it is too large
Load Diff
@@ -134,6 +134,13 @@
|
||||
"when": 1777547028555,
|
||||
"tag": "0018_slimy_proemial_gods",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 19,
|
||||
"version": "7",
|
||||
"when": 1777547264277,
|
||||
"tag": "0019_tiresome_genesis",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import {
|
||||
pgEnum,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core"
|
||||
import { games } from "./games"
|
||||
import { user } from "./auth"
|
||||
|
||||
export const suggestionStatusEnum = pgEnum("suggestion_status", [
|
||||
"pending",
|
||||
"approved",
|
||||
"rejected",
|
||||
])
|
||||
|
||||
export const communitySuggestions = pgTable(
|
||||
"community_suggestions",
|
||||
{
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
gameId: text("game_id")
|
||||
.notNull()
|
||||
.references(() => games.id, { onDelete: "cascade" }),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
fieldName: text("field_name").notNull(), // e.g. "title", "description", "developer"
|
||||
currentValue: text("current_value"), // current value (snapshot)
|
||||
proposedValue: text("proposed_value").notNull(), // proposed new value
|
||||
reason: text("reason"), // optional explanation
|
||||
status: suggestionStatusEnum("status").default("pending").notNull(),
|
||||
reviewedBy: text("reviewed_by").references(() => user.id),
|
||||
reviewedAt: timestamp("reviewed_at"),
|
||||
reviewNote: text("review_note"), // reviewer's note
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at")
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex("community_suggestions_game_field_user").on(
|
||||
table.gameId,
|
||||
table.fieldName,
|
||||
table.userId,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -8,3 +8,4 @@ export * from "./gamePlatformSupport"
|
||||
export * from "./gameComments"
|
||||
export * from "./savedGames"
|
||||
export * from "./reports"
|
||||
export * from "./community-suggestions"
|
||||
|
||||
Reference in New Issue
Block a user