Skip to content

Commit ae8a806

Browse files
committed
Change create_at and updated_at to TIMESTAMP WITH TIME ZONE.
1 parent e4e9de2 commit ae8a806

File tree

17 files changed

+213
-45
lines changed

17 files changed

+213
-45
lines changed

package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@nestjs/cli": "^10.0.0",
4444
"@nestjs/schematics": "^10.0.0",
4545
"@nestjs/testing": "^10.0.0",
46+
"@types/bcrypt": "^5.0.2",
4647
"@types/express": "^4.17.17",
4748
"@types/jest": "^29.5.2",
4849
"@types/node": "^20.3.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
Warnings:
3+
4+
- The `created_at` column on the `category_supplies` table would be dropped and recreated. This will lead to data loss if there is data in the column.
5+
- The `updated_at` column on the `category_supplies` table would be dropped and recreated. This will lead to data loss if there is data in the column.
6+
- The `created_at` column on the `sessions` table would be dropped and recreated. This will lead to data loss if there is data in the column.
7+
- The `updated_at` column on the `sessions` table would be dropped and recreated. This will lead to data loss if there is data in the column.
8+
- The `created_at` column on the `shelter_managers` table would be dropped and recreated. This will lead to data loss if there is data in the column.
9+
- The `updated_at` column on the `shelter_managers` table would be dropped and recreated. This will lead to data loss if there is data in the column.
10+
- The `created_at` column on the `shelter_supplies` table would be dropped and recreated. This will lead to data loss if there is data in the column.
11+
- The `updated_at` column on the `shelter_supplies` table would be dropped and recreated. This will lead to data loss if there is data in the column.
12+
- The `created_at` column on the `shelters` table would be dropped and recreated. This will lead to data loss if there is data in the column.
13+
- The `updated_at` column on the `shelters` table would be dropped and recreated. This will lead to data loss if there is data in the column.
14+
- The `created_at` column on the `supplies` table would be dropped and recreated. This will lead to data loss if there is data in the column.
15+
- The `updated_at` column on the `supplies` table would be dropped and recreated. This will lead to data loss if there is data in the column.
16+
- The `created_at` column on the `users` table would be dropped and recreated. This will lead to data loss if there is data in the column.
17+
- The `updated_at` column on the `users` table would be dropped and recreated. This will lead to data loss if there is data in the column.
18+
19+
*/
20+
-- AlterTable
21+
ALTER TABLE "category_supplies" ADD COLUMN "created_at_tmp" TIMESTAMP(3) default null;
22+
UPDATE "category_supplies"
23+
SET "created_at_tmp" = CASE
24+
WHEN "created_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("created_at", 'YYYY-MM-DD HH24:MI:SS')
25+
ELSE NOW()
26+
END;
27+
ALTER TABLE "category_supplies" DROP COLUMN "created_at";
28+
ALTER TABLE "category_supplies" RENAME COLUMN "created_at_tmp" TO "created_at";
29+
30+
-- AlterTable
31+
ALTER TABLE "category_supplies" ADD COLUMN "updated_at_tmp" TIMESTAMP(3) default null;
32+
UPDATE "category_supplies"
33+
SET "updated_at_tmp" = CASE
34+
WHEN "updated_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("updated_at", 'YYYY-MM-DD HH24:MI:SS')
35+
ELSE null
36+
END;
37+
ALTER TABLE "category_supplies" DROP COLUMN "updated_at";
38+
ALTER TABLE "category_supplies" RENAME COLUMN "updated_at_tmp" TO "updated_at";
39+
40+
-- AlterTable
41+
ALTER TABLE "sessions" ADD COLUMN "created_at_tmp" TIMESTAMP(3) default null;
42+
UPDATE "sessions"
43+
SET "created_at_tmp" = CASE
44+
WHEN "created_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("created_at", 'YYYY-MM-DD HH24:MI:SS')
45+
ELSE NOW()
46+
END;
47+
ALTER TABLE "sessions" DROP COLUMN "created_at";
48+
ALTER TABLE "sessions" RENAME COLUMN "created_at_tmp" TO "created_at";
49+
50+
-- AlterTable
51+
ALTER TABLE "sessions" ADD COLUMN "updated_at_tmp" TIMESTAMP(3) default null;
52+
UPDATE "sessions"
53+
SET "updated_at_tmp" = CASE
54+
WHEN "updated_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("updated_at", 'YYYY-MM-DD HH24:MI:SS')
55+
ELSE null
56+
END;
57+
ALTER TABLE "sessions" DROP COLUMN "updated_at";
58+
ALTER TABLE "sessions" RENAME COLUMN "updated_at_tmp" TO "updated_at";
59+
60+
-- AlterTable
61+
ALTER TABLE "shelter_managers" ADD COLUMN "created_at_tmp" TIMESTAMP(3) default null;
62+
UPDATE "shelter_managers"
63+
SET "created_at_tmp" = CASE
64+
WHEN "created_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("created_at", 'YYYY-MM-DD HH24:MI:SS')
65+
ELSE NOW()
66+
END;
67+
ALTER TABLE "shelter_managers" DROP COLUMN "created_at";
68+
ALTER TABLE "shelter_managers" RENAME COLUMN "created_at_tmp" TO "created_at";
69+
70+
-- AlterTable
71+
ALTER TABLE "shelter_managers" ADD COLUMN "updated_at_tmp" TIMESTAMP(3) default null;
72+
UPDATE "shelter_managers"
73+
SET "updated_at_tmp" = CASE
74+
WHEN "updated_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("updated_at", 'YYYY-MM-DD HH24:MI:SS')
75+
ELSE null
76+
END;
77+
ALTER TABLE "shelter_managers" DROP COLUMN "updated_at";
78+
ALTER TABLE "shelter_managers" RENAME COLUMN "updated_at_tmp" TO "updated_at";
79+
80+
-- AlterTable
81+
ALTER TABLE "shelter_supplies" ADD COLUMN "created_at_tmp" TIMESTAMP(3) default null;
82+
UPDATE "shelter_supplies"
83+
SET "created_at_tmp" = CASE
84+
WHEN "created_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("created_at", 'YYYY-MM-DD HH24:MI:SS')
85+
ELSE NOW()
86+
END;
87+
ALTER TABLE "shelter_supplies" DROP COLUMN "created_at";
88+
ALTER TABLE "shelter_supplies" RENAME COLUMN "created_at_tmp" TO "created_at";
89+
90+
91+
ALTER TABLE "shelter_supplies" ADD COLUMN "updated_at_tmp" TIMESTAMP(3) default null;
92+
UPDATE "shelter_supplies"
93+
SET "updated_at_tmp" = CASE
94+
WHEN "updated_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("updated_at", 'YYYY-MM-DD HH24:MI:SS')
95+
ELSE null
96+
END;
97+
ALTER TABLE "shelter_supplies" DROP COLUMN "updated_at";
98+
ALTER TABLE "shelter_supplies" RENAME COLUMN "updated_at_tmp" TO "updated_at";
99+
100+
-- AlterTable
101+
ALTER TABLE "shelters" ADD COLUMN "created_at_tmp" TIMESTAMP(3) default null;
102+
UPDATE "shelters"
103+
SET "created_at_tmp" = CASE
104+
WHEN "created_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("created_at", 'YYYY-MM-DD HH24:MI:SS')
105+
ELSE NOW()
106+
END;
107+
ALTER TABLE "shelters" DROP COLUMN "created_at";
108+
ALTER TABLE "shelters" RENAME COLUMN "created_at_tmp" TO "created_at";
109+
110+
-- AlterTable
111+
ALTER TABLE "shelters" ADD COLUMN "updated_at_tmp" TIMESTAMP(3) default null;
112+
UPDATE "shelters"
113+
SET "updated_at_tmp" = CASE
114+
WHEN "updated_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("updated_at", 'YYYY-MM-DD HH24:MI:SS')
115+
ELSE null
116+
END;
117+
ALTER TABLE "shelters" DROP COLUMN "updated_at";
118+
ALTER TABLE "shelters" RENAME COLUMN "updated_at_tmp" TO "updated_at";
119+
120+
-- AlterTable
121+
ALTER TABLE "supplies" ADD COLUMN "created_at_tmp" TIMESTAMP(3) default null;
122+
UPDATE "supplies"
123+
SET "created_at_tmp" = CASE
124+
WHEN "created_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("created_at", 'YYYY-MM-DD HH24:MI:SS')
125+
ELSE NOW()
126+
END;
127+
ALTER TABLE "supplies" DROP COLUMN "created_at";
128+
ALTER TABLE "supplies" RENAME COLUMN "created_at_tmp" TO "created_at";
129+
130+
-- AlterTable
131+
ALTER TABLE "supplies" ADD COLUMN "updated_at_tmp" TIMESTAMP(3) default null;
132+
UPDATE "supplies"
133+
SET "updated_at_tmp" = CASE
134+
WHEN "updated_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("updated_at", 'YYYY-MM-DD HH24:MI:SS')
135+
ELSE null
136+
END;
137+
ALTER TABLE "supplies" DROP COLUMN "updated_at";
138+
ALTER TABLE "supplies" RENAME COLUMN "updated_at_tmp" TO "updated_at";
139+
140+
-- AlterTable
141+
ALTER TABLE "users" ADD COLUMN "created_at_tmp" TIMESTAMP(3) default null;
142+
UPDATE "users"
143+
SET "created_at_tmp" = CASE
144+
WHEN "created_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("created_at", 'YYYY-MM-DD HH24:MI:SS')
145+
ELSE NOW()
146+
END;
147+
ALTER TABLE "users" DROP COLUMN "created_at";
148+
ALTER TABLE "users" RENAME COLUMN "created_at_tmp" TO "created_at";
149+
150+
ALTER TABLE "users" ADD COLUMN "updated_at_tmp" TIMESTAMP(3) default null;
151+
UPDATE "users"
152+
SET "updated_at_tmp" = CASE
153+
WHEN "updated_at" ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' THEN TO_TIMESTAMP("updated_at", 'YYYY-MM-DD HH24:MI:SS')
154+
ELSE null
155+
END;
156+
ALTER TABLE "users" DROP COLUMN "updated_at";
157+
ALTER TABLE "users" RENAME COLUMN "updated_at_tmp" TO "updated_at";

