Skip to content

Commit

Permalink
Change create_at and updated_at to TIMESTAMP WITH TIME ZONE.
Browse files Browse the repository at this point in the history
  • Loading branch information
antjoseb27 committed May 11, 2024
1 parent e4e9de2 commit 6a4f4b9
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 45 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
Expand Down
28 changes: 28 additions & 0 deletions prisma/migrations/20240511135945_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- ALTER TABLE
ALTER TABLE "users" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
ALTER TABLE "users" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;

-- ALTER TABLE
ALTER TABLE "category_supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
ALTER TABLE "category_supplies" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;

-- ALTER TABLE
ALTER TABLE "sessions" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
ALTER TABLE "sessions" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;

-- ALTER TABLE
ALTER TABLE "shelter_managers" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
ALTER TABLE "shelter_managers" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;

-- ALTER TABLE
ALTER TABLE "shelter_supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
ALTER TABLE "shelter_supplies" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;

-- ALTER TABLE
ALTER TABLE "shelters" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
ALTER TABLE "shelters" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;

-- ALTER TABLE
ALTER TABLE "supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
ALTER TABLE "supplies" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;

32 changes: 16 additions & 16 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ model User {
password String
phone String @unique
accessLevel AccessLevel @default(value: User)
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
sessions Session[]
shelterManagers ShelterManagers[]
Expand All @@ -37,8 +37,8 @@ model Session {
ip String?
userAgent String? @map("user_agent")
active Boolean @default(value: true)
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
user User @relation(fields: [userId], references: [id])
Expand All @@ -48,8 +48,8 @@ model Session {
model SupplyCategory {
id String @id @default(uuid())
name String @unique
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
supplies Supply[]
Expand All @@ -61,8 +61,8 @@ model ShelterSupply {
supplyId String @map("supply_id")
priority Int @default(value: 0)
quantity Int?
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
shelter Shelter @relation(fields: [shelterId], references: [id])
supply Supply @relation(fields: [supplyId], references: [id])
Expand All @@ -75,8 +75,8 @@ model Supply {
id String @id @default(uuid())
supplyCategoryId String @map("supply_category_id")
name String
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
supplyCategory SupplyCategory @relation(fields: [supplyCategoryId], references: [id])
shelterSupplies ShelterSupply[]
Expand All @@ -97,8 +97,8 @@ model Shelter {
latitude Float?
longitude Float?
verified Boolean @default(value: false)
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
shelterManagers ShelterManagers[]
shelterSupplies ShelterSupply[]
Expand All @@ -107,10 +107,10 @@ model Shelter {
}

model ShelterManagers {
shelterId String @map("shelter_id")
userId String @map("user_id")
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
shelterId String @map("shelter_id")
userId String @map("user_id")
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
user User @relation(fields: [userId], references: [id])
shelter Shelter @relation(fields: [shelterId], references: [id])
Expand Down
6 changes: 3 additions & 3 deletions src/sessions/sessions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SessionsService {
},
data: {
active: false,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});

Expand All @@ -36,7 +36,7 @@ export class SessionsService {
userId: user.id,
ip,
userAgent,
createdAt: new Date().toISOString(),
createdAt: new Date(),
},
});

Expand Down Expand Up @@ -73,7 +73,7 @@ export class SessionsService {
userId,
},
data: {
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
active: false,
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/shelter-managers/shelter-managers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ShelterManagersService {
data: {
shelterId,
userId,
createdAt: new Date().toISOString(),
createdAt: new Date(),
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/shelter-managers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import z from 'zod';
const ShelterManagerSchema = z.object({
shelterId: z.string(),
userId: z.string(),
createdAt: z.string(),
updatedAt: z.string().optional().nullable(),
createdAt: z.date(),
updatedAt: z.date().optional().nullable(),
});

const CreateShelterManagerSchema = ShelterManagerSchema.pick({
Expand Down
8 changes: 4 additions & 4 deletions src/shelter-supply/shelter-supply.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ShelterSupplyService {
prioritySum: {
increment: newPriority - oldPriority,
},
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand All @@ -41,7 +41,7 @@ export class ShelterSupplyService {
priority,
supplyId,
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
createdAt: new Date().toISOString(),
createdAt: new Date(),
},
});
}
Expand Down Expand Up @@ -74,7 +74,7 @@ export class ShelterSupplyService {
data: {
...data,
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand All @@ -91,7 +91,7 @@ export class ShelterSupplyService {
},
data: {
priority: SupplyPriority.UnderControl,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/shelter-supply/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const ShelterSupplySchema = z.object({
z.literal(SupplyPriority.Urgent),
]),
quantity: z.number().gt(0).nullable().optional(),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date().nullable().optional(),
});

const CreateShelterSupplySchema = ShelterSupplySchema.pick({
Expand Down
6 changes: 3 additions & 3 deletions src/shelter/shelter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ShelterService {
await this.prismaService.shelter.create({
data: {
...payload,
createdAt: new Date().toISOString(),
createdAt: new Date(),
},
});
}
Expand All @@ -42,7 +42,7 @@ export class ShelterService {
},
data: {
...payload,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand All @@ -55,7 +55,7 @@ export class ShelterService {
},
data: {
...payload,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/shelter/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const ShelterSchema = z.object({
capacity: z.number().min(0).nullable().optional(),
contact: z.string().nullable().optional(),
verified: z.boolean(),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date().nullable().optional(),
});

const CreateShelterSchema = ShelterSchema.omit({
Expand Down
4 changes: 2 additions & 2 deletions src/supply-categories/supply-categories.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SupplyCategoriesService {
await this.prismaService.supplyCategory.create({
data: {
...payload,
createdAt: new Date().toISOString(),
createdAt: new Date(),
},
});
}
Expand All @@ -29,7 +29,7 @@ export class SupplyCategoriesService {
},
data: {
...payload,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/supply-categories/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export enum SupplyStatus {
const SupplyCategorySchema = z.object({
id: z.string(),
name: z.string().transform(capitalize),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date().nullable().optional(),
});

const CreateSupplyCategorySchema = SupplyCategorySchema.pick({
Expand Down
4 changes: 2 additions & 2 deletions src/supply/supply.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SupplyService {
return await this.prismaService.supply.create({
data: {
...payload,
createdAt: new Date().toISOString(),
createdAt: new Date(),
},
});
}
Expand All @@ -26,7 +26,7 @@ export class SupplyService {
},
data: {
...payload,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/supply/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const SupplySchema = z.object({
id: z.string(),
supplyCategoryId: z.string(),
name: z.string().transform(capitalize),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date().nullable().optional(),
});

const CreateSupplySchema = SupplySchema.omit({
Expand Down
4 changes: 2 additions & 2 deletions src/users/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const UserSchema = z.object({
password: z.string(),
phone: z.string().transform(removeNotNumbers),
accessLevel: z.nativeEnum(AccessLevel),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date().nullable().optional(),
});

const CreateUserSchema = UserSchema.pick({
Expand Down
4 changes: 2 additions & 2 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class UsersService {
phone,
password: phone,
login: phone,
createdAt: new Date().toISOString(),
createdAt: new Date(),
},
});
}
Expand All @@ -29,7 +29,7 @@ export class UsersService {
},
data: {
...payload,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand Down

0 comments on commit 6a4f4b9

Please sign in to comment.