db-constraint while syncing,improving the code