From 2149bb7fb6b6f732ac8364e45d072a22921957db Mon Sep 17 00:00:00 2001 From: Max Magorsch Date: Mon, 22 Jun 2020 00:45:14 +0000 Subject: Rework the data model to improve the performance Signed-off-by: Max Magorsch --- pkg/database/connection.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'pkg/database') diff --git a/pkg/database/connection.go b/pkg/database/connection.go index 18fa2e6..06514df 100644 --- a/pkg/database/connection.go +++ b/pkg/database/connection.go @@ -21,9 +21,16 @@ var ( func CreateSchema() error { if !tableExists("messages") { - err := DBCon.CreateTable((*models.Message)(nil), &orm.CreateTableOptions{ - IfNotExists: true, - }) + for _, model := range []interface{}{(*models.Message)(nil), + (*models.MessageToReferences)(nil)} { + + err := DBCon.CreateTable(model, &orm.CreateTableOptions{ + IfNotExists: true, + }) + if err != nil { + return err + } + } // Add tsvector column for subjects DBCon.Exec("ALTER TABLE messages ADD COLUMN tsv_subject tsvector;") @@ -33,7 +40,7 @@ func CreateSchema() error { DBCon.Exec("ALTER TABLE messages ADD COLUMN tsv_body tsvector;") DBCon.Exec("CREATE INDEX body_idx ON messages USING gin(tsv_body);") - return err + return nil } return nil } -- cgit v1.2.3-18-g5258