Unless this action due to some form of legally actionable discrimination (i.e. was based on your race, religion, disability, gender, nationality, age, etc.), and your demotion did not violate the terms of an employment contract or union agreement, than it was legal. The fact is that in an "at will" work relationship a company can promote/demote and do anything else that it sees fit. Bottom line, you could be demoted for any reason or no reason at all, with or without notice.