Skip to content

Instantly share code, notes, and snippets.

@shahidhk
Created August 28, 2018 10:52
Show Gist options
  • Select an option

  • Save shahidhk/7fa861ceb499024a2224ce1158c5e9ca to your computer and use it in GitHub Desktop.

Select an option

Save shahidhk/7fa861ceb499024a2224ce1158c5e9ca to your computer and use it in GitHub Desktop.
Schema for a realtime poll application
CREATE TABLE "user" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
online_ping boolean,
last_seen_at timestamp with time zone
);
CREATE TABLE poll (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
question text NOT NULL
);
CREATE TABLE option (
id uuid DEFAULT gen_random_uuid() NOT NULL,
poll_id uuid NOT NULL REFERENCES poll (id),
text text NOT NULL
);
CREATE TABLE vote (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_by_user_id uuid NOT NULL REFERENCES "user" (id),
option_id uuid NOT NULL REFERENCES option (id),
created_at timestamp with time zone DEFAULT now() NOT NULL
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment