Actualize la base de datos
Plus un script que ejecuta la migracion automaticamente
This commit is contained in:
45
create.sql
45
create.sql
@@ -1,7 +1,10 @@
|
||||
#--------------------------------------------------------------------------------#
|
||||
#-----------------------------Eliminar todas las tablas--------------------------#
|
||||
#--------------------------------------------------------------------------------#
|
||||
start transaction;
|
||||
|
||||
set foreign_key_checks = 0;
|
||||
set autocommit = 0;
|
||||
|
||||
drop table if exists editorial;
|
||||
drop table if exists estado;
|
||||
@@ -17,7 +20,7 @@ drop table if exists correo;
|
||||
drop table if exists direccion;
|
||||
drop table if exists telefono;
|
||||
drop table if exists empresa;
|
||||
drop table if exists cliente;
|
||||
drop table if exists distribuidor;
|
||||
drop table if exists cliente;
|
||||
drop table if exists trabajador;
|
||||
drop table if exists distribuidor_direccion;
|
||||
@@ -34,12 +37,11 @@ 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 ejemplar_compra;
|
||||
drop table if exists ejemplar_venta;
|
||||
drop table if exists ejemplar_arriendo;
|
||||
drop table if exists usuario;
|
||||
|
||||
set foreign_key_checks = 1;
|
||||
|
||||
#--------------------------------------------------------------------------------#
|
||||
#--------------Definicion de las tablas relacionadas a los libros----------------#
|
||||
@@ -163,7 +165,7 @@ create table empresa
|
||||
inserted_at timestamp default CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
create table cliente
|
||||
create table distribuidor
|
||||
(
|
||||
id int unsigned primary key auto_increment,
|
||||
empresa_id int unsigned not null,
|
||||
@@ -328,27 +330,27 @@ create table arriendo
|
||||
foreign key (cliente_id) references cliente (id) on delete restrict on update cascade
|
||||
);
|
||||
|
||||
create table libro_compra
|
||||
create table ejemplar_compra
|
||||
(
|
||||
libro_id int unsigned,
|
||||
compra_id int unsigned,
|
||||
foreign key (libro_id) references libro (id) on delete restrict on update cascade,
|
||||
ejemplar_id int unsigned,
|
||||
compra_id int unsigned,
|
||||
foreign key (ejemplar_id) references ejemplar (id) on delete restrict on update cascade,
|
||||
foreign key (compra_id) references compra (id) on delete restrict on update cascade
|
||||
);
|
||||
|
||||
create table libro_venta
|
||||
create table ejemplar_venta
|
||||
(
|
||||
libro_id int unsigned,
|
||||
venta_id int unsigned,
|
||||
foreign key (libro_id) references libro (id) on delete restrict on update cascade,
|
||||
ejemplar_id int unsigned,
|
||||
venta_id int unsigned,
|
||||
foreign key (ejemplar_id) references ejemplar (id) on delete restrict on update cascade,
|
||||
foreign key (venta_id) references venta (id) on delete restrict on update cascade
|
||||
);
|
||||
|
||||
create table libro_arriendo
|
||||
create table ejemplar_arriendo
|
||||
(
|
||||
libro_id int unsigned,
|
||||
ejemplar_id int unsigned,
|
||||
arriendo_id int unsigned,
|
||||
foreign key (libro_id) references libro (id) on delete restrict on update cascade,
|
||||
foreign key (ejemplar_id) references ejemplar (id) on delete restrict on update cascade,
|
||||
foreign key (arriendo_id) references arriendo (id) on delete restrict on update cascade
|
||||
);
|
||||
|
||||
@@ -363,6 +365,11 @@ create table usuario
|
||||
password binary(32) not null,
|
||||
salt binary(16) not null,
|
||||
trabajador_id int unsigned not null,
|
||||
foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade,
|
||||
inserted_at timestamp default current_timestamp
|
||||
inserted_at timestamp default current_timestamp,
|
||||
foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade
|
||||
);
|
||||
|
||||
set autocommit = 1;
|
||||
set foreign_key_checks = 1;
|
||||
|
||||
commit;
|
||||
Reference in New Issue
Block a user