refactor sqlite table rebuilding