CREATE TABLE author (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description LONGTEXT, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE bid (id BIGINT AUTO_INCREMENT, user_id BIGINT, item_id BIGINT, price_bid DECIMAL(10, 2), time_bid DATETIME NOT NULL, INDEX item_id_idx (item_id), INDEX user_id_idx (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE bid_limit (id BIGINT AUTO_INCREMENT, user_id BIGINT, item_id BIGINT, price_bid DECIMAL(10,2), INDEX item_id_idx (item_id), INDEX user_id_idx (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE category (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description LONGTEXT, image VARCHAR(255), slug VARCHAR(255), created_at DATETIME, updated_at DATETIME, created_by BIGINT, updated_by BIGINT, archived TINYINT DEFAULT 0 NOT NULL, position BIGINT, UNIQUE INDEX sortable_idx (position), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE item (id BIGINT AUTO_INCREMENT, category_id BIGINT, author_id BIGINT, kind_id BIGINT, name VARCHAR(255) NOT NULL, description LONGTEXT, image VARCHAR(255), code VARCHAR(255), year VARCHAR(4), size VARCHAR(255), price_start DECIMAL(10,2) NOT NULL, price_actual DECIMAL(10,2), price_bid DECIMAL(10,2) NOT NULL, is_published TINYINT(1) DEFAULT '0', time_start DATETIME, time_end DATETIME, continuation TINYINT(1), is_finished TINYINT(1), status BIGINT, slug VARCHAR(255), created_at DATETIME, updated_at DATETIME, created_by BIGINT, updated_by BIGINT, archived TINYINT DEFAULT 0 NOT NULL, INDEX category_id_idx (category_id), INDEX author_id_idx (author_id), INDEX kind_id_idx (kind_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE kind (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE page (id BIGINT AUTO_INCREMENT, page_id BIGINT, name VARCHAR(255) NOT NULL, content LONGTEXT, in_menu TINYINT(1) DEFAULT '1', slug VARCHAR(255), created_at DATETIME, updated_at DATETIME, created_by BIGINT, updated_by BIGINT, position BIGINT, UNIQUE INDEX sortable_idx (position, page_id), INDEX page_id_idx (page_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE user (id BIGINT AUTO_INCREMENT, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, street VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL, zip VARCHAR(255) NOT NULL, state VARCHAR(255) NOT NULL, tel VARCHAR(255) NOT NULL, is_admin TINYINT(1) DEFAULT '0', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
ALTER TABLE bid ADD FOREIGN KEY (user_id) REFERENCES user(id);
ALTER TABLE bid ADD FOREIGN KEY (item_id) REFERENCES item(id);
ALTER TABLE bid_limit ADD FOREIGN KEY (user_id) REFERENCES user(id);
ALTER TABLE bid_limit ADD FOREIGN KEY (item_id) REFERENCES item(id);
ALTER TABLE item ADD FOREIGN KEY (kind_id) REFERENCES kind(id);
ALTER TABLE item ADD FOREIGN KEY (category_id) REFERENCES category(id);
ALTER TABLE item ADD FOREIGN KEY (author_id) REFERENCES author(id);
ALTER TABLE page ADD FOREIGN KEY (page_id) REFERENCES page(id);
