--
--



CREATE FUNCTION get_nb_of(my_array smallint[], val smallint) RETURNS integer
    LANGUAGE plpgsql
    AS $$
DECLARE        i int;        res int;        mymax int;BEGIN
        i:=1;
        res:=0;
        SELECT array_upper(my_array,1) INTO mymax;
        WHILE i <= mymax LOOP
                BEGIN
                        IF my_array[i] = val THEN
                                res=res+1;
                        END IF;
                EXCEPTION WHEN OTHERS THEN
                        RAISE NOTICE 'ERROR ON :%',my_array[i];
                        RETURN -1;
                END;
                i=i+1;
        END LOOP;
        RETURN res;

END;
$$;

CREATE FUNCTION get_index_of(my_array integer[], val integer) RETURNS integer
    LANGUAGE plpgsql
    AS $$
DECLARE
        i int;
        res int;
        mymax int;
BEGIN
        i:=1;
        res:=0;
        SELECT array_upper(my_array,1) INTO mymax;
        WHILE i <= mymax LOOP
                BEGIN
                        IF my_array[i] = val THEN
                                RETURN i;
                                res=res+1;
                        END IF;
                EXCEPTION WHEN OTHERS THEN
                        RAISE NOTICE 'ERROR ON :%',my_array[i];
                        RETURN -1;
                END;
                i=i+1;
        END LOOP;
        RETURN -1;

END;
$$;

CREATE FUNCTION get_index_of(my_array smallint[], val smallint) RETURNS integer
    LANGUAGE plpgsql
    AS $$
DECLARE
        i int;
        res int;
        mymax int;
BEGIN
        i:=1;
        res:=0;
        SELECT array_upper(my_array,1) INTO mymax;
        WHILE i <= mymax LOOP
                BEGIN
                        IF my_array[i] like '%'||val||'%' THEN
                                RETURN i;
                                res=res+1;
                        END IF;
                EXCEPTION WHEN OTHERS THEN
                        RAISE NOTICE 'ERROR ON :%',my_array[i];
                        RETURN -1;
                END;
                i=i+1;
        END LOOP;
        RETURN -1;

END;
$$;
--
-- Name: mm; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA mm;


ALTER SCHEMA mm OWNER TO postgres;




--
-- Name: amenagements; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE amenagements (
    id integer NOT NULL,
    name character varying(255),
    filename character varying(255)
);


ALTER TABLE mm.amenagements OWNER TO postgres;

--
-- Name: amenagements_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE amenagements_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.amenagements_id_seq OWNER TO postgres;

--
-- Name: amenagements_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE amenagements_id_seq OWNED BY amenagements.id;


--
-- Name: contexts; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE contexts (
    id integer NOT NULL,
    name character varying(25),
    layers text,
    ext character varying(100)
);


ALTER TABLE mm.contexts OWNER TO postgres;

--
-- Name: contexts_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE contexts_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.contexts_id_seq OWNER TO postgres;

--
-- Name: contexts_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE contexts_id_seq OWNED BY contexts.id;


--
-- Name: favoris; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE favoris (
    id integer NOT NULL,
    map text,
    u_id integer
);


ALTER TABLE mm.favoris OWNER TO postgres;

--
-- Name: favoris_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE favoris_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.favoris_id_seq OWNER TO postgres;

--
-- Name: favoris_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE favoris_id_seq OWNED BY favoris.id;


--
-- Name: groups; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE groups (
    id integer NOT NULL,
    name character varying(25) NOT NULL,
    description text NOT NULL,
    pid integer,
    adm integer
);


ALTER TABLE mm.groups OWNER TO postgres;

--
-- Name: groups_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE groups_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.groups_id_seq OWNER TO postgres;

--
-- Name: groups_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE groups_id_seq OWNED BY groups.id;


--
-- Name: ilinks; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE ilinks (
    id integer NOT NULL,
    name character varying(255),
    url text,
    content text,
    short character varying(250)
);


ALTER TABLE mm.ilinks OWNER TO postgres;

--
-- Name: ilinks_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE ilinks_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.ilinks_id_seq OWNER TO postgres;

--
-- Name: ilinks_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE ilinks_id_seq OWNED BY ilinks.id;


--
-- Name: links; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE links (
    id integer NOT NULL,
    title character varying(255),
    url character varying(255)
);


ALTER TABLE mm.links OWNER TO postgres;

--
-- Name: links_groups; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE links_groups (
    id integer NOT NULL,
    g_id integer,
    l_id integer
);


ALTER TABLE mm.links_groups OWNER TO postgres;

--
-- Name: links_groups_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE links_groups_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.links_groups_id_seq OWNER TO postgres;

--
-- Name: links_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE links_groups_id_seq OWNED BY links_groups.id;


--
-- Name: links_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE links_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.links_id_seq OWNER TO postgres;

--
-- Name: links_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE links_id_seq OWNED BY links.id;


--
-- Name: news; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE news (
    id integer NOT NULL,
    title character varying(50),
    content text,
    newstype integer,
    id_user integer,
    p_date date
);


ALTER TABLE mm.news OWNER TO postgres;

