Merge pull request #1 from shackbarth/keith1
[xtuple] / foundation-database / public / patches / fixflcol.sql
1 -- 4.4.1 and 4.5.0 fix - synchronize flcol_report_id
2 do $$
3 begin
4 if fetchMetricText('ServerVersion') < '4.6.0' then
5
6 update flcol set flcol_report_id = (select report_id from report
7                                     where report_name = 'FinancialReport'
8                                     order by report_grade desc
9                                     limit 1)
10 where flcol_report_id=285
11 and flcol_id in (
12   select flcol_id
13   from flcol left join report on flcol_report_id = report_id
14   where report_id is null)
15 ;
16
17 update flcol set flcol_report_id = (select report_id from report
18                                     where report_name = 'FinancialReportMonth'
19                                     order by report_grade desc
20                                     limit 1)
21 where flcol_report_id in (375, 335)
22 and flcol_id in (
23   select flcol_id
24   from flcol left join report on flcol_report_id = report_id
25   where report_id is null)
26 ;
27
28 update flcol set flcol_report_id = (select report_id from report
29                                     where report_name = 'FinancialReportMonthBudget'
30                                     order by report_grade desc
31                                     limit 1)
32 where flcol_report_id in (376, 336)
33 and flcol_id in (
34   select flcol_id
35   from flcol left join report on flcol_report_id = report_id
36   where report_id is null)
37 ;
38
39 update flcol set flcol_report_id = (select report_id from report
40                                     where report_name = 'FinancialReportMonthDbCr'
41                                     order by report_grade desc
42                                     limit 1)
43 where flcol_report_id=387
44 and flcol_id in (
45   select flcol_id
46   from flcol left join report on flcol_report_id = report_id
47   where report_id is null)
48 ;
49
50 update flcol set flcol_report_id = (select report_id from report
51                                     where report_name = 'FinancialReportMonthPriorMonth'
52                                     order by report_grade desc
53                                     limit 1)
54 where flcol_report_id in (377, 337)
55 and flcol_id in (
56   select flcol_id
57   from flcol left join report on flcol_report_id = report_id
58   where report_id is null)
59 ;
60
61 update flcol set flcol_report_id = (select report_id from report
62                                     where report_name = 'FinancialReportMonthPriorQuarter'
63                                     order by report_grade desc
64                                     limit 1)
65 where flcol_report_id in (386, 346)
66 and flcol_id in (
67   select flcol_id
68   from flcol left join report on flcol_report_id = report_id
69   where report_id is null)
70 ;
71
72 update flcol set flcol_report_id = (select report_id from report
73                                     where report_name = 'FinancialReportMonthPriorYear'
74                                     order by report_grade desc
75                                     limit 1)
76 where flcol_report_id in (378, 338)
77 and flcol_id in (
78   select flcol_id
79   from flcol left join report on flcol_report_id = report_id
80   where report_id is null)
81 ;
82
83 update flcol set flcol_report_id = (select report_id from report
84                                     where report_name = 'FinancialReportMonthQuarter'
85                                     order by report_grade desc
86                                     limit 1)
87 where flcol_report_id in (379, 339)
88 and flcol_id in (
89   select flcol_id
90   from flcol left join report on flcol_report_id = report_id
91   where report_id is null)
92 ;
93
94 update flcol set flcol_report_id = (select report_id from report
95                                     where report_name = 'FinancialReportMonthYear'
96                                     order by report_grade desc
97                                     limit 1)
98 where flcol_report_id in (374, 334)
99 and flcol_id in (
100   select flcol_id
101   from flcol left join report on flcol_report_id = report_id
102   where report_id is null)
103 ;
104
105 update flcol set flcol_report_id = (select report_id from report
106                                     where report_name = 'FinancialReportQuarter'
107                                     order by report_grade desc
108                                     limit 1)
109 where flcol_report_id in (380, 340)
110 and flcol_id in (
111   select flcol_id
112   from flcol left join report on flcol_report_id = report_id
113   where report_id is null)
114 ;
115
116 update flcol set flcol_report_id = (select report_id from report
117                                     where report_name = 'FinancialReportQuarterBudget'
118                                     order by report_grade desc
119                                     limit 1)
120 where flcol_report_id in (381, 341)
121 and flcol_id in (
122   select flcol_id
123   from flcol left join report on flcol_report_id = report_id
124   where report_id is null)
125 ;
126
127 update flcol set flcol_report_id = (select report_id from report
128                                     where report_name = 'FinancialReportQuarterPriorQuarter'
129                                     order by report_grade desc
130                                     limit 1)
131 where flcol_report_id in (382, 342)
132 and flcol_id in (
133   select flcol_id
134   from flcol left join report on flcol_report_id = report_id
135   where report_id is null)
136 ;
137
138 update flcol set flcol_report_id = (select report_id from report
139                                     where report_name = 'FinancialReportYear'
140                                     order by report_grade desc
141                                     limit 1)
142 where flcol_report_id in (383, 343)
143 and flcol_id in (
144   select flcol_id
145   from flcol left join report on flcol_report_id = report_id
146   where report_id is null)
147 ;
148
149 update flcol set flcol_report_id = (select report_id from report
150                                     where report_name = 'FinancialReportYearBudget'
151                                     order by report_grade desc
152                                     limit 1)
153 where flcol_report_id in (384, 344)
154 and flcol_id in (
155   select flcol_id
156   from flcol left join report on flcol_report_id = report_id
157   where report_id is null)
158 ;
159
160 update flcol set flcol_report_id = (select report_id from report
161                                     where report_name = 'FinancialReportYearPriorYear'
162                                     order by report_grade desc
163                                     limit 1)
164 where flcol_report_id in (385, 345)
165 and flcol_id in (
166   select flcol_id
167   from flcol left join report on flcol_report_id = report_id
168   where report_id is null)
169 ;
170
171 update flcol set flcol_report_id = (select report_id from report
172                                     where report_name = 'FinancialTrend'
173                                     order by report_grade desc
174                                     limit 1)
175 where flcol_report_id=388
176 and flcol_id in (
177   select flcol_id
178   from flcol left join report on flcol_report_id = report_id
179   where report_id is null)
180 ;
181
182 end if;
183 end$$;