Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Change text fields in CREATED_AT and UPDATED_AT to TIMESTAMPZ type. #60

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

34 changes: 17 additions & 17 deletions prisma/schema.prisma
updev-sistemas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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 @@ -43,8 +43,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 @@ -54,8 +54,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 @@ -67,8 +67,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 @@ -81,8 +81,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 @@ -108,11 +108,11 @@ model Shelter {
prioritySum Int @default(value: 0) @map("priority_sum")
latitude Float?
longitude Float?
verified Boolean @default(value: false)
verified Boolean @default(value: false)
category ShelterCategory @default(value: Shelter)
actived 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()

shelterManagers ShelterManagers[]
shelterSupplies ShelterSupply[]
Expand All @@ -122,10 +122,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 @@ -30,7 +30,7 @@ export class SessionsService {
},
data: {
active: false,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});

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

Expand Down Expand Up @@ -76,7 +76,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
10 changes: 7 additions & 3 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 @@ -89,6 +89,10 @@ export class ShelterSupplyService {
in: ids,
},
},
data: {
priority: SupplyPriority.UnderControl,
updatedAt: new Date(),
},
});

const prioritySum = supplies.reduce(
Expand Down
4 changes: 2 additions & 2 deletions src/shelter/shelter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ShelterService implements OnModuleInit {
},
data: {
...payload,
updatedAt: new Date().toISOString(),
updatedAt: new Date(),
},
});
}
Expand All @@ -59,7 +59,7 @@ export class ShelterService implements OnModuleInit {
},
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 @@ -25,8 +25,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