up.sql

The up script contains a statement that creates the channels table. Columns includes the channel id and user_id , which refers to the user in the users table. The channel also has a title column and an is_public column that contains a flag that represents the visibility of the channel. If is_public equals TRUE, it means the channel is public. Look at the following statement:

CREATE TABLE channels (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users,
title TEXT NOT NULL,
is_public BOOL NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

SELECT diesel_manage_updated_at('channels');

The table also has two columns—create_at, which takes the current timestamp when the row is created, and updated_at, which contains the timestamp of the latest update of the row. By default, the updated_at column takes the current timestamp as the default value on creation.

As we mentioned before, diesel creates a diesel_manage_updated_at function that sets a trigger to a table, which updates the updated_at column of rows automatically when the row is updated. Since we have the updated_at column in the table declaration, we can call this function in the SELECT statement.