'Define schema with default date 12 months in the future

How would I define an endDate to be 12 months in the future in my schema.prisma. For example:

model Subscription {
  id    Int     @id @default(autoincrement())
  startDate DateTime @default(now())
  endDate DateTime @default( How to define 1 year in the future?)
  ...
}


Solution 1:[1]

You would need to create a custom function that returns the time after one year and call it via the dbgenerated function.

Example: The function created in the database is called get_end_time. You can define it in schema as

model Subscription {
  id        Int      @id @default(autoincrement())
  startDate DateTime @default(now())
  endDate   DateTime @default(dbgenerated("get_end_time()"))
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nurul Sundarani