# Missing NOT NULL and uniqueness constraints in DB

**URL:** https://meta.discourse.org/t/missing-not-null-and-uniqueness-constraints-in-db/125945
**Category:** Development
**Created:** [August 16, 2019, 3:53am UTC](https://meta.discourse.org/t/missing-not-null-and-uniqueness-constraints-in-db/125945 "2019-08-16T03:53:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Utsav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/utsav/32/142741_2.png) [@Utsav](https://meta.discourse.org/u/Utsav)
#### Post date: [August 16, 2019, 3:53am UTC](https://meta.discourse.org/t/missing-not-null-and-uniqueness-constraints-in-db/125945/1 "2019-08-16T03:53:39Z")

</div>

Hi,

Wanted to make a report about a few validations/constraints that exist in models but are missing in DB.

#### Missing not null requirements

_PostDetail - key, value_ are required to be present in model but are nullable in DB.

1. Required in model (`app/models/post_detail.rb`):

#### Missing unique constraints

1. _TagGroup - name_. Unique in model (`app/models/tag_group.rb`)

2. Likewise, _WatchedWord - word_. (`app/models/watched_word.rb`)

3. Finally, _WebHookEventType - name_. (`app/models/web_hook_event_type.rb`):

Perhaps someone might be able to confirm if these seem reasonable. It’s possible they will help prevent a bug before it happens. Also, if so, the fix seems like it would be pretty straightforward, and I’m happy to create a pull request if that will be helpful.

Thanks.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 16, 2019, 5:05am UTC](https://meta.discourse.org/t/missing-not-null-and-uniqueness-constraints-in-db/125945/2 "2019-08-16T05:05:38Z")

</div>

> [@Utsav](#):
>
> validates\_uniqueness\_of :name, case\_sensitive: false

Case insensitive unique constraints are a bit tricky, I am uneasy adding the `citext` extension for this and we would be forced then to go `name_lower` and dupe the column just to add the index.

> [@Utsav](#):
>
> validates :word, presence: true, uniqueness: true, length: { maximum: 50 }

Yeah we should fix this

> [@Utsav](#):
>
> Finally, _WebHookEventType - name_ . ( `app/models/web_hook_event_type.rb` ):

Also fine to add an index here.
