1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00

Update dev-docs & improve migration code (#670)

This commit is contained in:
6543 2022-01-08 20:21:22 +01:00 committed by GitHub
parent acbde30c3b
commit c186e2fa8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 18 deletions

View File

@ -63,7 +63,7 @@ pipeline:
services:
service-postgres:
image: postgres:9.6
image: postgres:11
ports: ["5432"]
environment:
- POSTGRES_USER=postgres

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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)
}