0000_empty_emma_frost.sql 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. CREATE TABLE "accounts" (
  2. "id" varchar(30) PRIMARY KEY NOT NULL,
  3. "user_id" varchar(30) NOT NULL,
  4. "account_id" text NOT NULL,
  5. "provider_id" text NOT NULL,
  6. "access_token" text,
  7. "refresh_token" text,
  8. "id_token" text,
  9. "access_token_expires_at" timestamp with time zone,
  10. "refresh_token_expires_at" timestamp with time zone,
  11. "scope" text,
  12. "password" text,
  13. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  14. "updated_at" timestamp with time zone DEFAULT now() NOT NULL
  15. );
  16. --> statement-breakpoint
  17. CREATE TABLE "api_keys" (
  18. "id" varchar(30) PRIMARY KEY NOT NULL,
  19. "project_id" varchar(30) NOT NULL,
  20. "created_by" varchar(30) NOT NULL,
  21. "name" text NOT NULL,
  22. "hash" text NOT NULL,
  23. "suffix" varchar(4) NOT NULL,
  24. "last_used_at" timestamp with time zone,
  25. "expires_at" timestamp with time zone,
  26. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  27. "revoked_at" timestamp with time zone
  28. );
  29. --> statement-breakpoint
  30. CREATE TABLE "audit_logs" (
  31. "id" varchar(30) PRIMARY KEY NOT NULL,
  32. "actor_id" varchar(30),
  33. "project_id" varchar(30),
  34. "action" text NOT NULL,
  35. "ip_hash" varchar(64),
  36. "user_agent" text,
  37. "metadata" jsonb,
  38. "created_at" timestamp with time zone DEFAULT now() NOT NULL
  39. );
  40. --> statement-breakpoint
  41. CREATE TABLE "deployments" (
  42. "id" varchar(30) PRIMARY KEY NOT NULL,
  43. "project_id" varchar(30) NOT NULL,
  44. "triggered_by" varchar(30),
  45. "api_key_id" varchar(30),
  46. "status" text DEFAULT 'pending' NOT NULL,
  47. "schema_diff_summary" jsonb,
  48. "schema_snapshot" jsonb,
  49. "function_count" varchar(12),
  50. "function_names" jsonb,
  51. "error_code" text,
  52. "error_message" text,
  53. "started_at" timestamp with time zone,
  54. "finished_at" timestamp with time zone,
  55. "created_at" timestamp with time zone DEFAULT now() NOT NULL
  56. );
  57. --> statement-breakpoint
  58. CREATE TABLE "project_members" (
  59. "project_id" varchar(30) NOT NULL,
  60. "user_id" varchar(30) NOT NULL,
  61. "role" text DEFAULT 'developer' NOT NULL,
  62. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  63. "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  64. CONSTRAINT "project_members_project_id_user_id_pk" PRIMARY KEY("project_id","user_id")
  65. );
  66. --> statement-breakpoint
  67. CREATE TABLE "projects" (
  68. "id" varchar(30) PRIMARY KEY NOT NULL,
  69. "slug" text NOT NULL,
  70. "name" text NOT NULL,
  71. "owner_id" varchar(30) NOT NULL,
  72. "region" text DEFAULT 'eu-west-1' NOT NULL,
  73. "tier" text DEFAULT 'free' NOT NULL,
  74. "shard_id" text,
  75. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  76. "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  77. "deleted_at" timestamp with time zone
  78. );
  79. --> statement-breakpoint
  80. CREATE TABLE "sessions" (
  81. "id" varchar(30) PRIMARY KEY NOT NULL,
  82. "user_id" varchar(30) NOT NULL,
  83. "token" text NOT NULL,
  84. "expires_at" timestamp with time zone NOT NULL,
  85. "ip_address" text,
  86. "user_agent" text,
  87. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  88. "updated_at" timestamp with time zone DEFAULT now() NOT NULL
  89. );
  90. --> statement-breakpoint
  91. CREATE TABLE "users" (
  92. "id" varchar(30) PRIMARY KEY NOT NULL,
  93. "email" text NOT NULL,
  94. "email_verified" boolean DEFAULT false NOT NULL,
  95. "name" text,
  96. "image" text,
  97. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  98. "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  99. "deleted_at" timestamp with time zone
  100. );
  101. --> statement-breakpoint
  102. CREATE TABLE "verifications" (
  103. "id" varchar(30) PRIMARY KEY NOT NULL,
  104. "identifier" text NOT NULL,
  105. "value" text NOT NULL,
  106. "expires_at" timestamp with time zone NOT NULL,
  107. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  108. "updated_at" timestamp with time zone DEFAULT now() NOT NULL
  109. );
  110. --> statement-breakpoint
  111. 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
  112. ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
  113. ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
  114. ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_actor_id_users_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
  115. ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
  116. ALTER TABLE "deployments" ADD CONSTRAINT "deployments_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
  117. ALTER TABLE "deployments" ADD CONSTRAINT "deployments_triggered_by_users_id_fk" FOREIGN KEY ("triggered_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
  118. ALTER TABLE "deployments" ADD CONSTRAINT "deployments_api_key_id_api_keys_id_fk" FOREIGN KEY ("api_key_id") REFERENCES "public"."api_keys"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
  119. ALTER TABLE "project_members" ADD CONSTRAINT "project_members_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
  120. ALTER TABLE "project_members" ADD CONSTRAINT "project_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
  121. ALTER TABLE "projects" ADD CONSTRAINT "projects_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
  122. 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
  123. CREATE INDEX "accounts_user_id_idx" ON "accounts" USING btree ("user_id");--> statement-breakpoint
  124. CREATE UNIQUE INDEX "accounts_provider_account_idx" ON "accounts" USING btree ("provider_id","account_id");--> statement-breakpoint
  125. CREATE UNIQUE INDEX "api_keys_hash_idx" ON "api_keys" USING btree ("hash");--> statement-breakpoint
  126. CREATE INDEX "api_keys_project_idx" ON "api_keys" USING btree ("project_id");--> statement-breakpoint
  127. CREATE INDEX "audit_logs_project_created_idx" ON "audit_logs" USING btree ("project_id","created_at");--> statement-breakpoint
  128. CREATE INDEX "audit_logs_actor_created_idx" ON "audit_logs" USING btree ("actor_id","created_at");--> statement-breakpoint
  129. CREATE INDEX "deployments_project_created_idx" ON "deployments" USING btree ("project_id","created_at");--> statement-breakpoint
  130. CREATE INDEX "deployments_status_idx" ON "deployments" USING btree ("status");--> statement-breakpoint
  131. CREATE UNIQUE INDEX "projects_slug_idx" ON "projects" USING btree ("slug");--> statement-breakpoint
  132. CREATE INDEX "projects_owner_idx" ON "projects" USING btree ("owner_id");--> statement-breakpoint
  133. CREATE UNIQUE INDEX "sessions_token_idx" ON "sessions" USING btree ("token");--> statement-breakpoint
  134. CREATE INDEX "sessions_user_id_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint
  135. CREATE UNIQUE INDEX "users_email_idx" ON "users" USING btree ("email");--> statement-breakpoint
  136. CREATE INDEX "verifications_identifier_idx" ON "verifications" USING btree ("identifier");