When I got laid off at Microsoft in 2014 I thought it was the worst thing that happened to me. I had to learn some tough lessons, especially that it is a business and any personal feelings about the quality of work or how invaluable you thought you were dont matter. It's just business. It was a wakeup call. Jobs are no longer careers. they are stints. they aren't even a ladder, they're more like a web where you may move from gig to gig based on what SKILL YOU WANT TO LEARN and some moves may be lateral and not up.
You should have an education plan that happens regardless of if you have a job or not. even if you are attending one class. LEARN NEW SKILLS based off of what YOU want to learn, not what some job description wants of you. doing the same thing for 5 years makes you stale and a big target. build your portfolio up and don't be scared. rebuild yourself, be flexible. Be curious. Have fun exploring new skills and do this regardless of your employment status.
Be sure to update your resume every 6 months with the new things you've learned. always network.
The outcome of this will be that lots of people will get fired, and then the positions you held will be filled again by 1/10th of the staff with a hybrid skillset between yours and what the company wants from now on and that staff will be made of VENDORS.
They wont bother retraining you because you are too expensive to keep. So all of the things you thought you were doing right, or thinking that you were indispensable or irreplaceable doesn't matter. Its just business. YOU WERE JUST ON THE WRONG SIDE OF A SQL QUERY.
Dont take it hard. Get back in the game. You have endless possibilities. its not a career ladder with a 'top' or 'finish'. there is no retirement. Its more like a web, or a rock wall that you navigate. Some moves are back, or lateral, or small steps. Each step should be a path you take based on the skills you want to learn. Training for a job position is silly now a days. Train for skills that interest you and ALWAYS keep learning <3 You can do it. Now get out there and kick a--.