insights: migrate code insights queue to the codeinsights database
Created by: coury-clark
Currently, code insights interacts with two databases, the primary postgres and the code insights database. The primary postgres database is used for a few things:
- Interacting with user, org, repository, and other general Sourcegraph data
- Storing a queue for the code insights background workers
For architectural purposes, we should simplify the interactions with the primary postgres database and migrate the queue to the code insights database. This will allow us to do things such as:
- Transactional operations across queue and metadata tables
- Simplify code paths by allowing joins at the table level instead of the application level
- More independence of code insights as a feature on independently scalable infrastructure
This would also set up an architectural divide where many of the remaining of the interactions with the primary postgres database could be migrated to API calls if needed.
Since the code insights database currently runs on a Postgres compatible instance, the tables should be immediately transferrable. The only question then is how do we perform a seamless transition to the new database:
- Manually copy over remaining data? No thanks!
- Create an out of band migration to move records from the old DB to the new?
- Read and execute queries from both queues until the queue on primary postgres is drained?
I think option 2 will be the best, to ensure we can deprecate by a specific version.