Skip to content

Instantly share code, notes, and snippets.

@Youka
Created December 27, 2024 20:02
Show Gist options
  • Save Youka/119f842cedaec508f25a228a47094b02 to your computer and use it in GitHub Desktop.
Save Youka/119f842cedaec508f25a228a47094b02 to your computer and use it in GitHub Desktop.
Simple postgres script to create a users table
CREATE TABLE IF NOT EXISTS users (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name varchar(32) UNIQUE NOT NULL CHECK (length(name) >= 3),
avatar_file bytea STORAGE EXTERNAL CHECK (avatar_file IS NULL OR length(avatar_file) < 50000),
about_me varchar(2048),
date_time_creation timestamp NOT NULL DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'utc'),
date_time_last_login timestamp CHECK (date_time_last_login IS NULL OR date_time_last_login >= date_time_creation)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment