migration.sql 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. -- CreateTable
  2. CREATE TABLE "accounts" (
  3. "id" TEXT NOT NULL,
  4. "user_id" TEXT NOT NULL,
  5. "type" TEXT NOT NULL,
  6. "provider" TEXT NOT NULL,
  7. "provider_account_id" TEXT NOT NULL,
  8. "refresh_token" TEXT,
  9. "access_token" TEXT,
  10. "expires_at" INTEGER,
  11. "token_type" TEXT,
  12. "scope" TEXT,
  13. "id_token" TEXT,
  14. "session_state" TEXT,
  15. "refresh_token_expires_in" INTEGER,
  16. CONSTRAINT "accounts_pkey" PRIMARY KEY ("id")
  17. );
  18. -- CreateTable
  19. CREATE TABLE "sessions" (
  20. "id" TEXT NOT NULL,
  21. "session_token" TEXT NOT NULL,
  22. "user_id" TEXT NOT NULL,
  23. "expires" TIMESTAMP(3) NOT NULL,
  24. CONSTRAINT "sessions_pkey" PRIMARY KEY ("id")
  25. );
  26. -- CreateTable
  27. CREATE TABLE "users" (
  28. "id" TEXT NOT NULL,
  29. "name" TEXT,
  30. "email" TEXT,
  31. "email_verified" TIMESTAMP(3),
  32. "image" TEXT,
  33. CONSTRAINT "users_pkey" PRIMARY KEY ("id")
  34. );
  35. -- CreateTable
  36. CREATE TABLE "verificationtokens" (
  37. "identifier" TEXT NOT NULL,
  38. "token" TEXT NOT NULL,
  39. "expires" TIMESTAMP(3) NOT NULL
  40. );
  41. -- CreateTable
  42. CREATE TABLE "Subscription" (
  43. "id" SERIAL NOT NULL,
  44. "lemon_squeezy_id" INTEGER NOT NULL,
  45. "order_id" INTEGER NOT NULL,
  46. "name" TEXT NOT NULL,
  47. "email" TEXT NOT NULL,
  48. "status" TEXT NOT NULL,
  49. "renews_at" TIMESTAMP(3),
  50. "ends_at" TIMESTAMP(3),
  51. "trial_ends_at" TIMESTAMP(3),
  52. "resumes_at" TIMESTAMP(3),
  53. "price" INTEGER NOT NULL,
  54. "plan_id" INTEGER NOT NULL,
  55. "user_id" TEXT NOT NULL,
  56. "is_usage_based" BOOLEAN NOT NULL DEFAULT false,
  57. "subscription_item_id" INTEGER,
  58. CONSTRAINT "Subscription_pkey" PRIMARY KEY ("id")
  59. );
  60. -- CreateTable
  61. CREATE TABLE "Plan" (
  62. "id" SERIAL NOT NULL,
  63. "product_id" INTEGER NOT NULL,
  64. "variant_id" INTEGER NOT NULL,
  65. "name" TEXT,
  66. "description" TEXT,
  67. "variant_name" TEXT NOT NULL,
  68. "sort" INTEGER NOT NULL,
  69. "status" TEXT NOT NULL,
  70. "price" INTEGER NOT NULL,
  71. "interval" TEXT NOT NULL,
  72. "interval_count" INTEGER NOT NULL DEFAULT 1,
  73. CONSTRAINT "Plan_pkey" PRIMARY KEY ("id")
  74. );
  75. -- CreateTable
  76. CREATE TABLE "WebhookEvent" (
  77. "id" SERIAL NOT NULL,
  78. "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  79. "event_name" TEXT NOT NULL,
  80. "processed" BOOLEAN NOT NULL DEFAULT false,
  81. "body" JSONB NOT NULL,
  82. "processing_error" TEXT,
  83. CONSTRAINT "WebhookEvent_pkey" PRIMARY KEY ("id")
  84. );
  85. -- CreateIndex
  86. CREATE UNIQUE INDEX "accounts_provider_provider_account_id_key" ON "accounts"("provider", "provider_account_id");
  87. -- CreateIndex
  88. CREATE UNIQUE INDEX "sessions_session_token_key" ON "sessions"("session_token");
  89. -- CreateIndex
  90. CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
  91. -- CreateIndex
  92. CREATE UNIQUE INDEX "verificationtokens_token_key" ON "verificationtokens"("token");
  93. -- CreateIndex
  94. CREATE UNIQUE INDEX "verificationtokens_identifier_token_key" ON "verificationtokens"("identifier", "token");
  95. -- CreateIndex
  96. CREATE UNIQUE INDEX "Subscription_lemon_squeezy_id_key" ON "Subscription"("lemon_squeezy_id");
  97. -- CreateIndex
  98. CREATE UNIQUE INDEX "Subscription_order_id_key" ON "Subscription"("order_id");
  99. -- CreateIndex
  100. CREATE UNIQUE INDEX "Subscription_subscription_item_id_key" ON "Subscription"("subscription_item_id");
  101. -- CreateIndex
  102. CREATE INDEX "Subscription_plan_id_lemon_squeezy_id_idx" ON "Subscription"("plan_id", "lemon_squeezy_id");
  103. -- CreateIndex
  104. CREATE UNIQUE INDEX "Plan_variant_id_key" ON "Plan"("variant_id");
  105. -- AddForeignKey
  106. ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  107. -- AddForeignKey
  108. ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  109. -- AddForeignKey
  110. ALTER TABLE "Subscription" ADD CONSTRAINT "Subscription_plan_id_fkey" FOREIGN KEY ("plan_id") REFERENCES "Plan"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  111. -- AddForeignKey
  112. ALTER TABLE "Subscription" ADD CONSTRAINT "Subscription_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;