CREATE TABLE IF NOT EXISTS users(
    `id` INT(10) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR (300) UNIQUE NOT NULL,
    `password` VARCHAR (255) NOT NULL,
    `name` VARCHAR(250) NOT NULL DEFAULT "",
    `aboutme` TEXT NOT NULL DEFAULT "",
    `location` VARCHAR(250) NOT NULL DEFAULT "",
    `webpage` VARCHAR(255) NOT NULL DEFAULT "",
    `image` VARCHAR(255) NOT NULL DEFAULT "",
    PRIMARY KEY (id)
);

CREATE TABLE  IF NOT EXISTS groups(
    `id` INT(10) NOT NULL AUTO_INCREMENT,
    `owner_id` INT(10) NOT NULL,
    `name` VARCHAR (255) NOT NULL,
     PRIMARY KEY (id),
     FOREIGN KEY (owner_id) REFERENCES users(id)
);

CREATE TABLE IF NOT EXISTS gallery(
    `id` INT(10) NOT NULL AUTO_INCREMENT,
    `owner_id` INT(10) NOT NULL,
    `group_id` INT(10) DEFAULT NULL,
    `name` VARCHAR (255) NOT NULL,
    `mainImage` VARCHAR(255),
    `mainImageOriginal` VARCHAR(255),
    PRIMARY KEY (id),
    FOREIGN KEY (owner_id) REFERENCES users(id),
    FOREIGN KEY (group_id) REFERENCES groups(id)
);


CREATE TABLE IF NOT EXISTS images
(
    `id` INT(10) NOT NULL AUTO_INCREMENT,
    `gallery_id` INT(10) NOT NULL,
    `path` VARCHAR(255) NOT NULL,
    `path_orginal` VARCHAR(255) NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (gallery_id) REFERENCES gallery(id)
);