use score;
-- Rename the "learning_blocks_links" table to "links"
RENAME TABLE learning_blocks_links TO links;
-- Add  circularChallengesId into table "links" with relations
ALTER TABLE links
ADD COLUMN  circularChallengesId INT NULL,
ADD CONSTRAINT FK_0de6f9bd8e3dd90aa284d516097
FOREIGN KEY (circularChallengesId) 
REFERENCES circular_challenges(id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE links MODIFY learningBlockId INT NULL;
ALTER TABLE links
ADD CONSTRAINT FK_0de6f9bd8e3dd90aa284d51609l
FOREIGN KEY (circularChallengesId)
REFERENCES circular_challenges(id)
ON DELETE CASCADE ON UPDATE CASCADE;

-- Add  circular_challenges_files 
ALTER TABLE circular_challenges
DROP FOREIGN KEY FK_2c0da7cc9e31579548fabd94f3b;


CREATE TABLE circular_challenges_files (circularChallenges_id int NOT NULL,
 files_id int NOT NULL,
INDEX IDX_9ccddfba3235172ed1dd69266b (circularChallenges_id), 
INDEX IDX_9f51bfce3b36bd999341ec606d (files_id), PRIMARY KEY (circularChallenges_id, files_id));
 
ALTER TABLE circular_challenges_files ADD CONSTRAINT FK_9ccddfba3235172ed1dd69266bc FOREIGN KEY (circularChallenges_id) REFERENCES circular_challenges(id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE circular_challenges_files ADD CONSTRAINT FK_9f51bfce3b36bd999341ec606db FOREIGN KEY (files_id) REFERENCES files(id) ON DELETE CASCADE ON UPDATE CASCADE;
-- Add  learning_blocks_student_objectives 
CREATE TABLE learning_blocks_student_objectives 
(id int NOT NULL AUTO_INCREMENT, description varchar(255) NOT NULL, numStudent varchar(255) NOT NULL, learningBlocksId int NOT NULL, PRIMARY KEY (id));
ALTER TABLE learning_blocks_student_objectives ADD CONSTRAINT FK_df3743253c3516d64861a822834 FOREIGN KEY (learningBlocksId) REFERENCES learning_blocks(id) ON DELETE CASCADE ON UPDATE CASCADE;
 
-- Add  circular_economy_videos 
CREATE TABLE circular_economy_videos (
    id int NOT NULL AUTO_INCREMENT,
    videoUrl text NOT NULL,
    videoDescription text NOT NULL,
    circularEconomyId int NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (circularEconomyId) REFERENCES circular_economy(id)); 
    
    ALTER TABLE circular_economy_videos ADD CONSTRAINT FK_a36e9c3304cd3c8641aca958644
    FOREIGN KEY (circularEconomyId) REFERENCES circular_economy(id) ON DELETE CASCADE ON UPDATE CASCADE;