-- MySQL Script generated by MySQL Workbench
-- Thu Sep 25 10:30:08 2025
-- Model: New Model    Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema cochera2026
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema cochera2026
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `cochera2026` ;
USE `cochera2026` ;

-- -----------------------------------------------------
-- Table `cochera2026`.`empresa`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`empresa` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `nombre` VARCHAR(100) NOT NULL,
  `ubicacion` VARCHAR(255) NULL DEFAULT NULL,
  `logo` TEXT NULL,
  `descripcion` TEXT NULL,
  `fecha_ceacion` TIMESTAMP NULL,
  PRIMARY KEY (`id`));


-- -----------------------------------------------------

-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`roles` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `descripcion` VARCHAR(50) NOT NULL,
  PRIMARY KEY (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`user` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `name` VARCHAR(50) NOT NULL,
  `email` VARCHAR(100) NOT NULL,
  `password` VARCHAR(255) NOT NULL,
  `categoria` VARCHAR(50) NULL DEFAULT NULL,
  `idrol` INT NULL DEFAULT NULL,
  `id_empresa` INT NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX (`email` ASC) VISIBLE,
  INDEX (`idrol` ASC) VISIBLE,
  INDEX (`id_empresa` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`idrol`)
    REFERENCES `cochera2026`.`rol` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_empresa`)
    REFERENCES `cochera2026`.`empresa` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`tipo_vehiculo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`tipo_vehiculo` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `nombre` VARCHAR(50) NOT NULL,
  `valor` FLOAT NULL DEFAULT NULL,
  PRIMARY KEY (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`propietario`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`propietario` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `nombre` VARCHAR(100) NOT NULL,
  `telefono` VARCHAR(20) NULL DEFAULT NULL,
  `tipo_boleta` VARCHAR(50) NULL DEFAULT NULL,
  `numero_boleta` VARCHAR(50) NULL DEFAULT NULL,
  `id_registro` INT NULL DEFAULT NULL,
  PRIMARY KEY (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`vehiculo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`vehiculo` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `placa` VARCHAR(15) NOT NULL,
  `modelo` VARCHAR(50) NULL DEFAULT NULL,
  `marca` VARCHAR(50) NULL DEFAULT NULL,
  `color` VARCHAR(30) NULL DEFAULT NULL,
  `id_tipo_vehiculo` INT NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX (`placa` ASC) VISIBLE,
  INDEX (`id_tipo_vehiculo` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`id_tipo_vehiculo`)
    REFERENCES `cochera2026`.`tipo_vehiculo` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`vehiculo_propietario`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`vehiculo_propietario` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `id_vehiculo` INT NULL DEFAULT NULL,
  `id_propietario` INT NULL DEFAULT NULL,
  `fecha_inicio` DATE NOT NULL,
  `fecha_fin` DATE NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX (`id_vehiculo` ASC) VISIBLE,
  INDEX (`id_propietario` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`id_vehiculo`)
    REFERENCES `cochera2026`.`vehiculo` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_propietario`)
    REFERENCES `cochera2026`.`propietario` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`tolerancia`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`tolerancia` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `minutos` INT NOT NULL,
  `id_tipo_vehiculo` INT NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX (`id_tipo_vehiculo` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`id_tipo_vehiculo`)
    REFERENCES `cochera2026`.`tipo_vehiculo` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`registro`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`registro` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `id_vehiculo` INT NULL DEFAULT NULL,
  `id_user` INT NULL DEFAULT NULL,
  `id_empresa` INT NULL DEFAULT NULL,
  `fecha` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  INDEX (`id_vehiculo` ASC) VISIBLE,
  INDEX (`id_user` ASC) VISIBLE,
  INDEX (`id_empresa` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`id_vehiculo`)
    REFERENCES `cochera2026`.`vehiculo` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_user`)
    REFERENCES `cochera2026`.`user` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_empresa`)
    REFERENCES `cochera2026`.`empresa` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`ingreso`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`ingreso` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `fecha_ingreso` DATE NOT NULL,
  `hora_ingreso` TIME NOT NULL,
  `id_registro` INT NULL DEFAULT NULL,
  `id_user` INT NULL DEFAULT NULL,
  `id_empresa` INT NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX (`id_registro` ASC) VISIBLE,
  INDEX (`id_user` ASC) VISIBLE,
  INDEX (`id_empresa` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`id_registro`)
    REFERENCES `cochera2026`.`registro` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_user`)
    REFERENCES `cochera2026`.`user` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_empresa`)
    REFERENCES `cochera2026`.`empresa` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`salida`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`salida` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `fecha_salida` DATE NOT NULL,
  `hora_salida` TIME NOT NULL,
  `tiempo` TIME NULL DEFAULT NULL,
  `precio` FLOAT NULL DEFAULT NULL,
  `id_ingreso` INT NULL DEFAULT NULL,
  `id_user` INT NULL DEFAULT NULL,
  `id_empresa` INT NULL DEFAULT NULL,
  `id_pago` INT NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX (`id_ingreso` ASC) VISIBLE,
  INDEX (`id_user` ASC) VISIBLE,
  INDEX (`id_empresa` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`id_ingreso`)
    REFERENCES `cochera2026`.`ingreso` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_user`)
    REFERENCES `cochera2026`.`user` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_empresa`)
    REFERENCES `cochera2026`.`empresa` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`pago`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`pago` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `monto` FLOAT NOT NULL,
  `fecha_pago` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
  `metodo` VARCHAR(50) NULL DEFAULT NULL,
  `observacion` TEXT NULL DEFAULT NULL,
  PRIMARY KEY (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`observaciones`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`observaciones` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `tipo` VARCHAR(50) NULL DEFAULT NULL,
  `descripcion` TEXT NULL DEFAULT NULL,
  `id_registro` INT NULL DEFAULT NULL,
  `id_vehiculo` INT NULL DEFAULT NULL,
  `id_ingreso` INT NULL DEFAULT NULL,
  `id_empresa` INT NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX (`id_registro` ASC) VISIBLE,
  INDEX (`id_ingreso` ASC) VISIBLE,
  INDEX (`id_empresa` ASC) VISIBLE,
  INDEX (`id_vehiculo` ASC) VISIBLE,
);


