mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +00:00
Update dev-docs & improve migration code (#670)
This commit is contained in:
parent
acbde30c3b
commit
c186e2fa8c
5 changed files with 27 additions and 18 deletions
|
@ -63,7 +63,7 @@ pipeline:
|
|||
|
||||
services:
|
||||
service-postgres:
|
||||
image: postgres:9.6
|
||||
image: postgres:11
|
||||
ports: ["5432"]
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
|
|
|
@ -36,6 +36,7 @@ services:
|
|||
## Configure Postgres
|
||||
|
||||
The below example demonstrates postgres database configuration. See the official driver [documentation](https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING) for configuration options and examples.
|
||||
Please use postgres versions equal or higher than **11**.
|
||||
|
||||
```diff
|
||||
# docker-compose.yml
|
||||
|
|
|
@ -25,7 +25,7 @@ var alterTableReposDropCounter = task{
|
|||
```
|
||||
|
||||
:::info
|
||||
Adding new properties to models will be handled automatically by the underlying [ORM](#orm) based on the [struct field tags](https://stackoverflow.com/questions/10858787/what-are-the-uses-for-tags-in-go) of the model. If you add a completely new model, you have to add it to the `syncAll()` function at `server/store/datastore/migration/migration.go` to get a new table created.
|
||||
Adding new properties to models will be handled automatically by the underlying [ORM](#orm) based on the [struct field tags](https://stackoverflow.com/questions/10858787/what-are-the-uses-for-tags-in-go) of the model. If you add a completely new model, you have to add it to the `allBeans` variable at `server/store/datastore/migration/migration.go` to get a new table created.
|
||||
:::
|
||||
|
||||
:::warning
|
||||
|
|
|
@ -53,6 +53,12 @@ func newTestStore(t *testing.T, tables ...interface{}) (*storage, func()) {
|
|||
return &storage{
|
||||
engine: engine,
|
||||
}, func() {
|
||||
for _, bean := range tables {
|
||||
if err := engine.DropIndexes(bean); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
if err := engine.DropTables(tables...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
|
|
|
@ -34,6 +34,23 @@ var migrationTasks = []task{
|
|||
alterTableReposDropCounter,
|
||||
}
|
||||
|
||||
var allBeans = []interface{}{
|
||||
new(model.Agent),
|
||||
new(model.Build),
|
||||
new(model.BuildConfig),
|
||||
new(model.Config),
|
||||
new(model.File),
|
||||
new(model.Logs),
|
||||
new(model.Perm),
|
||||
new(model.Proc),
|
||||
new(model.Registry),
|
||||
new(model.Repo),
|
||||
new(model.Secret),
|
||||
new(model.Sender),
|
||||
new(model.Task),
|
||||
new(model.User),
|
||||
}
|
||||
|
||||
type migrations struct {
|
||||
Name string `xorm:"UNIQUE"`
|
||||
}
|
||||
|
@ -135,22 +152,7 @@ type syncEngine interface {
|
|||
}
|
||||
|
||||
func syncAll(sess syncEngine) error {
|
||||
for _, bean := range []interface{}{
|
||||
new(model.Agent),
|
||||
new(model.Build),
|
||||
new(model.BuildConfig),
|
||||
new(model.Config),
|
||||
new(model.File),
|
||||
new(model.Logs),
|
||||
new(model.Perm),
|
||||
new(model.Proc),
|
||||
new(model.Registry),
|
||||
new(model.Repo),
|
||||
new(model.Secret),
|
||||
new(model.Sender),
|
||||
new(model.Task),
|
||||
new(model.User),
|
||||
} {
|
||||
for _, bean := range allBeans {
|
||||
if err := sess.Sync2(bean); err != nil {
|
||||
return fmt.Errorf("sync2 error '%s': %v", reflect.TypeOf(bean), err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue