BEGIN;

-- CREATE TABLE "appointment_group" ----------------------------
CREATE TABLE "public"."appointment_group" ( 
	"fecha_creacion" Timestamp With Time Zone NOT NULL,
	"user_group" Integer NOT NULL,
	"id_room_appointment_study_receipt" UUid NOT NULL,
	"id_appointment_group" Integer NOT NULL,
	"id_data_group" Integer NOT NULL,
	"appointment_code" Character Varying( 10 ) COLLATE "pg_catalog"."default" NOT NULL,
	PRIMARY KEY ( "id_data_group" ),
	CONSTRAINT "unique_appointment_group_appointment_code" UNIQUE( "appointment_code" ) );
 ;
-- -------------------------------------------------------------

-- CREATE INDEX "index_id_group" -------------------------------
CREATE INDEX "index_id_group" ON "public"."appointment_group" USING btree( "id_data_group" Asc NULLS Last );
-- -------------------------------------------------------------

COMMIT;

BEGIN;

-- CREATE LINK "lnk_user_sonata_group" -------------------------
ALTER TABLE "public"."appointment_group"
	ADD CONSTRAINT "lnk_user_sonata_group" FOREIGN KEY ( "user_group" )
	REFERENCES "public"."user_sonata" ( "id" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

COMMIT;

BEGIN;

-- CREATE LINK "lnk_room_appointment_study_receipt_appointment_group" 
ALTER TABLE "public"."appointment_group"
	ADD CONSTRAINT "lnk_room_appointment_study_receipt_appointment_group" FOREIGN KEY ( "id_room_appointment_study_receipt" )
	REFERENCES "public"."room_appointment_study_receipt" ( "id_room_appointment_study_receipt" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

COMMIT;

BEGIN;

-- CREATE LINK "lnk_appointment_appointment_group" -------------
ALTER TABLE "public"."appointment_group"
	ADD CONSTRAINT "lnk_appointment_appointment_group" FOREIGN KEY ( "appointment_code" )
	REFERENCES "public"."appointment" ( "appointment_code" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

COMMIT;