-- -----------------------------------------------------
-- Table `cochera2026`.`tarifa`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`tarifa` (
  `id` INT NULL DEFAULT NULL AUTO_INCREMENT,
  `id_tipo_vehiculo` INT NULL DEFAULT NULL,
  `id_empresa` INT NULL DEFAULT NULL,
  `precio_hora` FLOAT NULL DEFAULT NULL,
  `horario_inicio` TIME NULL DEFAULT NULL,
  `horario_fin` TIME NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX (`id_tipo_vehiculo` ASC) VISIBLE,
  INDEX (`id_empresa` ASC) VISIBLE,
  CONSTRAINT ``
    FOREIGN KEY (`id_tipo_vehiculo`)
    REFERENCES `cochera2026`.`tipo_vehiculo` (`id`),
  CONSTRAINT ``
    FOREIGN KEY (`id_empresa`)
    REFERENCES `cochera2026`.`empresa` (`id`));


-- -----------------------------------------------------
-- Table `cochera2026`.`log`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `cochera2026`.`log` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `accion` VARCHAR(255) NULL,
  `id_user` INT NULL,
  `fecha` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
  `id_empresa` INT NULL,
  `ip` VARCHAR(45) NULL,
  `detalle` TEXT NULL,
  `estado` VARCHAR(20) NULL DEFAULT 'exitoso',
  `user_agent` VARCHAR(255) NULL,
  PRIMARY KEY (`id`),
  INDEX `idx_log_user` (`id_user` ASC),
  INDEX `idx_log_empresa` (`id_empresa` ASC),
  CONSTRAINT `fk_log_user`
    FOREIGN KEY (`id_user`)
    REFERENCES `cochera2026`.`user` (`id`),
  CONSTRAINT `fk_log_empresa`
    FOREIGN KEY (`id_empresa`)
    REFERENCES `cochera2026`.`empresa` (`id`)
);


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
