Group 1 and 2 metals can be made electrolytically by elecrtolysis of a halide salt in pyridine, lithium can be prepared by doing the same in amyl alcohol I have heard, although I have never tried this, for magnesium the best bet would probably be to fine a very low melting point eutectic salt mix and fuse it, then go electrolyse it from there.
You could probably reduce with Na maybe in a higher alcohol to get Mg, sodium an be electrolysed out of fused anhydrous NaOH, or better yet find a eutectic, I hear some of the gallium/sodium eutectics melt at an extremely low temperature, about 80 C or something like that
When isolating from fused NaOH, take care to keep the temperature almost EXACTLY the melting point of the hydroxide, do it on a hotplate, i've done it with an ordinary blowtorch because I don't currently have a hotplate and am too lazy to buy one
About 5-10 C above the melting point of NaOH, instead of metallic Na forming, a mettalloid alloy type material of Na dissolved in NaOH can be formed, but if done right, beads of metallic sodium will be formed that can be dug out of the NaOH with a bit of metal/knife or have a looped bit of wire dipped into them while molten, withdraw the wire and flick the beads of sodium into mineral oil for storage.
Eye protection and preferably gloves are a must, don't be scared of the pops and bangs of the beads of sodium that you arent quick enough to flick into oil, the electrolysis calms down somewhat after an initial few minutes