-- Deploy guix-data-service:add_location_information to pg

BEGIN;

CREATE TABLE locations (
    id integer GENERATED BY DEFAULT AS IDENTITY,
    file character varying NOT NULL,
    line integer NOT NULL,
    column_number integer NOT NULL,
    CONSTRAINT file_line_column PRIMARY KEY(file, line, column_number),
    UNIQUE (id)
);

ALTER TABLE package_metadata ADD COLUMN location_id integer REFERENCES locations(id);

ALTER TABLE package_metadata DROP CONSTRAINT synopsis_description_home_page;

ALTER TABLE package_metadata ADD CONSTRAINT synopsis_description_home_page_location_id UNIQUE (synopsis, description, home_page, location_id);

COMMIT;
