rgncycle-db/sql/create-relations-table.sql

26 lines
548 B
SQL

---
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));
---
DELETE FROM relations;
INSERT INTO relations (relation_role,from_entity,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)
RETURNING *;