|
35 | 35 | */ |
36 | 36 |
|
37 | 37 | use AdvisingApp\Interaction\Models\Interaction; |
38 | | -use AdvisingApp\Interaction\Models\InteractionDriver; |
39 | | -use App\Features\InteractableTypeFeature; |
40 | 38 | use Illuminate\Database\Migrations\Migration; |
41 | 39 | use Illuminate\Support\Collection; |
42 | 40 | use Illuminate\Support\Facades\DB; |
43 | | -use Illuminate\Support\Str; |
44 | 41 | use Tpetry\PostgresqlEnhanced\Schema\Blueprint; |
45 | 42 | use Tpetry\PostgresqlEnhanced\Support\Facades\Schema; |
46 | 43 |
|
@@ -82,201 +79,6 @@ public function up(): void |
82 | 79 | $table->string('interactable_type')->nullable(); |
83 | 80 | }); |
84 | 81 |
|
85 | | - // TODO: InteractableTypeFeature cleanup, remove this section (lines 82-173) |
86 | | - //Duplicate existing records and set as prospect type, set originals as student type |
87 | | - DB::table('interaction_statuses') |
88 | | - ->chunkById(100, function (Collection $interactionStatuses) { |
89 | | - foreach ($interactionStatuses as $interactionStatus) { |
90 | | - DB::table('interaction_statuses')->insert([ |
91 | | - 'id' => Str::orderedUuid(), |
92 | | - 'name' => $interactionStatus->name, |
93 | | - 'color' => $interactionStatus->color, |
94 | | - 'is_default' => $interactionStatus->is_default, |
95 | | - 'interactable_type' => 'prospect', |
96 | | - ]); |
97 | | - |
98 | | - DB::table('interaction_statuses') |
99 | | - ->where('id', $interactionStatus->id) |
100 | | - ->update(['interactable_type' => 'student']); |
101 | | - } |
102 | | - }); |
103 | | - |
104 | | - DB::table('interaction_types') |
105 | | - ->chunkById(100, function (Collection $interactionTypes) { |
106 | | - foreach ($interactionTypes as $interactionType) { |
107 | | - DB::table('interaction_types')->insert([ |
108 | | - 'id' => Str::orderedUuid(), |
109 | | - 'name' => $interactionType->name, |
110 | | - 'is_default' => $interactionType->is_default, |
111 | | - 'interactable_type' => 'prospect', |
112 | | - ]); |
113 | | - |
114 | | - DB::table('interaction_types') |
115 | | - ->where('id', $interactionType->id) |
116 | | - ->update(['interactable_type' => 'student']); |
117 | | - } |
118 | | - }); |
119 | | - |
120 | | - DB::table('interaction_outcomes') |
121 | | - ->chunkById(100, function (Collection $interactionOutcomes) { |
122 | | - foreach ($interactionOutcomes as $interactionOutcome) { |
123 | | - DB::table('interaction_outcomes')->insert([ |
124 | | - 'id' => Str::orderedUuid(), |
125 | | - 'name' => $interactionOutcome->name, |
126 | | - 'is_default' => $interactionOutcome->is_default, |
127 | | - 'interactable_type' => 'prospect', |
128 | | - ]); |
129 | | - |
130 | | - DB::table('interaction_outcomes') |
131 | | - ->where('id', $interactionOutcome->id) |
132 | | - ->update(['interactable_type' => 'student']); |
133 | | - } |
134 | | - }); |
135 | | - |
136 | | - DB::table('interaction_relations') |
137 | | - ->chunkById(100, function (Collection $interactionRelations) { |
138 | | - foreach ($interactionRelations as $interactionRelation) { |
139 | | - DB::table('interaction_relations')->insert([ |
140 | | - 'id' => Str::orderedUuid(), |
141 | | - 'name' => $interactionRelation->name, |
142 | | - 'is_default' => $interactionRelation->is_default, |
143 | | - 'interactable_type' => 'prospect', |
144 | | - ]); |
145 | | - |
146 | | - DB::table('interaction_relations') |
147 | | - ->where('id', $interactionRelation->id) |
148 | | - ->update(['interactable_type' => 'student']); |
149 | | - } |
150 | | - }); |
151 | | - |
152 | | - DB::table('interaction_drivers') |
153 | | - ->chunkById(100, function (Collection $interactionDrivers) { |
154 | | - foreach ($interactionDrivers as $interactionDriver) { |
155 | | - // There was a bug in interaction drivers where in a seeder we had accidentlly created duplicates for "Fast Track Certificates" |
156 | | - // This now needs to be addressed in order for the unique index to be applied properly later in this migration |
157 | | - $drivers = InteractionDriver::query()->where('name', 'Fast Track Certificates')->get(); |
158 | | - |
159 | | - if ($drivers->count() > 1) { |
160 | | - // Keep the first one, delete the rest |
161 | | - $keptDriver = $drivers->shift(); |
162 | | - |
163 | | - foreach ($drivers as $duplicateDriver) { |
164 | | - Interaction::query() |
165 | | - ->where('interaction_driver_id', $duplicateDriver->id) |
166 | | - ->update(['interaction_driver_id' => $keptDriver->id]); |
167 | | - |
168 | | - $duplicateDriver->forceDelete(); |
169 | | - } |
170 | | - } |
171 | | - |
172 | | - DB::table('interaction_drivers')->insert([ |
173 | | - 'id' => Str::orderedUuid(), |
174 | | - 'name' => $interactionDriver->name, |
175 | | - 'is_default' => $interactionDriver->is_default, |
176 | | - 'interactable_type' => 'prospect', |
177 | | - ]); |
178 | | - |
179 | | - DB::table('interaction_drivers') |
180 | | - ->where('id', $interactionDriver->id) |
181 | | - ->update(['interactable_type' => 'student']); |
182 | | - } |
183 | | - }); |
184 | | - |
185 | | - DB::table('interaction_initiatives') |
186 | | - ->chunkById(100, function (Collection $interactionInitiatives) { |
187 | | - foreach ($interactionInitiatives as $interactionInitiative) { |
188 | | - DB::table('interaction_initiatives')->insert([ |
189 | | - 'id' => Str::orderedUuid(), |
190 | | - 'name' => $interactionInitiative->name, |
191 | | - 'is_default' => $interactionInitiative->is_default, |
192 | | - 'interactable_type' => 'prospect', |
193 | | - ]); |
194 | | - |
195 | | - DB::table('interaction_initiatives') |
196 | | - ->where('id', $interactionInitiative->id) |
197 | | - ->update(['interactable_type' => 'student']); |
198 | | - } |
199 | | - }); |
200 | | - |
201 | | - // TODO: InteractableTypeFeature cleanup, remove this section (lines 175-252) |
202 | | - //Ensure interactions now have the correct foriegn key |
203 | | - DB::table('interactions') |
204 | | - ->chunkById(100, function (Collection $interactions) { |
205 | | - foreach ($interactions as $interaction) { |
206 | | - $interactionStatus = DB::table('interaction_statuses')->where('id', $interaction->interaction_status_id)->first(); |
207 | | - |
208 | | - if (! is_null($interactionStatus) && $interaction->interactable_type !== $interactionStatus->interactable_type) { |
209 | | - $newStatusId = DB::table('interaction_statuses') |
210 | | - ->where('name', $interactionStatus->name) |
211 | | - ->where('interactable_type', $interaction->interactable_type) |
212 | | - ->value('id'); |
213 | | - DB::table('interactions') |
214 | | - ->where('id', $interaction->id) |
215 | | - ->update(['interaction_status_id' => $newStatusId]); |
216 | | - } |
217 | | - |
218 | | - $interactionType = DB::table('interaction_types')->where('id', $interaction->interaction_type_id)->first(); |
219 | | - |
220 | | - if (! is_null($interactionType) && $interaction->interactable_type !== $interactionType->interactable_type) { |
221 | | - $newTypeId = DB::table('interaction_types') |
222 | | - ->where('name', $interactionType->name) |
223 | | - ->where('interactable_type', $interaction->interactable_type) |
224 | | - ->value('id'); |
225 | | - DB::table('interactions') |
226 | | - ->where('id', $interaction->id) |
227 | | - ->update(['interaction_type_id' => $newTypeId]); |
228 | | - } |
229 | | - |
230 | | - $interactionOutcome = DB::table('interaction_outcomes')->where('id', $interaction->interaction_outcome_id)->first(); |
231 | | - |
232 | | - if (! is_null($interactionOutcome) && $interaction->interactable_type !== $interactionOutcome->interactable_type) { |
233 | | - $newOutcomeId = DB::table('interaction_outcomes') |
234 | | - ->where('name', $interactionOutcome->name) |
235 | | - ->where('interactable_type', $interaction->interactable_type) |
236 | | - ->value('id'); |
237 | | - DB::table('interactions') |
238 | | - ->where('id', $interaction->id) |
239 | | - ->update(['interaction_outcome_id' => $newOutcomeId]); |
240 | | - } |
241 | | - |
242 | | - $interactionRelation = DB::table('interaction_relations')->where('id', $interaction->interaction_relation_id)->first(); |
243 | | - |
244 | | - if (! is_null($interactionRelation) && $interaction->interactable_type !== $interactionRelation->interactable_type) { |
245 | | - $newRelationId = DB::table('interaction_relations') |
246 | | - ->where('name', $interactionRelation->name) |
247 | | - ->where('interactable_type', $interaction->interactable_type) |
248 | | - ->value('id'); |
249 | | - DB::table('interactions') |
250 | | - ->where('id', $interaction->id) |
251 | | - ->update(['interaction_relation_id' => $newRelationId]); |
252 | | - } |
253 | | - |
254 | | - $interactionDriver = DB::table('interaction_drivers')->where('id', $interaction->interaction_driver_id)->first(); |
255 | | - |
256 | | - if (! is_null($interactionDriver) && $interaction->interactable_type !== $interactionDriver->interactable_type) { |
257 | | - $newDriverId = DB::table('interaction_drivers') |
258 | | - ->where('name', $interactionDriver->name) |
259 | | - ->where('interactable_type', $interaction->interactable_type) |
260 | | - ->value('id'); |
261 | | - DB::table('interactions') |
262 | | - ->where('id', $interaction->id) |
263 | | - ->update(['interaction_driver_id' => $newDriverId]); |
264 | | - } |
265 | | - |
266 | | - $interactionInitiative = DB::table('interaction_initiatives')->where('id', $interaction->interaction_initiative_id)->first(); |
267 | | - |
268 | | - if (! is_null($interactionInitiative) && $interaction->interactable_type !== $interactionInitiative->interactable_type) { |
269 | | - $newInitiativeId = DB::table('interaction_initiatives') |
270 | | - ->where('name', $interactionInitiative->name) |
271 | | - ->where('interactable_type', $interaction->interactable_type) |
272 | | - ->value('id'); |
273 | | - DB::table('interactions') |
274 | | - ->where('id', $interaction->id) |
275 | | - ->update(['interaction_initiative_id' => $newInitiativeId]); |
276 | | - } |
277 | | - } |
278 | | - }); |
279 | | - |
280 | 82 | //Make interactable_type non nullable, add unique index |
281 | 83 | Schema::table('interaction_statuses', function (Blueprint $table) { |
282 | 84 | $table->string('interactable_type')->nullable(false)->change(); |
@@ -337,8 +139,6 @@ public function up(): void |
337 | 139 | WHERE is_default = true AND deleted_at IS NULL; |
338 | 140 | '); |
339 | 141 | }); |
340 | | - |
341 | | - InteractableTypeFeature::activate(); |
342 | 142 | }); |
343 | 143 | } |
344 | 144 |
|
@@ -538,8 +338,6 @@ public function down(): void |
538 | 338 | $table->dropColumn('interactable_type'); |
539 | 339 | $table->unique('name'); |
540 | 340 | }); |
541 | | - |
542 | | - InteractableTypeFeature::deactivate(); |
543 | 341 | }); |
544 | 342 | } |
545 | 343 | }; |
0 commit comments