1+ <?php
2+ /**
3+ * Copyright 2018 OpenStack Foundation
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ * Unless required by applicable law or agreed to in writing, software
9+ * distributed under the License is distributed on an "AS IS" BASIS,
10+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ * See the License for the specific language governing permissions and
12+ * limitations under the License.
13+ **/
14+
15+ class AddOnDeleteCascadeFKPromoCodesMigration extends AbstractDBMigrationTask
16+ {
17+ protected $ title = "AddOnDeleteCascadeFKPromoCodesMigration " ;
18+
19+ protected $ description = "AddOnDeleteCascadeFKPromoCodesMigration " ;
20+
21+ function doUp ()
22+ {
23+ global $ database ;
24+
25+ $ res = DB ::query ("DELETE FROM MemberSummitRegistrationPromoCode
26+ WHERE ID not in (select ID from SummitRegistrationPromoCode); " )->value ();
27+
28+ $ res = DB ::query ("ALTER TABLE MemberSummitRegistrationPromoCode
29+ ADD CONSTRAINT FK_MemberSummitRegistrationPromoCode_SummitRegistrationPromoCode
30+ FOREIGN KEY (ID) REFERENCES SummitRegistrationPromoCode(ID) ON DELETE CASCADE; " )->value ();
31+
32+ $ res = DB ::query ("delete from SponsorSummitRegistrationPromoCode
33+ where ID not in (select ID from MemberSummitRegistrationPromoCode); " )->value ();
34+
35+ $ res = DB ::query ("ALTER TABLE SponsorSummitRegistrationPromoCode
36+ ADD CONSTRAINT FK_Sponsor_Member_PromoCode
37+ FOREIGN KEY (ID) REFERENCES MemberSummitRegistrationPromoCode(ID) ON DELETE CASCADE; " )->value ();
38+
39+ $ res = DB ::query ("delete from SpeakerSummitRegistrationPromoCode
40+ where ID not in (select ID from SummitRegistrationPromoCode); " )->value ();
41+
42+ $ res = DB ::query ("ALTER TABLE SpeakerSummitRegistrationPromoCode
43+ ADD CONSTRAINT FK_Speaker_PromoCode
44+ FOREIGN KEY (ID) REFERENCES SummitRegistrationPromoCode(ID) ON DELETE CASCADE; " )->value ();
45+ }
46+
47+ function doDown ()
48+ {
49+
50+ }
51+
52+ }
0 commit comments