diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9d9249c..c4c4ee5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -130,7 +130,7 @@ model Country { } model Flight { - id String @id @default(uuid()) + id String @id flightYear Int @db.SmallInt flightMonth Int @db.SmallInt flightDate Int @db.SmallInt diff --git a/src/lib/create.id.ts b/src/lib/create.id.ts index e9652a6..a13b6e4 100644 --- a/src/lib/create.id.ts +++ b/src/lib/create.id.ts @@ -1,6 +1,5 @@ import ShortUniqueId from 'short-unique-id'; -const uid = new ShortUniqueId({ length: 10 }); -export function createID() { - return uid.rnd(); +export function createID(length: number = 10) { + return new ShortUniqueId({ length: length }).rnd(); } diff --git a/src/services/flight/populate.flights.ts b/src/services/flight/populate.flights.ts index 5d099d6..2c19e93 100644 --- a/src/services/flight/populate.flights.ts +++ b/src/services/flight/populate.flights.ts @@ -75,7 +75,8 @@ export async function populateFlights(params: FlightQueryParam) { const result = await prisma.$transaction( data.map(entry => { Logger.debug( - 'Creating flight=%s%s on date=%s-%s-%s', + 'Creating id=%s flight=%s%s on date=%s-%s-%s', + entry.id, entry.airlineIata, entry.flightNumber, entry.flightYear, @@ -85,10 +86,8 @@ export async function populateFlights(params: FlightQueryParam) { return prisma.flight.upsert({ create: entry, - select: { - id: true, - }, - update: {}, + select: { id: true }, + update: { updatedAt: moment().toDate() }, where: { airlineIata_flightNumber_originIata_destinationIata_flightYear_flightMonth_flightDate: {