 COMMENT ON COLUMN route.way IS 'Aller ou retour.';
 COMMENT ON COLUMN route.name IS 'Nom du parcours type (Hastus ou Tigre).';
 COMMENT ON COLUMN route.direction IS 'Titre de la direction, a terme, viendra de l''application girouette.';
-
-
-
+ALTER TABLE ONLY route ADD CONSTRAINT route_id_pk PRIMARY KEY (id);
+ALTER TABLE ONLY route ADD CONSTRAINT route_comment_id FOREIGN KEY (comment_id) REFERENCES comment(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
+ALTER TABLE ONLY route ADD CONSTRAINT route_line_version_id_fk FOREIGN KEY (line_version_id) REFERENCES line_version(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX route_line_version_id_idx ON route USING btree (line_version_id);
 
 CREATE TABLE route_datasource (
-    id integer NOT NULL,
+    id serial,
     route_id integer NOT NULL,
     datasource_id integer NOT NULL,
     code character varying(20)
 );
 COMMENT ON TABLE route_datasource IS 'Reference de l''objet dans le referentiel de la datasource.';
-CREATE SEQUENCE route_datasource_id_seq
-    START WITH 1
-    INCREMENT BY 1
-    NO MINVALUE
-    NO MAXVALUE
-    CACHE 1;
-ALTER SEQUENCE route_datasource_id_seq OWNED BY route_datasource.id;
-CREATE SEQUENCE route_id_seq
-    START WITH 1
-    INCREMENT BY 1
-    NO MINVALUE
-    NO MAXVALUE
-    CACHE 1;
-ALTER SEQUENCE route_id_seq OWNED BY route.id;
-
-
-
+ALTER TABLE ONLY route_datasource ADD CONSTRAINT route_datasource_pk PRIMARY KEY (id);
+ALTER TABLE ONLY route_datasource ADD CONSTRAINT route_datasource_datasource_id_fk FOREIGN KEY (datasource_id) REFERENCES datasource(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
+ALTER TABLE ONLY route_datasource ADD CONSTRAINT route_datasource_route_id_fk FOREIGN KEY (route_id) REFERENCES route(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX route_datasource_code_idx ON route_datasource USING btree (code);
+CREATE INDEX route_datasource_route_id_idx ON route_datasource USING btree (route_id);
 
 CREATE TABLE route_not_exported (
-    id integer NOT NULL,
+    id serial,
     route_id integer,
     export_destination_id integer
 );
 COMMENT ON TABLE route_not_exported IS 'Routes qui ne doivent pas être exportées en production car il y a un travail en cours ou obsolete.';
-CREATE SEQUENCE route_not_exported_id_seq
-    START WITH 1
-    INCREMENT BY 1
-    NO MINVALUE
-    NO MAXVALUE
-    CACHE 1;
-ALTER SEQUENCE route_not_exported_id_seq OWNED BY route_not_exported.id;
-
-
-
+ALTER TABLE ONLY route_not_exported ADD CONSTRAINT route_not_exported_pk PRIMARY KEY (id);
+ALTER TABLE ONLY route_not_exported ADD CONSTRAINT route_not_exported_export_destination_id_fk FOREIGN KEY (export_destination_id) REFERENCES export_destination(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
+ALTER TABLE ONLY route_not_exported ADD CONSTRAINT route_not_exported_route_id_fk FOREIGN KEY (route_id) REFERENCES route(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
 
 CREATE TABLE route_section (
-    id integer NOT NULL,
+    id serial,
     start_stop_id integer NOT NULL,
     end_stop_id integer NOT NULL,
     start_date date NOT NULL,

COMMENT ON TABLE stop_time IS 'Horaire d''un troncon d''itineraire.';
COMMENT ON COLUMN stop_time.arrival_time IS 'Temps en seconde apres minuit de la date. Peut depasser 23h59.';
COMMENT ON COLUMN stop_time.departure_time IS 'Temps en seconde apres minuit de la date. Peut depasser 23h59.';
CREATE SEQUENCE stop_time_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE stop_time_id_seq OWNED BY stop_time.id;




CREATE TABLE transfer (
    id integer NOT NULL,
    start_stop_id integer NOT NULL,
    end_stop_id integer NOT NULL,
    duration integer NOT NULL,

    drop_off boolean NOT NULL
);
COMMENT ON TABLE odt_stop IS 'Lien entre un arret et une zone d''arret pour un intervalle de temps.';
ALTER TABLE ONLY odt_stop ADD CONSTRAINT odt_stop_pk PRIMARY KEY (odt_area_id, stop_id, start_date);
ALTER TABLE ONLY odt_stop ADD CONSTRAINT odt_stop_odt_area_id_fk FOREIGN KEY (odt_area_id) REFERENCES odt_area(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY odt_stop ADD CONSTRAINT odt_stop_stop_id_fk FOREIGN KEY (stop_id) REFERENCES stop(id) ON UPDATE RESTRICT ON DELETE RESTRICT;

CREATE TABLE physical_mode (
    id serial,
    name character varying(30) NOT NULL,
    type character varying(30) NOT NULL
);
COMMENT ON TABLE physical_mode IS 'Mode de transport.';
ALTER TABLE ONLY physical_mode ADD CONSTRAINT physical_mode_fk PRIMARY KEY (id);

CREATE TABLE poi (
    id serial,
    name character varying(255) NOT NULL,
    city_id integer NOT NULL,
    poi_type_id integer NOT NULL,
