-- CREATE TABLE "attributes" -----------------------------------
CREATE TABLE "public"."attributes" ( 
	"id" Serial NOT NULL,
	"name" Character Varying( 255 ) NOT NULL,
	"value" Character Varying( 255 ) NOT NULL,
	PRIMARY KEY ( "id" ) );
 ;
-- -------------------------------------------------------------

-- CREATE FIELD "brand_id" -------------------------------------
ALTER TABLE "public"."attributes" ADD COLUMN "brand_id" Integer;
-- -------------------------------------------------------------

-- CREATE FIELD "model_id" -------------------------------------
ALTER TABLE "public"."attributes" ADD COLUMN "model_id" Integer;
-- -------------------------------------------------------------

-- CREATE INDEX "index_brand_id" -------------------------------
CREATE INDEX "index_brand_id" ON "public"."attributes" USING btree( "brand_id" );
-- -------------------------------------------------------------

-- CREATE INDEX "index_model_id" -------------------------------
CREATE INDEX "index_model_id" ON "public"."attributes" USING btree( "model_id" );
-- -------------------------------------------------------------

-- CREATE LINK "public.attributes.lnk_brand_attributes" --------
ALTER TABLE "public"."attributes"
	ADD CONSTRAINT "lnk_brand_attributes" FOREIGN KEY ( "brand_id" )
	REFERENCES "public"."brand" ( "id" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE LINK "public.attributes.lnk_model_attributes" --------
ALTER TABLE "public"."attributes"
	ADD CONSTRAINT "lnk_model_attributes" FOREIGN KEY ( "model_id" )
	REFERENCES "public"."model" ( "id" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE FIELD "is_default" -----------------------------------
ALTER TABLE "public"."brand" ADD COLUMN "is_default" Boolean DEFAULT false NOT NULL;
-- -------------------------------------------------------------