From b13d5e746614d08a53ebf046565d8544b1c649e3 Mon Sep 17 00:00:00 2001 From: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com> Date: Mon, 23 May 2022 12:15:56 +0530 Subject: [PATCH] Added Archived column to FileInfo (#20164) * Added Archived column to FileInfo * fixed typo * Added new column to store column list * Fixing tests * Updated migration number to syncup with master --- .../000085_fileinfo_add_archived_column.down.sql | 14 ++++++++++++++ .../000085_fileinfo_add_archived_column.up.sql | 15 +++++++++++++++ .../000085_fileinfo_add_archived_column.down.sql | 1 + .../000085_fileinfo_add_archived_column.up.sql | 1 + model/file_info.go | 1 + store/sqlstore/file_info_store.go | 2 ++ 6 files changed, 34 insertions(+) create mode 100644 db/migrations/mysql/000085_fileinfo_add_archived_column.down.sql create mode 100644 db/migrations/mysql/000085_fileinfo_add_archived_column.up.sql create mode 100644 db/migrations/postgres/000085_fileinfo_add_archived_column.down.sql create mode 100644 db/migrations/postgres/000085_fileinfo_add_archived_column.up.sql diff --git a/db/migrations/mysql/000085_fileinfo_add_archived_column.down.sql b/db/migrations/mysql/000085_fileinfo_add_archived_column.down.sql new file mode 100644 index 0000000000..9ac9b2a9a2 --- /dev/null +++ b/db/migrations/mysql/000085_fileinfo_add_archived_column.down.sql @@ -0,0 +1,14 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'FileInfo' + AND table_schema = DATABASE() + AND column_name = 'Archived' + ) > 0, + 'ALTER TABLE FileInfo DROP COLUMN Archived;', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; diff --git a/db/migrations/mysql/000085_fileinfo_add_archived_column.up.sql b/db/migrations/mysql/000085_fileinfo_add_archived_column.up.sql new file mode 100644 index 0000000000..0b86090af3 --- /dev/null +++ b/db/migrations/mysql/000085_fileinfo_add_archived_column.up.sql @@ -0,0 +1,15 @@ + +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'FileInfo' + AND table_schema = DATABASE() + AND column_name = 'Archived' + ) > 0, + 'SELECT 1', + 'ALTER TABLE FileInfo ADD COLUMN Archived boolean NOT NULL DEFAULT false;' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; diff --git a/db/migrations/postgres/000085_fileinfo_add_archived_column.down.sql b/db/migrations/postgres/000085_fileinfo_add_archived_column.down.sql new file mode 100644 index 0000000000..120b2f9f26 --- /dev/null +++ b/db/migrations/postgres/000085_fileinfo_add_archived_column.down.sql @@ -0,0 +1 @@ +ALTER TABLE fileinfo DROP COLUMN IF EXISTS archived; diff --git a/db/migrations/postgres/000085_fileinfo_add_archived_column.up.sql b/db/migrations/postgres/000085_fileinfo_add_archived_column.up.sql new file mode 100644 index 0000000000..462b1c60db --- /dev/null +++ b/db/migrations/postgres/000085_fileinfo_add_archived_column.up.sql @@ -0,0 +1 @@ +ALTER TABLE fileinfo ADD COLUMN IF NOT EXISTS archived boolean NOT NULL DEFAULT false; diff --git a/model/file_info.go b/model/file_info.go index 569689967d..366b544676 100644 --- a/model/file_info.go +++ b/model/file_info.go @@ -55,6 +55,7 @@ type FileInfo struct { MiniPreview *[]byte `json:"mini_preview"` // declared as *[]byte to avoid postgres/mysql differences in deserialization Content string `json:"-"` RemoteId *string `json:"remote_id"` + Archived bool `json:"archived"` } func (fi *FileInfo) PreSave() { diff --git a/store/sqlstore/file_info_store.go b/store/sqlstore/file_info_store.go index ceb24bd39b..ea20a24743 100644 --- a/store/sqlstore/file_info_store.go +++ b/store/sqlstore/file_info_store.go @@ -41,6 +41,7 @@ type fileInfoWithChannelID struct { MiniPreview *[]byte Content string RemoteId *string + Archived bool } func (fi fileInfoWithChannelID) ToModel() *model.FileInfo { @@ -103,6 +104,7 @@ func newSqlFileInfoStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterfac "FileInfo.MiniPreview", "Coalesce(FileInfo.Content, '') AS Content", "Coalesce(FileInfo.RemoteId, '') AS RemoteId", + "FileInfo.Archived", } return s