From 10cf55e273960db1eed0256298c7943cf21dfbf8 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 28 Jun 2021 12:36:05 +0100 Subject: [PATCH] Creating a many-to-many database scenario and seeding with data. --- .../scripts/integrations/postgres/init.sql | 23 +++++++++++++++++++ .../scripts/integrations/postgres/reset.sh | 3 +++ packages/server/src/definitions/datasource.ts | 6 +---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100755 packages/server/scripts/integrations/postgres/reset.sh diff --git a/packages/server/scripts/integrations/postgres/init.sql b/packages/server/scripts/integrations/postgres/init.sql index 8d76f54a10..de8faa437a 100644 --- a/packages/server/scripts/integrations/postgres/init.sql +++ b/packages/server/scripts/integrations/postgres/init.sql @@ -15,3 +15,26 @@ CREATE TABLE Tasks ( FOREIGN KEY(PersonID) REFERENCES Persons(PersonID) ); +CREATE TABLE Products ( + ProductID INT NOT NULL PRIMARY KEY, + ProductName varchar(255) +); +CREATE TABLE Products_Tasks ( + ProductID INT NOT NULL, + TaskID INT NOT NULL, + CONSTRAINT fkProducts + FOREIGN KEY(ProductID) + REFERENCES Products(ProductID), + CONSTRAINT fkTasks + FOREIGN KEY(TaskID) + REFERENCES Tasks(TaskID), + PRIMARY KEY (ProductID, TaskID) +); +INSERT INTO Persons (PersonID, FirstName, LastName, Address, City) VALUES (1, 'Mike', 'Hughes', '123 Fake Street', 'Belfast'); +INSERT INTO Tasks (TaskID, PersonID, TaskName) VALUES (1, 1, 'assembling'); +INSERT INTO Products (ProductID, ProductName) VALUES (1, 'Computers'); +INSERT INTO Products (ProductID, ProductName) VALUES (2, 'Laptops'); +INSERT INTO Products (ProductID, ProductName) VALUES (3, 'Chairs'); +INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 1); +INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (2, 1); +INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (3, 1); diff --git a/packages/server/scripts/integrations/postgres/reset.sh b/packages/server/scripts/integrations/postgres/reset.sh new file mode 100755 index 0000000000..32778bd11f --- /dev/null +++ b/packages/server/scripts/integrations/postgres/reset.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker-compose down +docker volume prune -f diff --git a/packages/server/src/definitions/datasource.ts b/packages/server/src/definitions/datasource.ts index e8a5bfe10a..733ad679cb 100644 --- a/packages/server/src/definitions/datasource.ts +++ b/packages/server/src/definitions/datasource.ts @@ -75,11 +75,7 @@ export interface SearchFilters { } export interface RelationshipsJson { - through?: { - from: string - to: string - tableName: string - } + through?: string from: string to: string tableName: string