From 57dcb2ea16ff5cfa37c44fb7028ca446cb16a07d Mon Sep 17 00:00:00 2001 From: Expressionless Ball Thing Date: Fri, 14 Apr 2023 18:43:16 +1000 Subject: [PATCH 1/8] Made a Metadata schema, currently just has a foreign key to the filesystem table. --- postgres/up/05-create_filesystem_table.sql | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index 53e7a23d..89d54ed6 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -25,6 +25,20 @@ CREATE TABLE filesystem ( CONSTRAINT unique_name UNIQUE (Parent, LogicalName, IsDocument) ); +/** + Metadata table +**/ +DROP TABLE IF EXISTS metadata; +CREATE TABLE metadata ( + + EntityID uuid, + + CONSTRAINT fk_attached FOREIGN KEY (EntityID) + REFERENCES filesystem(EntityID), + + CONSTRAINT unique_id UNIQUE (EntityID) +); + /* Utility procedure :) */ DROP FUNCTION IF EXISTS new_entity; CREATE OR REPLACE FUNCTION new_entity (parentP uuid, logicalNameP VARCHAR, ownedByP INT, isDocumentP BOOLEAN DEFAULT false) RETURNS uuid @@ -70,4 +84,4 @@ BEGIN END IF; DELETE FROM filesystem WHERE EntityID = entityIDP; -END $$; \ No newline at end of file +END $$; From 6a6b31d22a83f7177f0a5ef3f987b1b70a42bdea Mon Sep 17 00:00:00 2001 From: Expressionless Ball Thing Date: Fri, 14 Apr 2023 19:18:33 +1000 Subject: [PATCH 2/8] Changed it so that file system also reference metadata. --- postgres/up/05-create_filesystem_table.sql | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index 89d54ed6..43eb85d7 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -13,6 +13,9 @@ CREATE TABLE filesystem ( IsPublished BOOLEAN DEFAULT false, CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), + /* MetaData */ + MetaID uuid NOT NULL, + OwnedBy INT, /* Pain */ Parent uuid REFERENCES filesystem(EntityID) DEFAULT NULL, @@ -20,6 +23,7 @@ CREATE TABLE filesystem ( /* FK Constraint */ CONSTRAINT fk_owner FOREIGN KEY (OwnedBy) REFERENCES groups(UID), + /* Unique name constraint: there should not exist an entity of the same type with the same parent and logical name. */ CONSTRAINT unique_name UNIQUE (Parent, LogicalName, IsDocument) @@ -31,13 +35,19 @@ CREATE TABLE filesystem ( DROP TABLE IF EXISTS metadata; CREATE TABLE metadata ( - EntityID uuid, + MetaID uuid PRIMARY KEY DEFAULT uuid_generate_v4(), + EntityID uuid NOT NULL, + CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), - CONSTRAINT fk_attached FOREIGN KEY (EntityID) + CONSTRAINT fk_file FOREIGN KEY (EntityID) REFERENCES filesystem(EntityID), CONSTRAINT unique_id UNIQUE (EntityID) ); +/* Have to do this because metadata and filesystem references each other. */ +ALTER TABLE filesystem add CONSTRAINT fk_meta + FOREIGN KEY (MetaID) + REFERENCES metadata(MetaID); /* Utility procedure :) */ DROP FUNCTION IF EXISTS new_entity; From 1a89c724d99e46fe2687eb4fb16b14ceecc9a41a Mon Sep 17 00:00:00 2001 From: Expressionless Ball Thing Date: Mon, 24 Apr 2023 17:06:42 +1000 Subject: [PATCH 3/8] changed the field name, and remove the foreign key from meta table to filesystem. --- postgres/up/05-create_filesystem_table.sql | 35 +++++++++------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index 43eb85d7..cdedf64c 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -1,6 +1,17 @@ SET timezone = 'Australia/Sydney'; CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +/* MetaData */ +DROP TABLE IF EXISTS metadata; +CREATE TABLE metadata ( + + MetadataID uuid PRIMARY KEY DEFAULT uuid_generate_v4(), + EntityID uuid NOT NULL, + CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), + + CONSTRAINT unique_id UNIQUE (EntityID) +) + /** The filesystem table models all file heirachies in our system **/ @@ -14,7 +25,7 @@ CREATE TABLE filesystem ( CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), /* MetaData */ - MetaID uuid NOT NULL, + MetadataID uuid NOT NULL, OwnedBy INT, /* Pain */ @@ -24,31 +35,13 @@ CREATE TABLE filesystem ( CONSTRAINT fk_owner FOREIGN KEY (OwnedBy) REFERENCES groups(UID), + CONSTRAINT fk_meta FOREIGN KEY (MetadataID) REFERENCES metadata(MetadataID) + /* Unique name constraint: there should not exist an entity of the same type with the same parent and logical name. */ CONSTRAINT unique_name UNIQUE (Parent, LogicalName, IsDocument) ); -/** - Metadata table -**/ -DROP TABLE IF EXISTS metadata; -CREATE TABLE metadata ( - - MetaID uuid PRIMARY KEY DEFAULT uuid_generate_v4(), - EntityID uuid NOT NULL, - CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), - - CONSTRAINT fk_file FOREIGN KEY (EntityID) - REFERENCES filesystem(EntityID), - - CONSTRAINT unique_id UNIQUE (EntityID) -); -/* Have to do this because metadata and filesystem references each other. */ -ALTER TABLE filesystem add CONSTRAINT fk_meta - FOREIGN KEY (MetaID) - REFERENCES metadata(MetaID); - /* Utility procedure :) */ DROP FUNCTION IF EXISTS new_entity; CREATE OR REPLACE FUNCTION new_entity (parentP uuid, logicalNameP VARCHAR, ownedByP INT, isDocumentP BOOLEAN DEFAULT false) RETURNS uuid From e713f2c3d663f61cc86c4f7f52a021257096b449 Mon Sep 17 00:00:00 2001 From: Varun Sethu Date: Sun, 21 May 2023 22:07:39 +1000 Subject: [PATCH 4/8] fixed pipeline failure --- postgres/dbver.txt | 2 +- postgres/up/05-create_filesystem_table.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres/dbver.txt b/postgres/dbver.txt index 56a6051c..d8263ee9 100644 --- a/postgres/dbver.txt +++ b/postgres/dbver.txt @@ -1 +1 @@ -1 \ No newline at end of file +2 \ No newline at end of file diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index cdedf64c..32afedf3 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -10,7 +10,7 @@ CREATE TABLE metadata ( CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), CONSTRAINT unique_id UNIQUE (EntityID) -) +); /** The filesystem table models all file heirachies in our system From 9f90214e28fd942c37b8056662ae713b913f459f Mon Sep 17 00:00:00 2001 From: Varun Sethu Date: Sun, 21 May 2023 22:16:32 +1000 Subject: [PATCH 5/8] fixed pipeline failure --- postgres/up/05-create_filesystem_table.sql | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index 32afedf3..6467bc49 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -4,12 +4,8 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; /* MetaData */ DROP TABLE IF EXISTS metadata; CREATE TABLE metadata ( - - MetadataID uuid PRIMARY KEY DEFAULT uuid_generate_v4(), - EntityID uuid NOT NULL, - CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), - - CONSTRAINT unique_id UNIQUE (EntityID) + MetadataID uuid PRIMARY KEY DEFAULT uuid_generate_v4(), + CreatedAt TIMESTAMP NOT NULL DEFAULT NOW() ); /** From b4e76d5b0fb29d07b591f0686918823831c32696 Mon Sep 17 00:00:00 2001 From: Varun Sethu Date: Sun, 21 May 2023 22:24:42 +1000 Subject: [PATCH 6/8] fixed pipeline failure --- postgres/up/05-create_filesystem_table.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index 6467bc49..c45f1de7 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -31,7 +31,7 @@ CREATE TABLE filesystem ( CONSTRAINT fk_owner FOREIGN KEY (OwnedBy) REFERENCES groups(UID), - CONSTRAINT fk_meta FOREIGN KEY (MetadataID) REFERENCES metadata(MetadataID) + CONSTRAINT fk_meta FOREIGN KEY (MetadataID) REFERENCES metadata(MetadataID), /* Unique name constraint: there should not exist an entity of the same type with the same parent and logical name. */ From 83967d2eaeaf959b8ecd25662722a18320ab6efa Mon Sep 17 00:00:00 2001 From: Varun Sethu Date: Sun, 21 May 2023 22:36:02 +1000 Subject: [PATCH 7/8] removed fk constraint - easier migration --- postgres/up/05-create_filesystem_table.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index c45f1de7..bf25de1a 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -31,7 +31,7 @@ CREATE TABLE filesystem ( CONSTRAINT fk_owner FOREIGN KEY (OwnedBy) REFERENCES groups(UID), - CONSTRAINT fk_meta FOREIGN KEY (MetadataID) REFERENCES metadata(MetadataID), + -- CONSTRAINT fk_meta FOREIGN KEY (MetadataID) REFERENCES metadata(MetadataID), /* Unique name constraint: there should not exist an entity of the same type with the same parent and logical name. */ From 9b5fc84651bbd89c2310e94a7847cea34d045266 Mon Sep 17 00:00:00 2001 From: Varun Sethu Date: Sun, 21 May 2023 22:40:11 +1000 Subject: [PATCH 8/8] removed fk constraint - easier migration --- postgres/up/05-create_filesystem_table.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/up/05-create_filesystem_table.sql b/postgres/up/05-create_filesystem_table.sql index bf25de1a..68ced09a 100644 --- a/postgres/up/05-create_filesystem_table.sql +++ b/postgres/up/05-create_filesystem_table.sql @@ -21,7 +21,7 @@ CREATE TABLE filesystem ( CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), /* MetaData */ - MetadataID uuid NOT NULL, + -- MetadataID uuid NOT NULL, OwnedBy INT, /* Pain */