prisma/schema.prisma

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ model User {
2222
password String
2323
phone String @unique
2424
accessLevel AccessLevel @default(value: User)
25-
createdAt String @map("created_at") @db.VarChar(32)
26-
updatedAt String? @map("updated_at") @db.VarChar(32)
25+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
26+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
2727
2828
sessions Session[]
2929
shelterManagers ShelterManagers[]
@@ -37,8 +37,8 @@ model Session {
3737
ip String?
3838
userAgent String? @map("user_agent")
3939
active Boolean @default(value: true)
40-
createdAt String @map("created_at") @db.VarChar(32)
41-
updatedAt String? @map("updated_at") @db.VarChar(32)
40+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
41+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
4242
4343
user User @relation(fields: [userId], references: [id])
4444
@@ -48,8 +48,8 @@ model Session {
4848
model SupplyCategory {
4949
id String @id @default(uuid())
5050
name String @unique
51-
createdAt String @map("created_at") @db.VarChar(32)
52-
updatedAt String? @map("updated_at") @db.VarChar(32)
51+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
52+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
5353
5454
supplies Supply[]
5555
@@ -61,8 +61,8 @@ model ShelterSupply {
6161
supplyId String @map("supply_id")
6262
priority Int @default(value: 0)
6363
quantity Int?
64-
createdAt String @map("created_at") @db.VarChar(32)
65-
updatedAt String? @map("updated_at") @db.VarChar(32)
64+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
65+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
6666
6767
shelter Shelter @relation(fields: [shelterId], references: [id])
6868
supply Supply @relation(fields: [supplyId], references: [id])
@@ -75,8 +75,8 @@ model Supply {
7575
id String @id @default(uuid())
7676
supplyCategoryId String @map("supply_category_id")
7777
name String
78-
createdAt String @map("created_at") @db.VarChar(32)
79-
updatedAt String? @map("updated_at") @db.VarChar(32)
78+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
79+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
8080
8181
supplyCategory SupplyCategory @relation(fields: [supplyCategoryId], references: [id])
8282
shelterSupplies ShelterSupply[]
@@ -97,8 +97,8 @@ model Shelter {
9797
latitude Float?
9898
longitude Float?
9999
verified Boolean @default(value: false)
100-
createdAt String @map("created_at") @db.VarChar(32)
101-
updatedAt String? @map("updated_at") @db.VarChar(32)
100+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
101+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
102102
103103
shelterManagers ShelterManagers[]
104104
shelterSupplies ShelterSupply[]
@@ -107,10 +107,10 @@ model Shelter {
107107
}
108108

109109
model ShelterManagers {
110-
shelterId String @map("shelter_id")
111-
userId String @map("user_id")
112-
createdAt String @map("created_at") @db.VarChar(32)
113-
updatedAt String? @map("updated_at") @db.VarChar(32)
110+
shelterId String @map("shelter_id")
111+
userId String @map("user_id")
112+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
113+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
114114
115115
user User @relation(fields: [userId], references: [id])
116116
shelter Shelter @relation(fields: [shelterId], references: [id])

src/sessions/sessions.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class SessionsService {
2727
},
2828
data: {
2929
active: false,
30-
updatedAt: new Date().toISOString(),
30+
updatedAt: new Date(),
3131
},
3232
});
3333

@@ -36,7 +36,7 @@ export class SessionsService {
3636
userId: user.id,
3737
ip,
3838
userAgent,
39-
createdAt: new Date().toISOString(),
39+
createdAt: new Date(),
4040
},
4141
});
4242

@@ -73,7 +73,7 @@ export class SessionsService {
7373
userId,
7474
},
7575
data: {
76-
updatedAt: new Date().toISOString(),
76+
updatedAt: new Date(),
7777
active: false,
7878
},
7979
});

src/shelter-managers/shelter-managers.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ShelterManagersService {
1414
data: {
1515
shelterId,
1616
userId,
17-
createdAt: new Date().toISOString(),
17+
createdAt: new Date(),
1818
},
1919
});
2020
}

