-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathmigration.sql
More file actions
134 lines (102 loc) · 4.82 KB
/
Copy pathmigration.sql
File metadata and controls
134 lines (102 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Warnings:
- Added the required column `buyerId` to the `transactions` table without a default value. This is not possible if the table is not empty.
- Added the required column `currency` to the `transactions` table without a default value. This is not possible if the table is not empty.
- Added the required column `sellerId` to the `transactions` table without a default value. This is not possible if the table is not empty.
*/
-- AlterEnum
-- This migration adds more than one value to an enum.
-- With PostgreSQL versions 11 and earlier, this is not possible
-- in a single migration. This can be worked around by creating
-- multiple migrations, each migration adding only one value to
-- the enum.
ALTER TYPE "TransactionStatus" ADD VALUE 'ESCROW_FUNDED';
ALTER TYPE "TransactionStatus" ADD VALUE 'BLOCKCHAIN_SUBMITTED';
ALTER TYPE "TransactionStatus" ADD VALUE 'CONFIRMING';
ALTER TYPE "TransactionStatus" ADD VALUE 'CONFIRMED';
ALTER TYPE "TransactionStatus" ADD VALUE 'DISPUTED';
ALTER TYPE "TransactionStatus" ADD VALUE 'REFUNDED';
-- AlterTable
ALTER TABLE "transactions" ADD COLUMN "blockNumber" INTEGER,
ADD COLUMN "blockchainHash" TEXT,
ADD COLUMN "buyerId" TEXT NOT NULL,
ADD COLUMN "confirmations" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "currency" TEXT NOT NULL,
ADD COLUMN "disputeReason" TEXT,
ADD COLUMN "escrowWallet" TEXT,
ADD COLUMN "gasFee" DECIMAL(65,30),
ADD COLUMN "platformFee" DECIMAL(65,30),
ADD COLUMN "sellerId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "users" ADD COLUMN "avatar_url" TEXT,
ADD COLUMN "bio" TEXT,
ADD COLUMN "export_requested_at" TIMESTAMP(3),
ADD COLUMN "location" TEXT,
ADD COLUMN "preferences" JSONB,
ADD COLUMN "privacy_settings" JSONB;
-- CreateTable
CREATE TABLE "user_activities" (
"id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"action" TEXT NOT NULL,
"metadata" JSONB,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "user_activities_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "user_relationships" (
"id" TEXT NOT NULL,
"follower_id" TEXT NOT NULL,
"following_id" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT 'active',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "user_relationships_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "password_history" (
"id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"password_hash" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "password_history_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "user_activities_user_id_idx" ON "user_activities"("user_id");
-- CreateIndex
CREATE INDEX "user_activities_action_idx" ON "user_activities"("action");
-- CreateIndex
CREATE INDEX "user_activities_created_at_idx" ON "user_activities"("created_at");
-- CreateIndex
CREATE INDEX "user_relationships_follower_id_idx" ON "user_relationships"("follower_id");
-- CreateIndex
CREATE INDEX "user_relationships_following_id_idx" ON "user_relationships"("following_id");
-- CreateIndex
CREATE UNIQUE INDEX "user_relationships_follower_id_following_id_key" ON "user_relationships"("follower_id", "following_id");
-- CreateIndex
CREATE INDEX "password_history_user_id_idx" ON "password_history"("user_id");
-- CreateIndex
CREATE INDEX "password_history_created_at_idx" ON "password_history"("created_at");
-- CreateIndex
CREATE INDEX "properties_price_idx" ON "properties"("price");
-- CreateIndex
CREATE INDEX "property_valuations_property_id_idx" ON "property_valuations"("property_id");
-- CreateIndex
CREATE INDEX "property_valuations_valuation_date_idx" ON "property_valuations"("valuation_date");
-- CreateIndex
CREATE INDEX "transactions_buyerId_idx" ON "transactions"("buyerId");
-- CreateIndex
CREATE INDEX "transactions_sellerId_idx" ON "transactions"("sellerId");
-- CreateIndex
CREATE INDEX "transactions_tx_hash_idx" ON "transactions"("tx_hash");
-- CreateIndex
CREATE INDEX "users_is_verified_idx" ON "users"("is_verified");
-- CreateIndex
CREATE INDEX "users_location_idx" ON "users"("location");
-- AddForeignKey
ALTER TABLE "user_activities" ADD CONSTRAINT "user_activities_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_relationships" ADD CONSTRAINT "user_relationships_follower_id_fkey" FOREIGN KEY ("follower_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_relationships" ADD CONSTRAINT "user_relationships_following_id_fkey" FOREIGN KEY ("following_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "password_history" ADD CONSTRAINT "password_history_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;