---
title: 'This week in #dev (Mar 24, 2023)'
teaser: 'It''s all about databases in this edition!

  '
tags: this week in dev,activerecord,postgresql,databases
author: thoughtbot
published_on: 2023-04-07
---

<aside class="info">
  <p>
    It's been a while since the last edition of This Week in #dev. It was a
    combination of busy days and some PTO. We're back now, and I'll be posting
    some retroactive editions soon. Stay tuned!
  </p>
</aside>

Welcome to another edition of This Week in #dev, a series of posts where we
bring some of the most interesting Slack conversations to the public. Today
we're talking about: GitHub's shared numbering sequence for Issues and Pull
Requests, filtering records in Postgres and database consitency.

## GitHub's Issue and Pull Request Numbering

[Louis Antonopoulos] discovered that GitHub Issues and Pull Requests share the
same numbering sequence, meaning that the next issue created after a Pull
Request is the number after the Pull Request number. He was surprised to find
out that this was the case, as he had previously assumed that the UI was doing
some kind of text analysis magic.

[Matheus Richard] suggests it is possible that GitHub uses the same underlying model
for both Issues and Pull Requests, which is why they share the same ID sequence. They also
discussed how GitLab treats issues and PRs differently using different syntax
for reference (`#123` for issues and `!123` for Merge Requests).

## Using Postgres ANY() to Filter Records

[Fernando Marques] learned about the Postgres' ANY() method, which can be used in
Active Record to filter/scope a search by one of the contents of an array
column. Here's one example of how to use it:

```ruby
Item.create(tags: ["modern", "leather", "jacket"], ...)

Item.where(":tags = ANY(tags)", tags: "modern") # also replaceable with `find_by`

# =>
# [#<Item:0x00000001191df258
#   id: 1,
#   tags: ["modern", "leather", "jacket"],
#   ...>
# ]
```

<aside class="info">
  <p>
    <a href="https://thoughtbot.com/blog/authors/summer">
      Summer ☀️
    </a>
    pointed out
    <a href="https://guides.rubyonrails.org/v7.0.4.2/active_record_postgresql.html#array">
      the Rails documentation
    </a>
    for working with Array types in Postgres.
  </p>
</aside>

## Database Gems for Improved Consistency and Indexing

[Matheus Richard] shares two gems to help with database management:
[database_consistency] which finds inconsistencies between AR models and DB
tables, and [lol_dba] which focuses on indexes and can generate a migration to
fix any problems.

[Neil Carvalho] includes [pghero] on the list. It gives you a nicer view of the
statistics collected by pg_stat_statement, and suggests missing indexes based on
your slower queries, he says. [rails-pg-extras] is another similar gem, [Summer ☀️]
adds.

[database_consistency]: https://github.com/djezzzl/database_consistency
[lol_dba]: https://github.com/plentz/lol_dba
[pghero]: https://github.com/ankane/pghero
[rails-pg-extras]: https://github.com/pawurb/rails-pg-extras

## Thanks

This edition was brought to you by [Fernando Marques], [Louis Antonopoulos],
[Matheus Richard], [Neil Carvalho], and [Summer ☀️]. Thanks to all contributors! 🎉

[Louis Antonopoulos]: https://thoughtbot.com/blog/authors/louis-antonopoulos
[Fernando Marques]: https://thoughtbot.com/blog/authors/fernando-marques
[Matheus Richard]: https://thoughtbot.com/blog/authors/matheus-richard
[Neil Carvalho]: https://thoughtbot.com/blog/authors/neil-carvalho
[Summer ☀️]: https://thoughtbot.com/blog/authors/summer