src/shelter-managers/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import z from 'zod';
33
const ShelterManagerSchema = z.object({
44
shelterId: z.string(),
55
userId: z.string(),
6-
createdAt: z.string(),
7-
updatedAt: z.string().optional().nullable(),
6+
createdAt: z.date(),
7+
updatedAt: z.date().optional().nullable(),
88
});
99

1010
const CreateShelterManagerSchema = ShelterManagerSchema.pick({

src/shelter-supply/shelter-supply.service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ShelterSupplyService {
2626
prioritySum: {
2727
increment: newPriority - oldPriority,
2828
},
29-
updatedAt: new Date().toISOString(),
29+
updatedAt: new Date(),
3030
},
3131
});
3232
}
@@ -41,7 +41,7 @@ export class ShelterSupplyService {
4141
priority,
4242
supplyId,
4343
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
44-
createdAt: new Date().toISOString(),
44+
createdAt: new Date(),
4545
},
4646
});
4747
}
@@ -74,7 +74,7 @@ export class ShelterSupplyService {
7474
data: {
7575
...data,
7676
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
77-
updatedAt: new Date().toISOString(),
77+
updatedAt: new Date(),
7878
},
7979
});
8080
}
@@ -91,7 +91,7 @@ export class ShelterSupplyService {
9191
},
9292
data: {
9393
priority: SupplyPriority.UnderControl,
94-
updatedAt: new Date().toISOString(),
94+
updatedAt: new Date(),
9595
},
9696
});
9797
}

src/shelter-supply/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const ShelterSupplySchema = z.object({
1313
z.literal(SupplyPriority.Urgent),
1414
]),
1515
quantity: z.number().gt(0).nullable().optional(),
16-
createdAt: z.string(),
17-
updatedAt: z.string().nullable().optional(),
16+
createdAt: z.date(),
17+
updatedAt: z.date().nullable().optional(),
1818
});
1919

2020
const CreateShelterSupplySchema = ShelterSupplySchema.pick({

src/shelter/shelter.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ShelterService {
2929
await this.prismaService.shelter.create({
3030
data: {
3131
...payload,
32-
createdAt: new Date().toISOString(),
32+
createdAt: new Date(),
3333
},
3434
});
3535
}
@@ -42,7 +42,7 @@ export class ShelterService {
4242
},
4343
data: {
4444
...payload,
45-
updatedAt: new Date().toISOString(),
45+
updatedAt: new Date(),
4646
},
4747
});
4848
}
@@ -55,7 +55,7 @@ export class ShelterService {
5555
},
5656
data: {
5757
...payload,
58-
updatedAt: new Date().toISOString(),
58+
updatedAt: new Date(),
5959
},
6060
});
6161
}

0 commit comments

Comments
 (0)