loop-payments/prisma-lint

Feature Request: Enforce `@default([])` for Arrays

Closed this issue · 2 comments

Reason

Let's assume we have this scheme

model Post {
  tags String[]
}

and add a few posts

await prisma.posts.createMany({
  data: [
    { tags: ['nature'] },    
    { tags: undefined },
  ].
})

this is how they looks in Postgres database

tags
{nature}
NULL

now, attempting to filter posts without any tags

const posts = await prisma.posts.findMany({
  where: {
    tags: { isEmpty: true }  
  },
});

this will not return any posts, so it can be very confusing sometimes

Rule Example

// good
model Post {
  tags String[] @default([])
}

// bad
model Post {
  tags String[]
}
maxh commented

Make sense. Thanks for suggesting. It will probably be most similar in implementation to this one:
https://github.com/loop-payments/prisma-lint/blob/main/src/rules/field-name-mapping-snake-case.ts

You're welcome to take a stab implementing, or I can take a look in the new year. More info if you'd like to try:
https://github.com/loop-payments/prisma-lint/blob/main/DEVELOPMENT.md

maxh commented

@PavlMais please take a look: #280