   id uuid primary key default uuid_generate_v4(),
   created timestamp not null default current_timestamp,
   modified timestamp not null default current_timestamp,
-  user_id uuid null references sg_public.user (id),
+  user_id uuid null references sg_public.user (id)
+    check (kind = 'post' or kind = 'proposal' or user_id is not null),
   topic_id uuid not null references sg_public.topic (id),
   kind sg_public.post_kind not null default 'post',
   body text null
     check (kind = 'vote' or body is not null),
-  replies_to_id uuid null references sg_public.post (id)
-    check (kind <> 'vote' or replies_to_id is not null),
+  parent_id uuid null references sg_public.post (id)
+    check (kind = 'post' or kind = 'proposal' or parent_id is not null),
   response boolean null
-    check (kind <> 'vote' or response is not null)
+    check (kind = 'post' or kind = 'proposal' or response is not null)
   -- also see join table: sg_public.post_entity_version
   -- specific to kind = 'proposal'
 );

  is 'The kind of post (post, proposal, vote).';
comment on column sg_public.post.body
  is 'The body or main content of the post.';
comment on column sg_public.post.replies_to_id
  is 'If the post is a reply, which post it replies to.';
comment on column sg_public.post.response
  is 'If the post is a vote, yes/no on approving.';

-- Insert post: any.
grant insert on table sg_public.post to sg_anonymous, sg_user, sg_admin;
create policy insert_post on sg_public.post
  for insert (topic_id, kind, body, parent_id, response) -- any user
  using (true);

-- Update post: user self (body, response), or admin.
