SET client_encoding = 'UTF-8';
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;


SET search_path = public, pg_catalog;


CREATE SEQUENCE appart_id_seq
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;

ALTER TABLE public.appart_id_seq OWNER TO appart;


SET default_tablespace = '';

SET default_with_oids = false;


/** Version 1 **/


CREATE TABLE appart (
    id integer DEFAULT nextval('appart_id_seq'::regclass) NOT NULL,
    prix numeric(28,0),
    prixcharges numeric(10,0),
    rue text DEFAULT ''::text NOT NULL,
    nbpiece character varying(28),
    surface numeric(28,0),
    description text DEFAULT ''::text NOT NULL,
    contact text DEFAULT ''::text NOT NULL,
    url character varying(200) DEFAULT ''::character varying NOT NULL,
    etage numeric(5,0),
    annee_construction numeric(28,0),
    points_positifs text DEFAULT ''::text NOT NULL,
    points_negatifs text DEFAULT ''::text NOT NULL,
    date_visite date,
    visite_indications text DEFAULT ''::text NOT NULL,
    statut smallint DEFAULT 0 NOT NULL,
    localite character varying(100) DEFAULT ''::character varying
);


ALTER TABLE public.appart OWNER TO appart;

COMMENT ON COLUMN appart.statut IS 'statut : 0 = pas visité 1 = on a rendez-vous, 2 = visité, 3 = déjà pris :(';

ALTER TABLE ONLY appart ADD CONSTRAINT appart_pkey PRIMARY KEY (id);

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;

REVOKE ALL ON TABLE appart FROM PUBLIC;
REVOKE ALL ON TABLE appart FROM appart;
GRANT ALL ON TABLE appart TO appart;
GRANT ALL ON TABLE appart TO appart_group;

REVOKE ALL ON TABLE site FROM PUBLIC;
REVOKE ALL ON TABLE site FROM appart;
GRANT ALL ON TABLE site TO appart;
GRANT ALL ON TABLE site TO appart_group;


/** Version 2 **/

ALTER TABLE public.appart ALTER date_visite TYPE timestamp without time zone;
ALTER TABLE public.appart ADD COLUMN date_libre date;

ALTER TABLE public.appart ADD COLUMN url_map text;
ALTER TABLE public.appart ALTER COLUMN url_map SET DEFAULT '';

