mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-17 03:45:13 +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:
|
services:
|
||||||
service-postgres:
|
service-postgres:
|
||||||
image: postgres:9.6
|
image: postgres:11
|
||||||
ports: ["5432"]
|
ports: ["5432"]
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=postgres
|
- POSTGRES_USER=postgres
|
||||||
|
|
|
@ -36,6 +36,7 @@ services:
|
||||||
## Configure Postgres
|
## 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.
|
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
|
```diff
|
||||||
# docker-compose.yml
|
# docker-compose.yml
|
||||||
|
|
|
@ -25,7 +25,7 @@ var alterTableReposDropCounter = task{
|
||||||
```
|
```
|
||||||
|
|
||||||
:::info
|
:::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
|
:::warning
|
||||||
|
|
|
@ -53,6 +53,12 @@ func newTestStore(t *testing.T, tables ...interface{}) (*storage, func()) {
|
||||||
return &storage{
|
return &storage{
|
||||||
engine: engine,
|
engine: engine,
|
||||||
}, func() {
|
}, func() {
|
||||||
|
for _, bean := range tables {
|
||||||
|
if err := engine.DropIndexes(bean); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := engine.DropTables(tables...); err != nil {
|
if err := engine.DropTables(tables...); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
|
|
@ -34,6 +34,23 @@ var migrationTasks = []task{
|
||||||
alterTableReposDropCounter,
|
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 {
|
type migrations struct {
|
||||||
Name string `xorm:"UNIQUE"`
|
Name string `xorm:"UNIQUE"`
|
||||||
}
|
}
|
||||||
|
@ -135,22 +152,7 @@ type syncEngine interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncAll(sess syncEngine) error {
|
func syncAll(sess syncEngine) error {
|
||||||
for _, bean := range []interface{}{
|
for _, bean := range allBeans {
|
||||||
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),
|
|
||||||
} {
|
|
||||||
if err := sess.Sync2(bean); err != nil {
|
if err := sess.Sync2(bean); err != nil {
|
||||||
return fmt.Errorf("sync2 error '%s': %v", reflect.TypeOf(bean), err)
|
return fmt.Errorf("sync2 error '%s': %v", reflect.TypeOf(bean), err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue