You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
awaitqueryRunner.query(`CREATE TABLE "user_following_users" ("follower_id" character varying NOT NULL, "following_id" character varying NOT NULL, CONSTRAINT "PK_user_following_users" PRIMARY KEY ("follower_id", "following_id"))`);
7
-
awaitqueryRunner.query(`CREATE INDEX "IDX_user_following_users_follower_id" ON "user_following_users" ("follower_id")`);
8
-
awaitqueryRunner.query(`CREATE INDEX "IDX_user_following_users_following_id" ON "user_following_users" ("following_id")`);
9
-
awaitqueryRunner.query(`ALTER TABLE "user_following_users" ADD CONSTRAINT "FK_user_following_users_follower_id" FOREIGN KEY ("follower_id") REFERENCES "User"("firebaseUid") ON DELETE CASCADE ON UPDATE CASCADE`);
10
-
awaitqueryRunner.query(`ALTER TABLE "user_following_users" ADD CONSTRAINT "FK_user_following_users_following_id" FOREIGN KEY ("following_id") REFERENCES "User"("firebaseUid") ON DELETE CASCADE ON UPDATE CASCADE`);
6
+
awaitqueryRunner.query(`CREATE TABLE IF NOT EXISTS "user_following_users" ("follower_id" character varying NOT NULL, "following_id" character varying NOT NULL, CONSTRAINT "PK_user_following_users" PRIMARY KEY ("follower_id", "following_id"))`);
7
+
awaitqueryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_user_following_users_follower_id" ON "user_following_users" ("follower_id")`);
8
+
awaitqueryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_user_following_users_following_id" ON "user_following_users" ("following_id")`);
9
+
10
+
// Add fks only if they don't exist
11
+
constfk1Exists=awaitqueryRunner.query(`SELECT 1 FROM pg_constraint WHERE conname = 'FK_user_following_users_follower_id'`);
12
+
if(!fk1Exists||fk1Exists.length===0){
13
+
awaitqueryRunner.query(`ALTER TABLE "user_following_users" ADD CONSTRAINT "FK_user_following_users_follower_id" FOREIGN KEY ("follower_id") REFERENCES "User"("firebaseUid") ON DELETE CASCADE ON UPDATE CASCADE`);
14
+
}
15
+
16
+
constfk2Exists=awaitqueryRunner.query(`SELECT 1 FROM pg_constraint WHERE conname = 'FK_user_following_users_following_id'`);
17
+
if(!fk2Exists||fk2Exists.length===0){
18
+
awaitqueryRunner.query(`ALTER TABLE "user_following_users" ADD CONSTRAINT "FK_user_following_users_following_id" FOREIGN KEY ("following_id") REFERENCES "User"("firebaseUid") ON DELETE CASCADE ON UPDATE CASCADE`);
19
+
}
11
20
12
21
awaitqueryRunner.query(`ALTER TABLE "User" ADD COLUMN IF NOT EXISTS "soldPosts" integer NOT NULL DEFAULT 0`);
0 commit comments