db->tableExists('configuration')) { return; } $schoolYearStart = $this->configValue('school_year_start_date'); if ($schoolYearStart === null || $schoolYearStart === '') { return; } $this->upsertConfigValue('fall_semester_start', $schoolYearStart); } public function down(): void { } private function configValue(string $key): ?string { $row = $this->db->table('configuration') ->select('config_value') ->where('config_key', $key) ->orderBy('id', 'DESC') ->get(1) ->getRowArray(); return $row ? (string) $row['config_value'] : null; } private function upsertConfigValue(string $key, string $value): void { $exists = $this->db->table('configuration') ->select('id') ->where('config_key', $key) ->get(1) ->getRowArray(); if ($exists) { $this->db->table('configuration') ->where('config_key', $key) ->update(['config_value' => $value]); return; } $this->db->table('configuration')->insert([ 'config_key' => $key, 'config_value' => $value, ]); } }