BEGIN;

CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY ,
    username VARCHAR(255),
    password VARCHAR(60),
    CONSTRAINT uniq_username
        UNIQUE (username)
);

ALTER TABLE items ADD COLUMN owner_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE;
ALTER TABLE locations ADD COLUMN owner_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE;
ALTER TABLE groups ADD COLUMN owner_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE;
ALTER TABLE categories ADD COLUMN owner_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE;

COMMIT;