﻿CREATE TABLE public.messages
(
   id serial PRIMARY KEY, 
   type character varying(10) NOT NULL,
   channel character varying(64) NOT NULL, 
   channel_network character varying(40) NOT NULL, 
   "user" character varying(31) NOT NULL, 
   user_network character varying(40) NOT NULL, 
   messages integer DEFAULT 0, 
   messages_words bigint DEFAULT 0, 
   messages_characters bigint DEFAULT 0, 
   actions integer DEFAULT 0,
   actions_words bigint DEFAULT 0,
   actions_characters bigint DEFAULT 0,
   notices integer DEFAULT 0,
   notices_words bigint DEFAULT 0,
   notices_characters bigint DEFAULT 0,
   FOREIGN KEY (channel, channel_network) REFERENCES channels(name, network),
   FOREIGN KEY ("user", user_network) REFERENCES users(name, network),
   unique(channel, channel_network, "user", user_network)
);
ALTER TABLE public.messages
  OWNER TO "pyRot";
