feat: adjust scripts

This commit is contained in:
dancingCycle 2023-04-25 21:36:30 +02:00
parent 92d1193cef
commit 1ba1fe3480
5 changed files with 22 additions and 43 deletions

View File

@ -1,11 +0,0 @@
#!/bin/bash
#
echo "Started..."
#Started...
DB_NAME="todo"
DB_USER="todo"
#
psql -h localhost -p 5432 -U $DB_USER -f ./sql/create-relation_roles-table.sql -d $DB_NAME
#
echo "Done."
#Done.

0
script/create-relations-table.sh Normal file → Executable file
View File

View File

@ -1,8 +1,6 @@
---
DROP TABLE IF EXISTS relations;
---
DROP TABLE IF EXISTS relation_roles;
---
DROP TABLE IF EXISTS entities;
---
CREATE TABLE IF NOT EXISTS entities(
@ -19,7 +17,11 @@ VALUES
('Hostsharing eG',53.6388387,10.0148720),
('WEtell GmbH',48.0143619,7.8450213),
('WTF Kooperative eG',53.5836365,10.0153690),
('Software Ingenieur Begerad',52.2659474, 10.4394900),
('GLS Gemeinschaftsbank eG',51.4708953,7.2195074),
('Fairphone', 52.3900606,4.8890757),
('dieUmweltDruckerei GmbH',52.3741017,9.7454469)
('dieUmweltDruckerei GmbH',52.3741017,9.7454469),
('Reka',52.1625908,10.2982074),
('Hof Morgentau',52.2254150,10.4556969),
('Der kleine Heideladen',52.2651152, 10.43836880)
RETURNING *;

View File

@ -1,13 +0,0 @@
---
DROP TABLE IF EXISTS relation_roles;
---
CREATE TABLE IF NOT EXISTS relation_roles(
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL);
---
DELETE FROM relation_roles;
INSERT INTO relation_roles (name)
VALUES
('supplier'),
('customer')
RETURNING *;

View File

@ -2,24 +2,25 @@
DROP TABLE IF EXISTS relations;
---
CREATE TABLE IF NOT EXISTS relations(
id BIGSERIAL PRIMARY KEY,
relation_role BIGINT NOT NULL,
from_entity BIGINT NOT NULL,
to_entity BIGINT NOT NULL,
FOREIGN KEY(relation_role) REFERENCES relation_roles(id),
FOREIGN KEY(to_entity) REFERENCES entities(id),
FOREIGN KEY(from_entity) REFERENCES entities(id));
relation_id BIGSERIAL PRIMARY KEY,
relation_from_entity BIGINT NOT NULL,
relation_to_entity BIGINT NOT NULL,
FOREIGN KEY(relation_to_entity) REFERENCES entities(entity_id),
FOREIGN KEY(relation_from_entity) REFERENCES entities(entity_id));
---
DELETE FROM relations;
INSERT INTO relations (relation_role,from_entity,to_entity)
INSERT INTO relations (relation_from_entity,relation_to_entity)
VALUES
(1,6,1),
(1,6,2),
(1,6,3),
(1,6,4),
(1,6,5),
(1,6,7),
(1,6,8),
(1,5,6)
(6,1),
(6,2),
(6,3),
(6,4),
(6,5),
(6,7),
(6,8),
(6,9),
(6,10),
(6,11),
(6,12)
RETURNING *;