aboutsummaryrefslogtreecommitdiffstats
path: root/mayor-orig/mayor-naplo/update/pre002483-2-naplo.sql
blob: dfb24919890dd79bedf225892f7a9ee2814d62be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- drop existing key and columns
drop procedure if exists drop_column;
delimiter ';;'
create procedure drop_column() 
begin 
    if exists (select * from information_schema.table_constraints where table_schema=database() and table_name = 'bejegyzes' and constraint_name='bejegyzes_ibfk_3') then
	alter table `bejegyzes` drop foreign key `bejegyzes_ibfk_3`;
    end if; 
    if exists (select * from information_schema.columns where table_schema = database() and table_name = 'bejegyzes' and column_name = 'bejegyzesTipusId') then 
	alter table `bejegyzes` drop column `bejegyzesTipusId`;
    end if; 
    if exists (select * from information_schema.columns where table_schema = database() and table_name = 'bejegyzes' and column_name = 'hianyzasDb') then 
	alter table `bejegyzes` drop column `hianyzasDb`;
    end if; 
end;;
delimiter ';'
call drop_column();

-- alter table bejegyzes (add column)
alter table `bejegyzes` add column `bejegyzesTipusId` tinyint(3) unsigned;
alter table `bejegyzes` add column `hianyzasDb` tinyint(3) unsigned DEFAULT NULL;

-- update bejegyzes
update `bejegyzes` left join `%INTEZMENYDB%`.`bejegyzesTipus` 
on `bejegyzes`.`tipus`=`bejegyzesTipus`.`tipus` and (`bejegyzes`.`fokozat`=`bejegyzesTipus`.`fokozat` or `bejegyzes`.`tipus`='üzenet')
set `bejegyzes`.`bejegyzesTipusId`=`bejegyzesTipus`.`bejegyzesTipusId`;

-- Még nincsenek a bejegyzesTipus táblában beállítva a hianyzasDb értékek
-- -- update `bejegyzes` left join `%INTEZMENYDB%`.`bejegyzesTipus` using (`bejegyzesTipusId`) 
-- --    set `bejegyzes`.`hianyzasDb`=`bejegyzesTipus`.`hianyzasDb` where `szoveg`='Igazolatlan hiányzás';
-- Ezért fix 1-re állítjuk (hogy pozitív legyen - látszik, hogy hiányzásért kapta)
update `bejegyzes` left join `%INTEZMENYDB%`.`bejegyzesTipus` using (`bejegyzesTipusId`) 
    set `bejegyzes`.`hianyzasDb`=1 where `szoveg`='Igazolatlan hiányzás' and `bejegyzes`.`tipus`='fegyelmi';

-- alter table bejegyzes (drop column)
alter table `bejegyzes` drop column `fokozat`;
alter table `bejegyzes` drop column `tipus`;
alter table `bejegyzes` modify `bejegyzesTipusId` tinyint(3) unsigned NOT NULL;
alter table `bejegyzes` ADD FOREIGN KEY `bejegyzes_ibfk_3` (`bejegyzesTipusId`) 
    REFERENCES `%INTEZMENYDB%`.`bejegyzesTipus` (`bejegyzesTipusId`) ON DELETE NO ACTION ON UPDATE CASCADE;