adding new sql ddl and fixes to the code to reflect new db moedl