stock/stock.sql

74 lines
2.1 KiB
MySQL
Raw Normal View History

2017-10-24 21:42:57 +02:00
\c postgres;
drop database tetastock;
drop role tetastock;
2017-10-21 10:44:11 +02:00
create role tetastock with LOGIN ENCRYPTED PASSWORD 'tetastock';
create database tetastock;
\c tetastock;
2017-10-21 10:44:11 +02:00
CREATE TABLE stock_users (
2017-10-19 11:57:28 +02:00
id serial primary key,
mail text not NULL,
password text not NULL,
name text not NULL
);
2017-10-21 10:44:11 +02:00
CREATE TABLE stock_kits (
2017-10-19 11:57:28 +02:00
id serial primary key,
name text not NULL unique,
designation text not NULL
2017-10-19 11:57:28 +02:00
);
2017-10-21 10:44:11 +02:00
CREATE TABLE stock_providers (
2017-10-19 11:57:28 +02:00
id serial primary key,
name text unique not NULL,
2017-10-19 11:57:28 +02:00
address text not NULL,
mail text not NULL,
url text not NULL,
comment text not NULL
);
2017-10-21 10:44:11 +02:00
CREATE TABLE stock_componants (
2017-10-19 11:57:28 +02:00
id serial primary key,
2017-10-21 10:44:11 +02:00
reference varchar(20) unique not NULL,
2017-10-29 08:31:14 +01:00
designation varchar(100) not NULL,
2017-10-24 21:42:57 +02:00
last_price NUMERIC not NULL default 0,
mean_price NUMERIC not NULL default 0,
quantity NUMERIC not NULL default 0,
min_quantity NUMERIC not NULL default 0,
2017-10-21 10:44:11 +02:00
place varchar(15) not NULL,
provider_id integer REFERENCES stock_providers(id)
2017-10-19 11:57:28 +02:00
);
2017-10-21 10:44:11 +02:00
CREATE TABLE stock_kit_compositions (
2017-10-19 11:57:28 +02:00
id serial primary key,
kit_id integer REFERENCES Stock_kits(id),
2017-10-21 10:44:11 +02:00
componant_id integer REFERENCES stock_componants(id),
2017-10-19 11:57:28 +02:00
quantity integer not NULL
);
2017-10-21 10:44:11 +02:00
CREATE TABLE stock_orders (
id serial primary key,
componant_id integer REFERENCES stock_componants(id),
quantity integer not NULL,
price NUMERIC not NULL default 0,
date timestamp not NULL
);
alter table stock_users owner to tetastock;
alter table stock_kits owner to tetastock;
alter table stock_providers owner to tetastock;
alter table stock_componants owner to tetastock;
alter table stock_kit_compositions owner to tetastock;
alter table stock_orders owner to tetastock;
alter database tetastock owner to tetastock;
insert into stock_users (mail, password, name) values
('doug.letough@free.fr', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough');
insert into stock_users (mail, password, name) values
('doug@redatomik.org', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough');
2017-10-29 08:31:14 +01:00
insert into stock_users (mail, password, name) values ('test', '$2b$08$OkfihuGRyLdpftBpGhnpeeeUhUTQS0oXvR2NFByC.65XCKKvPBWHS');