CREATE TABLE cat (id BIGINT AUTO_INCREMENT, title TEXT NOT NULL, min_weight FLOAT(10, 3), price FLOAT(10, 2), order_id BIGINT DEFAULT 0 NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE page (id BIGINT AUTO_INCREMENT, title VARCHAR(255) NOT NULL, alias VARCHAR(255) UNIQUE, body TEXT, images text, is_activated TINYINT(1) DEFAULT '1' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE permission (id BIGINT AUTO_INCREMENT, credential VARCHAR(255) NOT NULL UNIQUE, description VARCHAR(255), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE session (id VARCHAR(128), session_data text, session_time BIGINT, user_id BIGINT, token VARCHAR(255), device_id VARCHAR(255), INDEX user_id_idx (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE user (id BIGINT AUTO_INCREMENT, username VARCHAR(255) NOT NULL UNIQUE, name VARCHAR(255) NOT NULL, email VARCHAR(128), email_check VARCHAR(255), email_change VARCHAR(128) NOT NULL, email_change_check VARCHAR(255), social VARCHAR(255), phone VARCHAR(11), phone_check VARCHAR(255), phone_change VARCHAR(11) NOT NULL, salt VARCHAR(128), password VARCHAR(128), password_recovery VARCHAR(255), is_active TINYINT(1) DEFAULT '0' NOT NULL, is_super_admin TINYINT(1) DEFAULT '0', last_login DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX name_idx_idx (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE user_group (id BIGINT AUTO_INCREMENT, title VARCHAR(128) NOT NULL UNIQUE, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE user_group_permissions (user_group_id BIGINT, permission_id BIGINT, PRIMARY KEY(user_group_id, permission_id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE user_group_users (user_id BIGINT, user_group_id BIGINT, PRIMARY KEY(user_id, user_group_id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE user_log (id BIGINT AUTO_INCREMENT, user_id BIGINT NOT NULL, log_type VARCHAR(50) NOT NULL, model VARCHAR(50) NOT NULL, model_id BIGINT NOT NULL, log TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX model_idx_idx (model), INDEX model_id_idx_idx (model_id), INDEX user_id_idx (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE user_permissions (user_id BIGINT, permission_id BIGINT, PRIMARY KEY(user_id, permission_id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
CREATE TABLE cs_setting (id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL UNIQUE, type VARCHAR(255) DEFAULT 'input' NOT NULL, widget_options LONGTEXT, value LONGTEXT, setting_group VARCHAR(255) DEFAULT NULL, setting_default LONGTEXT DEFAULT NULL, variables LONGTEXT DEFAULT NULL, slug VARCHAR(255), UNIQUE INDEX cs_setting_sluggable_idx (slug), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 ENGINE = INNODB;
ALTER TABLE session ADD CONSTRAINT session_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE;
ALTER TABLE user_group_permissions ADD CONSTRAINT user_group_permissions_permission_id_permission_id FOREIGN KEY (permission_id) REFERENCES permission(id);
ALTER TABLE user_group_users ADD CONSTRAINT user_group_users_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE;
ALTER TABLE user_group_users ADD CONSTRAINT user_group_users_user_group_id_user_group_id FOREIGN KEY (user_group_id) REFERENCES user_group(id) ON DELETE CASCADE;
ALTER TABLE user_log ADD CONSTRAINT user_log_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE;
ALTER TABLE user_permissions ADD CONSTRAINT user_permissions_permission_id_permission_id FOREIGN KEY (permission_id) REFERENCES permission(id);
