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

@ -927,13 +927,15 @@ 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,
/*
* 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:
*
* 1. target, projectPartner, ApplicationPeriodProjectType
@ -943,7 +945,7 @@ alter table `project` rename column `projectType_id` to `project_type_id`;
* 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
@ -984,16 +986,44 @@ alter table `project_partner`
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,6 +1033,12 @@ 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
@ -1024,6 +1060,12 @@ 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
@ -1094,24 +1136,24 @@ alter table `user_profile_project_type`
/* 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
from information_schema.key_column_usage
where referenced_table_name is not null and table_name = 'user'
order by table_name;