Why null is not always the right solution

Photo by Chris Barbalis on Unsplash

There is something that always annoys me when I look at a schema.

active can have 3 values: true, false and nil

When I create a user, I expect to have the most important columns filled.

active is an important value because this information can change the whole behaviour of my application.

I refer toNULL as "I don't know," and this answer is not acceptable for this column.

You should avoid NULL for a boolean.

In SQL, you cannot compare NULL with TRUE and FALSE.

Discover the power of UUIDs on a brand new Rails application

by Joshua Fuller

In my last article, I explained why it is better to use UUIDs instead of sequential IDs.

Now we will create a new Rails 6 application with UUIDs as primary key with PostgreSQL as database adapter.

Enabling UUID to our application

PostgreSQL can store many pieces of information like data types.

rails new rails_uuid -d=postgresql

To be able to use the power of UUID with PostgreSQL, we need to create a migration.

rails g migration enable_uuid

PostgresSQL knows now how to create tables with UUID type

Set UUID as a default Primary key type

With this configuration, our new models will have UUID as a primary key type

Creating our first model

Run rails g model Post title

As you see now, we need to specify the uuid as primary key when we…

Working with UUIDs instead of IDs gives a lot of benefits.

by Ronan Le Fichant

Lastly, I started to work with UUIDs and I will give you 3 reasons why:

1. When you are providing IDs to your clients, they might know the numbers of records.

This can be nothing when you are a small company, but you give this info to your rivals and malicious users.

For example, if you create a new user, the server will increment the ID in the database and give you the biggest (latest) one. So if your user is number 1334. You can guess the size of users in the database.

2. You can randomly guess the path of a resource.

I assume you have a RESTful application. Because of it, we (client) can easily guess the correct path to access some information.


Rails 6 comes with a lot of new features including Webpack.

Chapter 1: Dockerfile

I assume you already have a Rails project created with PostgreSQL.

Now we will create a Dockerfile file in the root project.

# Dockerfile# Use ruby image to build our own image
FROM ruby:2.7
# We specify everything will happen within the /app folder inside the container
# We copy these files from our current application to the /app container
COPY Gemfile Gemfile.lock ./
# We install all the dependencies
RUN bundle install
# We copy all the files from our current application to the /app container
COPY . .
# We expose the port

Guillaume Occuly

Ruby Developer — http://www.occuly.me/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store