0000_certain_bedlam.sql 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. CREATE TABLE "accounts" (
  2. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  3. "user_id" uuid NOT NULL,
  4. "type" text NOT NULL,
  5. "provider" text NOT NULL,
  6. "provider_account_id" text NOT NULL,
  7. "refresh_token" text,
  8. "access_token" text,
  9. "expires_at" integer,
  10. "token_type" text,
  11. "scope" text,
  12. "id_token" text,
  13. "session_state" text
  14. );
  15. --> statement-breakpoint
  16. CREATE TABLE "sessions" (
  17. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  18. "session_token" text NOT NULL,
  19. "user_id" uuid NOT NULL,
  20. "expires" timestamp NOT NULL,
  21. CONSTRAINT "sessions_session_token_unique" UNIQUE("session_token")
  22. );
  23. --> statement-breakpoint
  24. CREATE TABLE "user_activities" (
  25. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  26. "user_id" uuid NOT NULL,
  27. "type" text NOT NULL,
  28. "description" text NOT NULL,
  29. "credit_amount" integer,
  30. "metadata" text,
  31. "created_at" timestamp DEFAULT now()
  32. );
  33. --> statement-breakpoint
  34. CREATE TABLE "users" (
  35. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  36. "email" text NOT NULL,
  37. "password" text,
  38. "username" text,
  39. "email_verified" timestamp,
  40. "image" text,
  41. "is_email_verified" boolean DEFAULT false NOT NULL,
  42. "credits" integer DEFAULT 10 NOT NULL,
  43. "created_at" timestamp DEFAULT now(),
  44. "updated_at" timestamp DEFAULT now(),
  45. CONSTRAINT "users_email_unique" UNIQUE("email")
  46. );
  47. --> statement-breakpoint
  48. CREATE TABLE "verification_tokens" (
  49. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  50. "email" text NOT NULL,
  51. "token" text NOT NULL,
  52. "expires" timestamp NOT NULL,
  53. "type" text NOT NULL,
  54. "created_at" timestamp DEFAULT now(),
  55. CONSTRAINT "verification_tokens_token_unique" UNIQUE("token")
  56. );
  57. --> statement-breakpoint
  58. ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
  59. ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
  60. ALTER TABLE "user_activities" ADD CONSTRAINT "user_activities_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;