diff options
author | Sergey Dryabzhinsky <sergey.dryabzhinsky@gmail.com> | 2018-06-11 15:34:26 +0300 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2018-06-11 20:34:26 +0800 |
commit | 57897cc8c2c90ab1566a65bcd1eabfd41a906070 (patch) | |
tree | 146467cd0a0c7867345f584e2b6d05e68af6e831 /models | |
parent | 459c8be94fb704f974579471dd7a7197bd226b69 (diff) |
repo: update repository description field to contain more than 256 symbols (#5219)
* Update repository description field to contain more than 256 symbols
- update repository model - description field now is `TEXT` and limited by 4000 symbols
- new migration
- add description to html forms - repo creation and repo settings
- add translation for description
* Update for description field, new features
- add autosize (height) for description textarea, new plugin
- set max description length to 512 symbols
- update locales
* Fix migration - typo in var
* Update repo description behaviour
- add textarea autosize for /repo/create
- add symbols counter under description testarea (create/edit)
* Fix function definition - it a var
* Revert ru-RU locale
* Update by review
- Use type `varchar(512)` in migration
- Remove unused files from autosize plugin
* Fix migration - new project paths
* Fixes after review 2
- copyright year
- format includes
- use switch instead of multi-if
* Remove unused `default:` option.
Diffstat (limited to 'models')
-rw-r--r-- | models/migrations/migrations.go | 2 | ||||
-rw-r--r-- | models/migrations/v18.go | 34 | ||||
-rw-r--r-- | models/repo.go | 6 |
3 files changed, 39 insertions, 3 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 432717c7..7e700f49 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -64,6 +64,8 @@ var migrations = []Migration{ NewMigration("update repository sizes", updateRepositorySizes), // v16 -> v17:v0.10.31 NewMigration("remove invalid protect branch whitelist", removeInvalidProtectBranchWhitelist), + // v17 -> v18:v0.11.48 + NewMigration("store long text in repository description field", updateRepositoryDescriptionField), } // Migrate database to current version diff --git a/models/migrations/v18.go b/models/migrations/v18.go new file mode 100644 index 00000000..086cd27a --- /dev/null +++ b/models/migrations/v18.go @@ -0,0 +1,34 @@ +// Copyright 2018 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "fmt" + + "github.com/go-xorm/xorm" + + "github.com/gogs/gogs/pkg/setting" +) + +func updateRepositoryDescriptionField(x *xorm.Engine) error { + exist, err := x.IsTableExist("repository") + if err != nil { + return fmt.Errorf("IsTableExist: %v", err) + } else if !exist { + return nil + } + switch { + case setting.UseMySQL: + _, err = x.Exec("ALTER TABLE `repository` MODIFY `description` VARCHAR(512);") + case setting.UseMSSQL: + _, err = x.Exec("ALTER TABLE `repository` ALTER COLUMN `description` VARCHAR(512);") + case setting.UsePostgreSQL: + _, err = x.Exec("ALTER TABLE `repository` ALTER COLUMN `description` TYPE VARCHAR(512);") + case setting.UseSQLite3: + // Sqlite3 uses TEXT type by default for any string type field. + // Keep this comment to mention that we don't missed any option. + } + return err +} diff --git a/models/repo.go b/models/repo.go index 7a873afc..909af1d8 100644 --- a/models/repo.go +++ b/models/repo.go @@ -146,7 +146,7 @@ type Repository struct { Owner *User `xorm:"-" json:"-"` LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` Name string `xorm:"INDEX NOT NULL"` - Description string + Description string `xorm:"VARCHAR(512)"` Website string DefaultBranch string Size int64 `xorm:"NOT NULL DEFAULT 0"` @@ -1331,8 +1331,8 @@ func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) { func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) { repo.LowerName = strings.ToLower(repo.Name) - if len(repo.Description) > 255 { - repo.Description = repo.Description[:255] + if len(repo.Description) > 512 { + repo.Description = repo.Description[:512] } if len(repo.Website) > 255 { repo.Website = repo.Website[:255] |