--
-- Name: news_groups; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE news_groups (
    id integer NOT NULL,
    g_id integer,
    n_id integer
);


ALTER TABLE mm.news_groups OWNER TO postgres;

--
-- Name: news_groups_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE news_groups_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.news_groups_id_seq OWNER TO postgres;

--
-- Name: news_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE news_groups_id_seq OWNED BY news_groups.id;


--
-- Name: news_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE news_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.news_id_seq OWNER TO postgres;

--
-- Name: news_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE news_id_seq OWNED BY news.id;


--
-- Name: newstype; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE newstype (
    id integer NOT NULL,
    name character varying(30)
);


ALTER TABLE mm.newstype OWNER TO postgres;

--
-- Name: newstype_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE newstype_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.newstype_id_seq OWNER TO postgres;

--
-- Name: newstype_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE newstype_id_seq OWNED BY newstype.id;


--
-- Name: revetements; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE revetements (
    id integer NOT NULL,
    name character varying(255),
    filename character varying(255),
    type character varying(50)
);


ALTER TABLE mm.revetements OWNER TO postgres;

--
-- Name: revetements_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE revetements_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.revetements_id_seq OWNER TO postgres;

--
-- Name: revetements_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE revetements_id_seq OWNED BY revetements.id;


--
-- Name: savedpath; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE savedpath (
    id integer NOT NULL,
    trace text,
    name character varying(150),
    id_user integer,
    wkb_geometry public.geometry,
    CONSTRAINT enforce_dims_wkb_geometry CHECK ((public.st_ndims(wkb_geometry) = 2)),
    CONSTRAINT enforce_geotype_wkb_geometry CHECK (((public.geometrytype(wkb_geometry) = 'MULTIPOINT'::text) OR (wkb_geometry IS NULL))),
    CONSTRAINT enforce_srid_wkb_geometry CHECK ((public.st_srid(wkb_geometry) = 4326))
);


ALTER TABLE mm.savedpath OWNER TO postgres;

--
-- Name: savedpath_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE savedpath_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.savedpath_id_seq OWNER TO postgres;

--
-- Name: savedpath_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE savedpath_id_seq OWNED BY savedpath.id;


--
-- Name: themes; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE themes (
    id integer NOT NULL,
    name character varying(50),
    description text,
    color character varying(6),
    ord integer,
    pid integer
);


ALTER TABLE mm.themes OWNER TO postgres;

--
-- Name: themes_groups; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE themes_groups (
    id integer NOT NULL,
    t_id integer,
    g_id integer
);


ALTER TABLE mm.themes_groups OWNER TO postgres;

--
-- Name: themes_groups_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE themes_groups_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.themes_groups_id_seq OWNER TO postgres;

--
-- Name: themes_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE themes_groups_id_seq OWNED BY themes_groups.id;


--
-- Name: themes_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE themes_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.themes_id_seq OWNER TO postgres;

--
-- Name: themes_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE themes_id_seq OWNED BY themes.id;


--
-- Name: user_group; Type: TABLE; Schema: mm; Owner: postgres; Tablespace: 
--

CREATE TABLE user_group (
    id integer NOT NULL,
    id_user integer,
    id_group integer
);


ALTER TABLE mm.user_group OWNER TO postgres;

--
-- Name: user_group_id_seq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE user_group_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.user_group_id_seq OWNER TO postgres;

--
-- Name: user_group_id_seq; Type: SEQUENCE OWNED BY; Schema: mm; Owner: postgres
--

ALTER SEQUENCE user_group_id_seq OWNED BY user_group.id;


--
-- Name: velo_users_idseq; Type: SEQUENCE; Schema: mm; Owner: postgres
--

CREATE SEQUENCE velo_users_idseq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE mm.velo_users_idseq OWNER TO postgres;

