There is something that always annoys me when I look at a schema.
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 to
NULL 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 AND TRUE IS NULL
NULL AND FALSE IS NULL
NULL AND TRUE OR FALSE…
Now we will create a new Rails 6 application with UUIDs as primary key with PostgreSQL as database adapter.
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
rails g model Post title
Lastly, I started to work with UUIDs and I will give you 3 reasons why:
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.
I assume you have a RESTful application. Because of it, we (client) can easily guess the correct path to access some information.
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
WORKDIR /app# 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