Messages table fixes to improve query performance (#2026)

* Move to yaml sqlc config

* Add util for ungraceful sql execs

* Fix messages schema + add indexes

* Add migration to drop+recreate messages table

* Create index only if does not exist

* Fix typo

* Unexport function
This commit is contained in:
Gabe Kangas
2022-08-03 10:21:55 -07:00
committed by GitHub
parent 0b5ddf433b
commit eda62a91dc
6 changed files with 53 additions and 28 deletions

View File

@ -29,6 +29,8 @@ func migrateDatabaseSchema(db *sql.DB, from, to int) error {
migrateToSchema4(db)
case 4:
migrateToSchema5(db)
case 5:
migrateToSchema6(db)
default:
log.Fatalln("missing database migration step")
}
@ -42,6 +44,16 @@ func migrateDatabaseSchema(db *sql.DB, from, to int) error {
return nil
}
func migrateToSchema6(db *sql.DB) {
// Fix chat messages table schema. Since chat is ephemeral we can drop
// the table and recreate it.
// Drop the old messages table
mustExec(`DROP TABLE messages`, db)
// Recreate it
CreateMessagesTable(db)
}
// nolint:cyclop
func migrateToSchema5(db *sql.DB) {
// Create the access tokens table.