Estoy cambiando un poco todo

This commit is contained in:
Daniel Cortés
2019-06-04 14:22:56 -04:00
parent 7e509555c7
commit dc52c8daae
13 changed files with 216 additions and 180 deletions

View File

@@ -58,8 +58,8 @@ 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_paterno varchar(255) null,
apellido_materno varchar(255) null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
@@ -80,26 +80,26 @@ create table idioma
create table libro
(
id int unsigned primary key auto_increment,
isbn varchar(255) not null,
titulo varchar(255) default null,
numero_paginas int not null,
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,
inserted_at timestamp default CURRENT_TIMESTAMP
isbn varchar(255) not null,
ano_publicacion int default null,
numero_paginas int not null,
titulo varchar(255) default null,
precio_referencia int not null,
inserted_at timestamp default CURRENT_TIMESTAMP,
foreign key (editorial_id) references editorial (id) on delete restrict on update cascade
);
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,
serie varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP,
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,
inserted_at timestamp default CURRENT_TIMESTAMP
foreign key (estado_id) references estado (id) on delete restrict on update cascade
);
create table libro_autor
@@ -145,6 +145,13 @@ create table telefono
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table correo
(
id int unsigned primary key auto_increment,
correo varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
create table empresa
(
id int unsigned primary key auto_increment,
@@ -155,10 +162,10 @@ create table empresa
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,
inserted_at timestamp default CURRENT_TIMESTAMP
rut varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP,
foreign key (empresa_id) references empresa (id) on delete restrict on update cascade
);
create table cliente
@@ -199,6 +206,14 @@ create table distribuidor_telefono
foreign key (telefono_id) references telefono (id) on delete restrict on update cascade
);
create table distribuidor_correo
(
distribuidor_id int unsigned,
correo_id int unsigned,
foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade,
foreign key (correo_id) references correo (id) on delete restrict on update cascade
);
create table cliente_direccion
(
cliente_id int unsigned,
@@ -215,6 +230,14 @@ create table cliente_telefono
foreign key (telefono_id) references telefono (id) on delete restrict on update cascade
);
create table cliente_correo
(
cliente_id int unsigned,
correo_id int unsigned,
foreign key (cliente_id) references cliente (id) on delete restrict on update cascade,
foreign key (correo_id) references correo (id) on delete restrict on update cascade
);
create table trabajador_direccion
(
trabajador_id int unsigned,
@@ -231,6 +254,14 @@ create table trabajador_telefono
foreign key (telefono_id) references telefono (id) on delete restrict on update cascade
);
create table trabajador_correo
(
trabajador_id int unsigned,
correo_id int unsigned,
foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade,
foreign key (correo_id) references correo (id) on delete restrict on update cascade
);
#--------------------------------------------------------------------------------#
#-------Definicion de las tablas relacionadas a la venta/compra/arriendo---------#
#--------------------------------------------------------------------------------#
@@ -241,7 +272,6 @@ create table factura
folio varchar(255) not null,
precio_neto int not null,
precio_iva int not null,
costo_iva int not null,
fecha_compra datetime not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
@@ -252,7 +282,6 @@ create table boleta
folio varchar(255) not null,
precio_neto int not null,
precio_iva int not null,
costo_iva int not null,
fecha_venta datetime not null,
inserted_at timestamp default CURRENT_TIMESTAMP
);
@@ -262,9 +291,9 @@ create table compra
id int unsigned primary key auto_increment,
factura_id int unsigned not null,
distribuidor_id int unsigned not null,
inserted_at timestamp default CURRENT_TIMESTAMP,
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,
inserted_at timestamp default CURRENT_TIMESTAMP
foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade
);
create table venta
@@ -273,24 +302,26 @@ create table venta
cliente_id int unsigned not null,
trabajador_id int unsigned not null,
boleta_id int unsigned not null,
inserted_at timestamp default CURRENT_TIMESTAMP,
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,
inserted_at timestamp default CURRENT_TIMESTAMP
foreign key (boleta_id) references boleta (id) on delete restrict on update cascade
);
create table arriendo
(
id int unsigned primary key auto_increment,
trabajador_id int unsigned not null,
cliente_id int unsigned not null,
costo_arriendo int not null,
multa int,
costo_total int,
fecha_arriendo date not null,
fecha_devolucion_estimada date not null,
fecha_devolucion_real date,
trabajador_id int unsigned not null,
cliente_id int unsigned not null,
inserted_at timestamp default CURRENT_TIMESTAMP
multa int,
costo_total int,
inserted_at timestamp default CURRENT_TIMESTAMP,
foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade,
foreign key (cliente_id) references cliente (id) on delete restrict on update cascade
);
create table libro_compra
@@ -349,7 +380,60 @@ values ('Español'),
('Japones');
insert into editorial (nombre)
values ('The Pragmatic Bookshelf'),
('O\'Reilly Media'),
('Manning Publications');
values ('Editorial N1'),
('Editorial N2'),
('Editorial N3');
insert into categoria (nombre)
values ('Terror'),
('Aventura'),
('Fantasia');
insert into autor(nombre, apellido_paterno, apellido_materno)
values ('Howard Philips', 'Lovecraft', NULL),
('Stephen', 'King', NULL),
('Brandon', 'Sanderson', NULL);
insert into libro (editorial_id, isbn, ano_publicacion, numero_paginas, titulo, precio_referencia)
values (1, '0-765-31178-X', 2006, 541, 'Mistborn: The Final Empire', 10000),
(1, '0-765-31688-9', 2007, 590, 'Mistborn: The Well of Ascension', 10000),
(1, '978-0-7653-1689-9', 2008, 572, 'Mistborn: The Hero of Ages', 10000),
(2, '1231231231232', 1931, 100, 'The Shadow over Innsmouth', 10000),
(2, '1231231231232', 1933, 100, 'The Dreams in the Witch House', 10000),
(2, '1231231231232', 1936, 100, 'At the Mountains of Madness', 10000),
(3, '0385086954', 1974, 199, 'Carrie', 10000),
(3, '978-0-670-26077-5', 1979, 428, 'The Dead Zone', 10000),
(3, '0-670-81302-8', 1986, 1138, 'It', 10000);
insert into libro_autor(libro_id, autor_id)
values (1, 3),
(2, 3),
(3, 3),
(4, 1),
(5, 1),
(6, 1),
(7, 2),
(8, 2),
(9, 2);
insert into libro_categoria(libro_id, categoria_id)
values (1, 3),
(2, 3),
(3, 3),
(4, 1),
(5, 1),
(6, 1),
(7, 1),
(8, 1),
(9, 1);
insert into libro_idioma(libro_id, idioma_id)
values (1, 2),
(2, 2),
(3, 2),
(4, 2),
(5, 2),
(6, 2),
(7, 2),
(8, 2),
(9, 2);