you need to redesign a database, so it matches our requirements starting code: CREATE…
- User
you need to redesign a database, so it matches our requirements
starting code: CREATE TABLE "Detail" ( "id" SERIAL NOT NULL UNIQUE, "VIN" VARCHAR(255), "Name" VARCHAR(255), "Parent" INTEGER, "Desc" TEXT, "Note" TEXT, PRIMARY KEY("id") );
CREATE TABLE "Folder" ( "id" SERIAL NOT NULL UNIQUE, "Parent" INTEGER, "Tag" CHAR(4), "VIN" VARCHAR(255) ARRAY, PRIMARY KEY("id") );
CREATE TABLE "IMG" ( "id" SERIAL NOT NULL UNIQUE, "Parent" INTEGER NOT NULL, "Path" TEXT NOT NULL, PRIMARY KEY("id") );
CREATE TABLE "Position" ( "id" SERIAL NOT NULL, "Number" SMALLINT NOT NULL UNIQUE GENERATED BY DEFAULT AS IDENTITY, "Coordinate" POINT ARRAY NOT NULL, "Detail_id" INTEGER, "Folder_id" INTEGER, PRIMARY KEY("id") );
ALTER TABLE "Detail" ADD FOREIGN KEY("Parent") REFERENCES "Folder"("id") ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE "Folder" ADD FOREIGN KEY("Parent") REFERENCES "Folder"("id") ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE "IMG" ADD FOREIGN KEY("Parent") REFERENCES "Detail"("id") ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE "IMG" ADD FOREIGN KEY("Parent") REFERENCES "Folder"("id") ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE "Detail" ADD FOREIGN KEY("id") REFERENCES "Position"("Detail_id") ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE "Folder" ADD FOREIGN KEY("id") REFERENCES "Position"("Folder_id") ON UPDATE NO ACTION ON DELETE NO ACTION;
requirements:
- detail can belong to multiple folders
- folder can belong to multiple folders and have multiple child elements
- detail can have no child elements
- each detail can have different position when it is in different folder
- each folder can have different position when it is in different folder
- folder or detail can have no position when inside folder
- there can't be 2 elements with the same position inside folder
answers to common questions:
- yes, it's DAG
- folder and detail can't share same position inside the same folder
- sometimes details and folders can have no position inside folder
- detail can't have child details or folders
- folder can have other folders as child
- position of a detail or a folder is unique only within a folder they belong to. e.g. detail A have position 2 in folder B and position 32 in folder C. another example: folder D have position 34 in folder G and position 54 in folder R.
- each detail and folder need an image
- use postgesql
any other questions?
- Assistant