--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY amenagements ALTER COLUMN id SET DEFAULT nextval('amenagements_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY contexts ALTER COLUMN id SET DEFAULT nextval('contexts_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY favoris ALTER COLUMN id SET DEFAULT nextval('favoris_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY groups ALTER COLUMN id SET DEFAULT nextval('groups_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY ilinks ALTER COLUMN id SET DEFAULT nextval('ilinks_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY links ALTER COLUMN id SET DEFAULT nextval('links_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY links_groups ALTER COLUMN id SET DEFAULT nextval('links_groups_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY news ALTER COLUMN id SET DEFAULT nextval('news_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY news_groups ALTER COLUMN id SET DEFAULT nextval('news_groups_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY newstype ALTER COLUMN id SET DEFAULT nextval('newstype_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY revetements ALTER COLUMN id SET DEFAULT nextval('revetements_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY savedpath ALTER COLUMN id SET DEFAULT nextval('savedpath_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY themes ALTER COLUMN id SET DEFAULT nextval('themes_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY themes_groups ALTER COLUMN id SET DEFAULT nextval('themes_groups_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY user_group ALTER COLUMN id SET DEFAULT nextval('user_group_id_seq'::regclass);


--
-- Name: amenagements_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY amenagements
    ADD CONSTRAINT amenagements_pkey PRIMARY KEY (id);


--
-- Name: contexts_name_key; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY contexts
    ADD CONSTRAINT contexts_name_key UNIQUE (name);


--
-- Name: contexts_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY contexts
    ADD CONSTRAINT contexts_pkey PRIMARY KEY (id);


--
-- Name: favoris_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY favoris
    ADD CONSTRAINT favoris_pkey PRIMARY KEY (id);


--
-- Name: groups_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY groups
    ADD CONSTRAINT groups_pkey PRIMARY KEY (id);


--
-- Name: ilinks_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY ilinks
    ADD CONSTRAINT ilinks_pkey PRIMARY KEY (id);


--
-- Name: links_groups_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY links_groups
    ADD CONSTRAINT links_groups_pkey PRIMARY KEY (id);


--
-- Name: links_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY links
    ADD CONSTRAINT links_pkey PRIMARY KEY (id);


--
-- Name: news_groups_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY news_groups
    ADD CONSTRAINT news_groups_pkey PRIMARY KEY (id);


--
-- Name: news_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY news
    ADD CONSTRAINT news_pkey PRIMARY KEY (id);


--
-- Name: newstype_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY newstype
    ADD CONSTRAINT newstype_pkey PRIMARY KEY (id);


--
-- Name: revetements_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY revetements
    ADD CONSTRAINT revetements_pkey PRIMARY KEY (id);


--
-- Name: savedpath_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY savedpath
    ADD CONSTRAINT savedpath_pkey PRIMARY KEY (id);


--
-- Name: themes_groups_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY themes_groups
    ADD CONSTRAINT themes_groups_pkey PRIMARY KEY (id);


--
-- Name: themes_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY themes
    ADD CONSTRAINT themes_pkey PRIMARY KEY (id);


--
-- Name: uniq_link; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY user_group
    ADD CONSTRAINT uniq_link UNIQUE (id_group, id_user);


--
-- Name: user_group_pkey; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY user_group
    ADD CONSTRAINT user_group_pkey PRIMARY KEY (id);


--
-- Name: velo_groups_name_unicity; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY groups
    ADD CONSTRAINT velo_groups_name_unicity UNIQUE (name);


--
-- Name: velo_savedpath_nameid; Type: CONSTRAINT; Schema: mm; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY savedpath
    ADD CONSTRAINT velo_savedpath_nameid UNIQUE (name, id_user);


--
-- Name: favoris_u_id_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY favoris
    ADD CONSTRAINT favoris_u_id_fkey FOREIGN KEY (u_id) REFERENCES users(id);


--
-- Name: groups_pid_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY groups
    ADD CONSTRAINT groups_pid_fkey FOREIGN KEY (pid) REFERENCES groups(id);


--
-- Name: links_groups_g_id_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY links_groups
    ADD CONSTRAINT links_groups_g_id_fkey FOREIGN KEY (g_id) REFERENCES groups(id);


--
-- Name: links_groups_l_id_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY links_groups
    ADD CONSTRAINT links_groups_l_id_fkey FOREIGN KEY (l_id) REFERENCES links(id);


--
-- Name: news_groups_g_id_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY news_groups
    ADD CONSTRAINT news_groups_g_id_fkey FOREIGN KEY (g_id) REFERENCES groups(id);


--
-- Name: news_groups_n_id_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY news_groups
    ADD CONSTRAINT news_groups_n_id_fkey FOREIGN KEY (n_id) REFERENCES news(id);


--
-- Name: news_id_user_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY news
    ADD CONSTRAINT news_id_user_fkey FOREIGN KEY (id_user) REFERENCES users(id);


--
-- Name: news_newstype_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY news
    ADD CONSTRAINT news_newstype_fkey FOREIGN KEY (newstype) REFERENCES newstype(id);


--
-- Name: savedpath_id_user_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY savedpath
    ADD CONSTRAINT savedpath_id_user_fkey FOREIGN KEY (id_user) REFERENCES users(id);


--
-- Name: themes_pid_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY themes
    ADD CONSTRAINT themes_pid_fkey FOREIGN KEY (pid) REFERENCES themes(id);


--
-- Name: user_group_id_group_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY user_group
    ADD CONSTRAINT user_group_id_group_fkey FOREIGN KEY (id_group) REFERENCES groups(id);


--
-- Name: user_group_id_user_fkey; Type: FK CONSTRAINT; Schema: mm; Owner: postgres
--

ALTER TABLE ONLY user_group
    ADD CONSTRAINT user_group_id_user_fkey FOREIGN KEY (id_user) REFERENCES users(id);


--
--


INSERT INTO groups VALUES (default, 'public', 'Accès public aux applications', NULL, 0);
INSERT INTO groups VALUES (default, 'admin', 'The adminstrator group', NULL, 1);


INSERT INTO user_group VALUES (default, 1, 2);


CREATE TABLE documents (
    id serial PRIMARY KEY,
    name character varying(50),
    title character varying(50),
    description text,
    filename character varying(255),
    url text
);


CREATE TABLE documents_groups (
    id serial PRIMARY KEY,
    g_id integer REFERENCES mm.documents(id),
    d_id integer REFERENCES mm.groups(id)
);


