DROP TABLE IF EXISTS redirects;

CREATE TABLE redirects
(
    id SERIAL PRIMARY KEY,
    market_id INTEGER NOT NULL,
    source_uri VARCHAR NOT NULL,
    target_uri VARCHAR NOT NULL,
    UNIQUE (market_id, source_uri)
);

GRANT ALL ON TABLE redirects TO root;
GRANT ALL ON TABLE redirects TO photowall_user;
GRANT ALL ON TABLE redirects TO public;

ALTER TABLE redirects
    ADD CONSTRAINT market_fkey
    FOREIGN KEY (market_id)
    REFERENCES markets(id) MATCH SIMPLE;
