feedback feature
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { pgTable } from 'drizzle-orm/pg-core'
|
||||
import { createInsertSchema, createSelectSchema } from 'drizzle-zod'
|
||||
import { id, createdAt } from '../../helpers'
|
||||
|
||||
export const feedback = pgTable('feedback', (t) => ({
|
||||
id: id('feedback'),
|
||||
userId: t.text('user_id'), // nullable — stores Better Auth user ID or null for anonymous
|
||||
message: t.text('message').notNull(),
|
||||
createdAt,
|
||||
})).enableRLS()
|
||||
|
||||
export type Feedback = typeof feedback.$inferSelect
|
||||
export type NewFeedback = typeof feedback.$inferInsert
|
||||
export const insertFeedbackSchema = createInsertSchema(feedback)
|
||||
export const selectFeedbackSchema = createSelectSchema(feedback)
|
||||
@@ -5,6 +5,9 @@ export * from './auth/sessions'
|
||||
export * from './auth/users'
|
||||
export * from './auth/verifications'
|
||||
|
||||
// Feedback table
|
||||
export * from './feedback/feedback'
|
||||
|
||||
// Project tables
|
||||
export * from './projects/addresses'
|
||||
export * from './projects/likes'
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
-- Create feedback table
|
||||
CREATE TABLE IF NOT EXISTS feedback (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
user_id TEXT,
|
||||
message TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Enable Row Level Security
|
||||
ALTER TABLE feedback ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Allow anyone (authenticated or anonymous) to submit feedback
|
||||
CREATE POLICY "Anyone can insert feedback"
|
||||
ON feedback
|
||||
FOR INSERT
|
||||
TO anon, authenticated
|
||||
WITH CHECK (true);
|
||||
|
||||
-- Allow service role full access (for admin review)
|
||||
CREATE POLICY "Service role full access"
|
||||
ON feedback
|
||||
TO service_role
|
||||
USING (true)
|
||||
WITH CHECK (true);
|
||||
Reference in New Issue
Block a user