task/3382: Harmonisera tabellnamn #6

Merged
ansv7779 merged 104 commits from task/3382 into develop 2024-11-12 13:33:44 +01:00
2 changed files with 109 additions and 61 deletions
Showing only changes of commit 770d0aff31 - Show all commits

View File

@ -1,5 +1,7 @@
package se.su.dsv.scipro.match;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Table;
import se.su.dsv.scipro.activityplan.ActivityPlanTemplate;
import se.su.dsv.scipro.system.ProjectType;
@ -10,19 +12,23 @@ import jakarta.persistence.MapsId;
import java.io.Serializable;
@Entity
@Table(name = "application_period_project_type")
public class ApplicationPeriodProjectType implements Serializable {
@EmbeddedId
private ApplicationPeriodProjectTypeId applicationPeriodProjectTypeId = new ApplicationPeriodProjectTypeId();
@MapsId("applicationPeriodId")
@ManyToOne
@JoinColumn(name = "application_period_id")
private ApplicationPeriod applicationPeriod;
@MapsId("projectTypeId")
@ManyToOne
@JoinColumn(name = "project_type_id")
private ProjectType projectType;
@ManyToOne(optional = true)
@JoinColumn(name = "activity_plan_template_id")
private ActivityPlanTemplate activityPlanTemplate;
protected ApplicationPeriodProjectType() {}

View File

@ -424,7 +424,7 @@ alter table `general_system_settings_system_module` add primary key (general_sys
alter table `general_system_settings_system_module`
add constraint fk_general_system_settings_system_module_id
foreign key (general_system_settings_id) references general_system_settings(id)
foreign key (general_system_settings_id) references general_system_settings (id)
on delete cascade on update cascade;
-- table: general_system_settings_supervisor_change_recipient
@ -440,7 +440,7 @@ alter table `general_system_settings_supervisor_change_recipient` add primary ke
alter table `general_system_settings_supervisor_change_recipient`
add constraint fk_general_system_settings_supervisor_change_recipient_id
foreign key (general_system_settings_id) references general_system_settings(id)
foreign key (general_system_settings_id) references general_system_settings (id)
on delete cascade on update cascade;
-- table: general_system_settings_alarm_recipient
@ -456,7 +456,7 @@ alter table `general_system_settings_alarm_recipient` add primary key (general_s
alter table `general_system_settings_alarm_recipient`
add constraint fk_general_system_settings_alarm_recipient_id
foreign key (general_system_settings_id) references general_system_settings(id)
foreign key (general_system_settings_id) references general_system_settings (id)
on delete cascade on update cascade;
-- table: general_system_settings
@ -508,12 +508,12 @@ alter table `program` rename column `nameEn` to `name_en`;
alter table `user_program`
add constraint fk_user_program_program_id
foreign key (program_id) references program(id)
foreign key (program_id) references program (id)
on delete cascade on update cascade;
alter table `user_program`
add constraint fk_user_program_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: note
@ -523,7 +523,7 @@ alter table `note` drop key `user_id`;
alter table `note`
add constraint fk_note_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: comment and comment_thread
@ -546,12 +546,12 @@ alter table comment rename column `creator_id` to `user_id`;
alter table `comment`
add constraint fk_comment_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
alter table `comment`
add constraint fk_comment_comment_thread_id
foreign key (comment_thread_id) references comment_thread(id)
foreign key (comment_thread_id) references comment_thread (id)
on delete cascade on update cascade;
-- table: reviewer_target
@ -565,7 +565,7 @@ alter table `reviewer_target` add constraint uk_reviewer_target_user_id_year uni
alter table `reviewer_target`
add constraint fk_reviewer_target_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: notification_delivery_configuration
@ -578,7 +578,7 @@ alter table `notification_delivery_configuration` add constraint uk_one_setting_
alter table `notification_delivery_configuration`
add constraint fk_notification_delivery_configuration_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: username
@ -595,7 +595,7 @@ alter table `user_name` add constraint uk_user_name unique(user_name);
alter table `user_name`
add constraint fk_user_name_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: user_role
@ -604,7 +604,7 @@ alter table `user_role` drop foreign key `user_role_user_id`;
alter table `user_role`
add constraint fk_user_role_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: user_languages
@ -616,7 +616,7 @@ rename table `user_languages` to `user_language`;
alter table `user_language`
add constraint fk_user_language_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
/*
@ -655,7 +655,7 @@ alter table `unit` add constraint uk_unit_identifier unique(identifier);
alter table `user`
add constraint fk_user_unit_id
foreign key (unit_id) references unit(id)
foreign key (unit_id) references unit (id)
on delete cascade on update cascade;
-- table: Password
@ -674,14 +674,14 @@ create index idx_password_deleted on password(deleted);
alter table `password`
add constraint fk_password_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- add FK from user till password
alter table `user`
add constraint fk_user_password_id
foreign key (password_id) references password(id)
foreign key (password_id) references password (id)
on delete cascade on update cascade;
-- table: user_profile
@ -703,7 +703,7 @@ alter table `user_profile` add constraint uk_user_profile_user_id unique(user_id
alter table `user_profile`
add constraint fk_user_profile_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: user_profile_default_project_status_filter
@ -718,7 +718,7 @@ alter table `user_profile_default_project_status_filter` rename column `defaultP
alter table `user_profile_default_project_status_filter`
add constraint fk_user_profile_default_project_status_filter_user_profile_id
foreign key (user_profile_id) references user_profile(id)
foreign key (user_profile_id) references user_profile (id)
on delete cascade on update cascade;
-- table: user_profile_default_project_team_member_roles_filter
@ -733,7 +733,7 @@ alter table `user_profile_default_project_team_member_roles_filter` rename colum
alter table `user_profile_default_project_team_member_roles_filter`
add constraint fk_up_dp_tm_roles_filter_user_profile_id
foreign key (user_profile_id) references user_profile(id)
foreign key (user_profile_id) references user_profile (id)
on delete cascade on update cascade;
/*
@ -758,7 +758,7 @@ alter table `user_profile_project_type` rename column `defaultProjectTypeFilter_
alter table `user_profile_project_type`
add constraint fk_user_profile_project_type_user_profile_id
foreign key (user_profile_id) references user_profile(id)
foreign key (user_profile_id) references user_profile (id)
on delete cascade on update cascade;
-- table: ExternalResource, except foreign key to coming table project_type
@ -844,7 +844,7 @@ alter table `grading_criterion_template` rename column `gradingReportTemplate_id
alter table `grading_criterion_template`
add constraint fk_gct_grading_report_template_id
foreign key (grading_report_template_id) references grading_report_template(id)
foreign key (grading_report_template_id) references grading_report_template (id)
on delete cascade on update cascade;
/* >>> END: */
@ -868,7 +868,7 @@ alter table `grading_criterion_point_template` rename column `gradingCriterionTe
alter table `grading_criterion_point_template`
add constraint fk_gc_pt_grading_criterion_template_id
foreign key (grading_criterion_template_id) references grading_criterion_template(id)
foreign key (grading_criterion_template_id) references grading_criterion_template (id)
on delete cascade on update cascade;
/* >>> END: */
@ -888,7 +888,7 @@ alter table `checklist_template_project_type` add primary key (checklist_templat
alter table `checklist_template_project_type`
add constraint fk_ct_pt_checklist_template_id
foreign key (checklist_template_id) references checklist_template(id)
foreign key (checklist_template_id) references checklist_template (id)
on delete cascade on update cascade;
-- table: milestone_activity_template_ProjectType, except foreign key to coming table project_type
@ -907,7 +907,7 @@ alter table `milestone_activity_template_project_type` add primary key (`milesto
alter table `milestone_activity_template_project_type`
add constraint fk_ma_tpt_milestone_activity_template_id
foreign key (milestone_activity_template_id) references milestone_activity_template(id)
foreign key (milestone_activity_template_id) references milestone_activity_template (id)
on delete cascade on update cascade;
-- table: idea, we only remove foreign key from idea to ProjectType and rename the column projectType_id here.
@ -927,23 +927,25 @@ alter table `project` drop key `FKED904B19B2B6081F`;
alter table `project` rename column `projectType_id` to `project_type_id`;
/* >>> STACK PUSH
* table target, projectPartner and ApplicationPeriodProjectType has not only foreign key referencing table ProjectType,
* but also foreign key referencing table ApplicationPeriod. Table ApplicationPeriodProjectType references to
* ActivityPlanTemplate as well.
* Table ActivityTemplate, ActivityPlanTemplate, ApplicationPeriod using camel case naming convention,
* ApplicationPeriod has a related table, applicationperiodexemption, and they all need to
* fixed as well, before ProjectType can be fixed.
* Removal of foreign keys and renaming of columns and table name must be fixed in following order:
/*
* Table target, projectPartner and ApplicationPeriodProjectType has not only foreign key referencing table ProjectType,
* but also foreign key referencing table ApplicationPeriod. Table ApplicationPeriodProjectType references to
* ActivityPlanTemplate as well.
*
* 1. target, projectPartner, ApplicationPeriodProjectType
* 2. ActivityTemplate and ActivityPlanTemplate
* 3. ApplicationPeriod and applicationperiodexcemption
* Table ActivityTemplate, ActivityPlanTemplate, ApplicationPeriod using camel case naming convention,
* ApplicationPeriod has a related table, applicationperiodexemption, and they all need to
* fixed as well, before ProjectType can be fixed.
*
* Foreign keys will be then added in reverse order, it's like a stack pop.
* Removal of foreign keys and renaming of columns and table name must be fixed in following order:
*
* 1. target, projectPartner, ApplicationPeriodProjectType
* 2. ActivityTemplate and ActivityPlanTemplate
* 3. ApplicationPeriod and applicationperiodexcemption
*
* Foreign keys will be then added in reverse order, it's like a stack pop.
*/
-- 1st table group: target, projectPartner, ApplicationPeriodProjectType
-- >>> STACK PUSH: 1st table group: target, projectPartner, ApplicationPeriodProjectType
-- table: target, except foreign key to coming table project_type, and application_period
@ -961,7 +963,7 @@ alter table `target` add primary key (application_period_id, project_type_id, us
alter table `target`
add constraint fk_target_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: projectPartner, except foreign key to coming table project_type, and application_period
@ -981,19 +983,47 @@ alter table `project_partner` rename column `applicationPeriod_id` to `applicati
alter table `project_partner`
add constraint fk_project_partner_user_id
foreign key (user_id) references user(id)
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: ApplicationPeriodProjectType, except foreign key to coming table application_period, project_type and activity_plan_template.
alter table `ApplicationPeriodProjectType` drop foreign key `FK_hqebt63rl2mhogp66dy5m7upo`;
alter table `ApplicationPeriodProjectType` drop foreign key `FK_546usee339qh4g5otguwka3hi`;
alter table `ApplicationPeriodProjectType` drop foreign key `FK_3ku67jvegs1xxh8ykk023i7sb`;
alter table `ApplicationPeriodProjectType` drop key `FK_3ku67jvegs1xxh8ykk023i7sb`;
alter table `ApplicationPeriodProjectType` drop key `FK_546usee339qh4g5otguwka3hi`;
alter table `ApplicationPeriodProjectType` drop key `FK_hqebt63rl2mhogp66dy5m7upo`;
alter table `ApplicationPeriodProjectType` drop primary key;
rename table `ApplicationPeriodProjectType` to `application_period_project_type`;
alter table `application_period_project_type` rename column `applicationPeriod_id` to `application_period_id`;
alter table `application_period_project_type` rename column `projectType_id` to `project_type_id`;
alter table `application_period_project_type` rename column `activityPlanTemplate_id` to `activity_plan_template_id`;
alter table `application_period_project_type` add primary key (application_period_id, project_type_id);
/* Activate following later
-- **********************************************************************************
-- TODO: fix table ActivityPlanTemplate, verify no foreign keys are referenced to ActivityPlanTemplate before fix it
-- **********************************************************************************
-- **********************************************************************************
-- TODO: Add back all foreign key references to activity_plan_template
-- **********************************************************************************
-- add foreign key reference from application_period_project_type to activity_plan_template
alter table `application_period_project_type`
add constraint fk_ap_pt_activity_plan_template_id
foreign key (activity_plan_template_id) references activity_plan_template (id)
on delete cascade on update cascade;
-- **********************************************************************************
-- TODO: fix table ApplicationPeriod, verify no foreign keys are referenced to ApplicationPeriod before fix it
-- **********************************************************************************
@ -1003,16 +1033,22 @@ alter table `project_partner`
-- TODO: Add back all foreign key references to application_period
-- **********************************************************************************
-- add foreign key reference from application_period_project_type to application_period
alter table `application_period_project_type`
add constraint fk_ap_pt_application_period_id
foreign key (application_period_id) references application_period (id)
on delete cascade on update cascade;
-- add foreign key reference from project_partner to application_period
alter table `project_partner`
add constraint fk_project_partner_application_period_id
foreign key (application_period_id) references application_period(id)
foreign key (application_period_id) references application_period (id)
on delete cascade on update cascade;
-- add foreign key reference from target to application_period
alter table `target`
add constraint fk_target_application_period_id
foreign key (application_period_id) references application_period(id)
foreign key (application_period_id) references application_period (id)
on delete cascade on update cascade;
-- **********************************************************************************
@ -1024,95 +1060,101 @@ alter table `target`
-- TODO: Add back all foreign key references to project_type
-- **********************************************************************************
-- add foreign key reference from target to project_type
alter table `application_period_project_type`
add constraint fk_ap_pt_project_type_id
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from target to project_type
alter table `project_partner`
add constraint fk_project_partner_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from target to project_type
alter table `target`
add constraint fk_target_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from project to project_type
alter table `project`
add constraint fk_project_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from idea to project_type
alter table `idea`
add constraint fk_idea_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from milestone_activity_template_project_type to project_type
alter table `milestone_activity_template_project_type`
add constraint fk_ma_tpt_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from checklist_template_project_type to project_type
alter table `checklist_template_project_type`
add constraint fk_ct_pt_project_type_id
foreign key (fk_ct_pt_project_type_id) references project_type(id)
foreign key (fk_ct_pt_project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from grading_report_template to project_type
alter table `grading_report_template`
add constraint fk_grading_report_template_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from project_type_settings to project_type
alter table `project_type_settings`
add constraint fk_project_type_settings_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from project_type_project_module to project_type
alter table `project_type_project_module`
add constraint fk_project_type_project_module_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from external_resource to project_type
alter table `external_resource`
add constraint fk_external_resource_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
-- add foreign key reference from user_profile_project_type to project_type.
alter table `user_profile_project_type`
add constraint fk_user_profile_project_type_project_type_id
foreign key (project_type_id) references project_type(id)
foreign key (project_type_id) references project_type (id)
on delete cascade on update cascade;
*/
/* the mess with ProjectType
SQL query for FK-to:
>>> SQL query for FK-to:
select table_name, column_name, referenced_table_name, referenced_column_name
from key_column_usage
from information_schema.key_column_usage
where table_schema = 'tozh4728' and
referenced_table_name = 'ProjectType';
SQL query for FK-to count:
>>> SQL query for FK-to count:
select referenced_table_name, count(*) as c
from key_column_usage
from information_schema.key_column_usage
where table_schema = 'tozh4728' and
referenced_table_name is not null
group by referenced_table_name order by c desc;
SQL Query for FK-from
>>> SQL Query for FK-from
select table_name, column_name, referenced_table_name, referenced_column_name
from key_column_usage
where referenced_table_name is not null and table_name = 'user'
select table_name, column_name, referenced_table_name, referenced_column_name
from information_schema.key_column_usage
where referenced_table_name is not null and table_name = 'user'
order by table_name;