From 0ff7a864ec0c576b76a6846e70bb5bc0082f0250 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Mon, 15 Feb 2021 23:18:08 +0000 Subject: [PATCH] Attempting to resolved 'no such column: profile_pictures_show_to' Have resolved the settings table not found but now the column is not migrating for some reason --- multiaccounts/accounts/database.go | 2 +- protocol/messenger.go | 14 ++++++++++++++ protocol/messenger_config.go | 11 +++++++++++ protocol/messenger_test.go | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/multiaccounts/accounts/database.go b/multiaccounts/accounts/database.go index 7d8bb34e0..b750479be 100644 --- a/multiaccounts/accounts/database.go +++ b/multiaccounts/accounts/database.go @@ -380,7 +380,7 @@ func (db *Database) SaveSetting(setting string, value interface{}) error { update, err = db.db.Prepare("UPDATE settings SET wallet_visible_tokens = ? WHERE synthetic_id = 'id'") case "appearance": update, err = db.db.Prepare("UPDATE settings SET appearance = ? WHERE synthetic_id = 'id'") - case "profile_pictures_show_to": + case "profile-pictures-show-to": update, err = db.db.Prepare("UPDATE settings SET profile_pictures_show_to = ? WHERE synthetic_id = 'id'") case "profile-pictures-visibility": update, err = db.db.Prepare("UPDATE settings SET profile_pictures_visibility = ? WHERE synthetic_id = 'id'") diff --git a/protocol/messenger.go b/protocol/messenger.go index 69448a572..c03b1508b 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -201,6 +201,14 @@ func NewMessenger( } } + // Apply any post database creation changes to the database + c.db = database + for _, opt := range c.afterDbCreatedHooks { + if err := opt(&c); err != nil { + return nil, err + } + } + // Apply migrations for all components. err := sqlite.Migrate(database) if err != nil { @@ -776,6 +784,12 @@ func (m *Messenger) attachIdentityImagesToChatIdentity(context chatContext, ci * return err } + if s.ProfilePicturesVisibility == accounts.ProfilePicturesVisibilityContactsOnly { + m.logger.Info("settings.ProfilePicturesVisibility is there") + } + + // TODO check that all the migration code is in place use ProfilePicturesVisibility as a guide + // getting an error of no such column: profile_pictures_show_to if s.ProfilePicturesShowTo == accounts.ProfilePicturesShowToNone { m.logger.Info(fmt.Sprintf("settings.ProfilePicturesShowTo is set to '%d', skipping attaching IdentityImages", s.ProfilePicturesShowTo)) return nil diff --git a/protocol/messenger_config.go b/protocol/messenger_config.go index e76e9466c..dbad27d27 100644 --- a/protocol/messenger_config.go +++ b/protocol/messenger_config.go @@ -5,6 +5,7 @@ import ( "go.uber.org/zap" + "github.com/status-im/status-go/appdatabase/migrations" "github.com/status-im/status-go/multiaccounts" "github.com/status-im/status-go/protocol/anonmetrics" "github.com/status-im/status-go/protocol/common" @@ -44,6 +45,7 @@ type config struct { // The database instance has a higher priority. dbConfig dbConfig db *sql.DB + afterDbCreatedHooks []Option multiAccount *multiaccounts.Database mailserversDatabase *mailservers.Database account *multiaccounts.Account @@ -102,6 +104,15 @@ func WithDatabase(db *sql.DB) Option { } } +func WithToplevelDatabaseMigrations() Option { + return func(c *config) error { + c.afterDbCreatedHooks = append(c.afterDbCreatedHooks, func(c *config) error { + return migrations.Migrate(c.db) + }) + return nil + } +} + func WithMultiAccounts(ma *multiaccounts.Database) Option { return func(c *config) error { c.multiAccount = ma diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index 7a083c057..0fb597da3 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -132,6 +132,7 @@ func newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey, logger *z WithMultiAccounts(madb), WithAccount(iai.ToMultiAccount()), WithDatasync(), + WithToplevelDatabaseMigrations(), } options = append(options, extraOptions...)