blog/drafts/published/postgres_messaging_app.md
simonpetit 23cfaf7819
All checks were successful
continuous-integration/drone/push Build is passing
new article ?
2025-12-03 17:15:59 +00:00

900 B

Postgres as a messaging app

Here is a funny idea I came up with : using postgres to make an instant messaging app.

The tables

First create a basic user table:

CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    username VARCHAR
);

Then create a conversation table:

CREATE TABLE conversation (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    name VARCHAR
);

And a participant table:

CREATE TABLE participant (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID REFERENCES users(id),
    conversation_id UUID REFERENCES conversation(id)
);

Then a message table :

CREATE TABLE message ( 
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    sender_id UUID REFERENCES participant(id),
    conversation_id UUID REFERENCES conversation(id),
    content VARCHAR
);