Correcciones varias... se me fue la onda

Le puse una columna de inserted_at a todas las tablas de la base de
datos excepto las de join

El resto son bugs.. no se, muchas cosas
This commit is contained in:
Daniel Cortés
2019-05-28 23:36:52 -04:00
parent 50ae40449b
commit e4c7e8f282
7 changed files with 114 additions and 70 deletions

View File

@@ -2,53 +2,56 @@
#-----------------------------Eliminar todas las tablas--------------------------#
#--------------------------------------------------------------------------------#
set foreign_key_checks = 0;
drop table if exists usuario;
drop table if exists libro_arriendo;
drop table if exists libro_venta;
drop table if exists libro_compra;
drop table if exists arriendo;
drop table if exists venta;
drop table if exists compra;
drop table if exists boleta;
drop table if exists factura;
drop table if exists trabajador_telefono;
drop table if exists trabajador_direccion;
drop table if exists cliente_telefono;
drop table if exists cliente_direccion;
drop table if exists distribuidor_telefono;
drop table if exists distribuidor_direccion;
drop table if exists trabajador;
drop table if exists cliente;
drop table if exists distribuidor;
drop table if exists empresa;
drop table if exists telefono;
drop table if exists direccion;
drop table if exists libro_idioma;
drop table if exists libro_categoria;
drop table if exists libro_autor;
drop table if exists editorial;
drop table if exists estado;
drop table if exists autor;
drop table if exists categoria;
drop table if exists idioma;
drop table if exists libro;
drop table if exists ejemplar;
drop table if exists editorial;
drop table if exists idioma;
drop table if exists categoria;
drop table if exists autor;
drop table if exists estado;
set foreign_key_checks = 1;
drop table if exists libro_autor;
drop table if exists libro_categoria;
drop table if exists libro_idioma;
drop table if exists direccion;
drop table if exists telefono;
drop table if exists empresa;
drop table if exists distribuidor;
drop table if exists cliente;
drop table if exists trabajador;
drop table if exists distribuidor_direccion;
drop table if exists distribuidor_telefono;
drop table if exists cliente_direccion;
drop table if exists cliente_telefono;
drop table if exists trabajador_direccion;
drop table if exists trabajador_telefono;
drop table if exists factura;
drop table if exists boleta;
drop table if exists compra;
drop table if exists venta;
drop table if exists arriendo;
drop table if exists libro_compra;
drop table if exists libro_venta;
drop table if exists libro_arriendo;
drop table if exists usuario;
set foreign_key_checks = 1;
#--------------------------------------------------------------------------------#
#--------------Definicion de las tablas relacionadas a los libros----------------#
#--------------------------------------------------------------------------------#
create table editorial
(
id int unsigned primary key auto_increment,
nombre varchar(255) not null
id int unsigned primary key auto_increment,
nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table estado
(
id int unsigned primary key auto_increment,
nombre varchar(255) not null
id int unsigned primary key auto_increment,
nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table autor
@@ -56,19 +59,22 @@ create table autor
id int unsigned primary key auto_increment,
nombre varchar(255) not null,
apellido_paterno varchar(255) not null,
apellido_materno varchar(255) not null
apellido_materno varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table categoria
(
id int unsigned primary key auto_increment,
nombre varchar(255) not null
id int unsigned primary key auto_increment,
nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table idioma
(
id int unsigned primary key auto_increment,
nombre varchar(255) not null
id int unsigned primary key auto_increment,
nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table libro
@@ -80,18 +86,20 @@ create table libro
precio_referencia int not null,
ano_publicacion int default null,
editorial_id int unsigned not null,
foreign key (editorial_id) references editorial (id) on delete restrict on update cascade
foreign key (editorial_id) references editorial (id) on delete restrict on update cascade,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table ejemplar
(
id int unsigned primary key auto_increment,
serie varchar(255) not null,
libro_id int unsigned not null,
estado_id int unsigned default 1,
id int unsigned primary key auto_increment,
serie varchar(255) not null,
libro_id int unsigned not null,
estado_id int unsigned default 1,
unique key serie_libro (serie, libro_id),
foreign key (libro_id) references libro (id) on delete cascade on update cascade,
foreign key (estado_id) references estado (id) on delete restrict on update cascade
foreign key (estado_id) references estado (id) on delete restrict on update cascade,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table libro_autor
@@ -124,29 +132,33 @@ create table libro_idioma
#--------------------------------------------------------------------------------#
create table direccion
(
id int unsigned primary key auto_increment,
calle varchar(255) not null,
numero varchar(255) not null
id int unsigned primary key auto_increment,
calle varchar(255) not null,
numero varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table telefono
(
id int unsigned primary key auto_increment,
numero varchar(255) not null
id int unsigned primary key auto_increment,
numero varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table empresa
(
id int unsigned primary key auto_increment,
nombre varchar(255) not null
id int unsigned primary key auto_increment,
nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table distribuidor
(
id int unsigned primary key auto_increment,
rut varchar(255) not null,
empresa_id int unsigned not null,
foreign key (empresa_id) references empresa (id) on delete restrict on update cascade
id int unsigned primary key auto_increment,
rut varchar(255) not null,
empresa_id int unsigned not null,
foreign key (empresa_id) references empresa (id) on delete restrict on update cascade,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table cliente
@@ -156,7 +168,8 @@ create table cliente
nombre varchar(255) not null,
apellido_paterno varchar(255) not null,
apellido_materno varchar(255) not null,
fecha_nacimiento date not null
fecha_nacimiento date not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table trabajador
@@ -166,7 +179,8 @@ create table trabajador
nombre varchar(255) not null,
apellido_paterno varchar(255) not null,
apellido_materno varchar(255) not null,
fecha_contrato date not null
fecha_contrato date not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table distribuidor_direccion
@@ -228,7 +242,8 @@ create table factura
precio_neto int not null,
precio_iva int not null,
costo_iva int not null,
fecha_compra datetime not null
fecha_compra datetime not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table boleta
@@ -238,7 +253,8 @@ create table boleta
precio_neto int not null,
precio_iva int not null,
costo_iva int not null,
fecha_venta datetime not null
fecha_venta datetime not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table compra
@@ -247,7 +263,8 @@ create table compra
factura_id int unsigned not null,
distribuidor_id int unsigned not null,
foreign key (factura_id) references factura (id) on delete restrict on update cascade,
foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade
foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table venta
@@ -258,7 +275,8 @@ create table venta
boleta_id int unsigned not null,
foreign key (cliente_id) references cliente (id) on delete restrict on update cascade,
foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade,
foreign key (boleta_id) references boleta (id) on delete restrict on update cascade
foreign key (boleta_id) references boleta (id) on delete restrict on update cascade,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table arriendo
@@ -271,7 +289,8 @@ create table arriendo
fecha_devolucion_estimada date not null,
fecha_devolucion_real date,
trabajador_id int unsigned not null,
cliente_id int unsigned not null
cliente_id int unsigned not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table libro_compra
@@ -308,7 +327,8 @@ create table usuario
nombre varchar(255) not null,
password varbinary(2000) not null,
trabajador_id int unsigned not null,
foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade
foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade,
inserted_at timestamp default current_timestamp
);
#--------------------------------------------------------------------------------#