Add SQL to generate tables

This is just a quick pg_dump. Could really use a clean up, but it will preserve some of the magic views in case everything goes tits up.