-- CREATE TABLE "blocks" ---------------------------------------
CREATE TABLE "public"."blocks" ( 
	"id" Serial NOT NULL,
	"title" Character Varying DEFAULT '255' NOT NULL,
	"key" Character Varying( 255 ) NOT NULL,
	PRIMARY KEY ( "id" ) );
 ;
-- -------------------------------------------------------------

-- CREATE FIELD "days" -----------------------------------------
ALTER TABLE "public"."blocks" ADD COLUMN "days" Integer;
-- -------------------------------------------------------------

-- CREATE FIELD "promotions_id" --------------------------------
ALTER TABLE "public"."blocks" ADD COLUMN "promotions_id" Integer NOT NULL;
-- -------------------------------------------------------------

-- CREATE INDEX "index_promotions_blocks_id" -------------------
CREATE INDEX "index_promotions_blocks_id" ON "public"."blocks" USING btree( "promotions_id" );
-- -------------------------------------------------------------

-- CREATE LINK "public.blocks.lnk_promotions_blocks" -----------
ALTER TABLE "public"."blocks"
	ADD CONSTRAINT "lnk_promotions_blocks" FOREIGN KEY ( "promotions_id" )
	REFERENCES "public"."promotions" ( "id" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE TABLE "block_items" ----------------------------------
CREATE TABLE "public"."block_items" ( 
	"id" Serial NOT NULL,
	"number" Integer NOT NULL,
	"customize_speed" Boolean DEFAULT false NOT NULL,
	"customize_data" Boolean DEFAULT false NOT NULL,
	"configure_speed_multiplier" Boolean DEFAULT false NOT NULL,
	"configure_data_multiplier" Boolean DEFAULT false NOT NULL,
	"speed_up" Integer,
	"speed_down" Integer,
	"download_limit" Integer,
	"speed_multiplier" Numeric( 5, 2 ),
	"data_multiplier" Numeric( 5, 2 ),
	PRIMARY KEY ( "id" ) );
 ;
-- -------------------------------------------------------------

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

-- CREATE FIELD "blocks_id" ------------------------------------
ALTER TABLE "public"."block_items" ADD COLUMN "blocks_id" Integer NOT NULL;
-- -------------------------------------------------------------

-- CREATE INDEX "index_blocks_id" ------------------------------
CREATE INDEX "index_blocks_id" ON "public"."block_items" USING btree( "blocks_id" );
-- -------------------------------------------------------------

-- CREATE LINK "public.block_items.lnk_blocks_block_items" -----
ALTER TABLE "public"."block_items"
	ADD CONSTRAINT "lnk_blocks_block_items" FOREIGN KEY ( "blocks_id" )
	REFERENCES "public"."blocks" ( "id" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------


-- CREATE TABLE "generated_intervals" --------------------------
CREATE TABLE "public"."generated_intervals" ( 
	"id" Serial NOT NULL,
	"start_date" Timestamp Without Time Zone NOT NULL,
	"end_date" Timestamp Without Time Zone NOT NULL,
	"speed_up" Integer NOT NULL,
	"speed_down" Integer NOT NULL,
	PRIMARY KEY ( "id" ) );
 ;
-- -------------------------------------------------------------

-- CREATE FIELD "status" ---------------------------------------
ALTER TABLE "public"."generated_intervals" ADD COLUMN "status" Integer NOT NULL;
-- -------------------------------------------------------------

-- CREATE FIELD "assigned_promotions_id" -----------------------
ALTER TABLE "public"."generated_intervals" ADD COLUMN "assigned_promotions_id" Integer NOT NULL;
-- -------------------------------------------------------------

-- CREATE INDEX "index_assigned_promotions_id" -----------------
CREATE INDEX "index_assigned_promotions_id" ON "public"."generated_intervals" USING btree( "assigned_promotions_id" );
-- -------------------------------------------------------------


-- CREATE LINK "public.generated_intervals.lnk_assigned_promotions_generated_intervals" 
ALTER TABLE "public"."generated_intervals"
	ADD CONSTRAINT "lnk_assigned_promotions_generated_intervals" FOREIGN KEY ( "assigned_promotions_id" )
	REFERENCES "public"."assigned_promotions" ( "id" ) MATCH FULL
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------


-- CREATE TABLE "todo" -----------------------------------------
CREATE TABLE "public"."todo" ( 
	"id" Serial NOT NULL,
	"code" Character Varying( 255 ) NOT NULL,
	"status" Integer NOT NULL,
	PRIMARY KEY ( "id" ) );
 ;
-- -------------------------------------------------------------

-- CREATE FIELD "device" ---------------------------------------
ALTER TABLE "public"."todo" ADD COLUMN "device" Character Varying( 36 );
-- -------------------------------------------------------------

-- CREATE FIELD "recharge" -------------------------------------
ALTER TABLE "public"."todo" ADD COLUMN "recharge" Character Varying( 36 );
-- -------------------------------------------------------------

-- CREATE FIELD "created_at" -----------------------------------
ALTER TABLE "public"."todo" ADD COLUMN "created_at" Timestamp Without Time Zone NOT NULL;
-- -------------------------------------------------------------

-- CREATE FIELD "executed_at" ----------------------------------
ALTER TABLE "public"."todo" ADD COLUMN "executed_at" Timestamp Without Time Zone;
-- -------------------------------------------------------------