How can I create a custom constraint to have default to getpgusername()

I have a non nullable field called createdBy I would like it to auto populate to getpgusername(). How can i create a Migration field constraint to do that?

You'll need to add some raw SQL to do that. Here's an example of adding a new timestamp column to a model that defaults to the current time:

database.schema(FluentUserAccessToken.v20200523.schemaName)
  .field(FluentUserAccessToken.v20200922.createdAt, .datetime, .required, 
  .sql(SQLColumnConstraintAlgorithm.default(SQLRaw("CURRENT_TIMESTAMP"))))
  .update()
Terms of Service

Privacy Policy

Cookie Policy