-- PW-1312: add table for addresses

DROP TABLE IF EXISTS addresses;

CREATE TABLE addresses (
    id SERIAL PRIMARY KEY,
    address1 VARCHAR,
    name VARCHAR,
    company_name VARCHAR,
    country_code VARCHAR,
    city VARCHAR,
    zipcode VARCHAR,
    state_code VARCHAR,
    co VARCHAR,
    house_number VARCHAR,
    house_extension VARCHAR
);

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

ALTER TABLE addresses
    ADD CONSTRAINT country_code_fkey
    FOREIGN KEY (country_code)
    REFERENCES "i18n-territories"(iso2char) MATCH SIMPLE;

ALTER TABLE addresses
    ADD CONSTRAINT state_code_fkey
    FOREIGN KEY (state_code)
    REFERENCES states(code) MATCH SIMPLE;
