Add the content field to FileInfo (#15749)

* Add the content field to FileInfo

* Fixing the upgrade code

* Trying to fix the text-scheme

* Fixing test-schema

* Fixing test-schema

* Moving the migration to the next version
Этот коммит содержится в:
Jesús Espino
2020-11-02 15:43:48 +01:00
коммит произвёл GitHub
родитель 9bff309dd0
Коммит 24621a22ed
8 изменённых файлов: 111 добавлений и 2 удалений

Просмотреть файл

@@ -38,6 +38,7 @@ func newSqlFileInfoStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface
table.ColMap("ThumbnailPath").SetMaxSize(512)
table.ColMap("PreviewPath").SetMaxSize(512)
table.ColMap("Name").SetMaxSize(256)
table.ColMap("Content").SetMaxSize(0)
table.ColMap("Extension").SetMaxSize(64)
table.ColMap("MimeType").SetMaxSize(256)
}
@@ -272,6 +273,33 @@ func (fs SqlFileInfoStore) AttachToPost(fileId, postId, creatorId string) error
return nil
}
func (fs SqlFileInfoStore) SetContent(fileId, content string) error {
query := fs.getQueryBuilder().
Update("FileInfo").
Set("Content", content).
Where(sq.Eq{"Id": fileId})
queryString, args, err := query.ToSql()
if err != nil {
return errors.Wrap(err, "file_info_tosql")
}
sqlResult, err := fs.GetMaster().Exec(queryString, args...)
if err != nil {
return errors.Wrapf(err, "failed to update FileInfo content with id=%s", fileId)
}
count, err := sqlResult.RowsAffected()
if err != nil {
// RowsAffected should never fail with the MySQL or Postgres drivers
return errors.Wrap(err, "unable to retrieve rows affected")
} else if count == 0 {
// Could not attach the file to the post
return store.NewErrInvalidInput("FileInfo", "<id>", fmt.Sprintf("<%s>", fileId))
}
return nil
}
func (fs SqlFileInfoStore) DeleteForPost(postId string) (string, error) {
if _, err := fs.GetMaster().Exec(
`UPDATE

Просмотреть файл

@@ -192,6 +192,7 @@ func upgradeDatabase(sqlStore SqlStore, currentModelVersionString string) error
upgradeDatabaseToVersion528(sqlStore)
upgradeDatabaseToVersion5281(sqlStore)
upgradeDatabaseToVersion529(sqlStore)
upgradeDatabaseToVersion530(sqlStore)
return nil
}
@@ -865,6 +866,15 @@ func upgradeDatabaseToVersion5281(sqlStore SqlStore) {
}
}
func upgradeDatabaseToVersion530(sqlStore SqlStore) {
// if shouldPerformUpgrade(sqlStore, VERSION_5_29_0, VERSION_5_30_0) {
sqlStore.CreateColumnIfNotExistsNoDefault("FileInfo", "Content", "longtext", "text")
// saveSchemaVersion(sqlStore, VERSION_5_30_0)
// }
}
func precheckMigrationToVersion528(sqlStore SqlStore) error {
teamsQuery, _, err := sqlStore.getQueryBuilder().Select(`COALESCE(SUM(CASE
WHEN CHAR_LENGTH(SchemeId) > 26 THEN 1