mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-04-15 01:41:56 +00:00
Integrate migrations with drone.
Also add migration to tests.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package migrate
|
||||
|
||||
type Rev1 struct{}
|
||||
|
||||
var RenamePrivelegedToPrivileged = &Rev1{}
|
||||
|
||||
func (r *Rev1) Revision() int64 {
|
||||
return 201402200603
|
||||
}
|
||||
|
||||
func (r *Rev1) Up(op Operation) error {
|
||||
_, err := op.RenameColumns("repos", map[string]string{
|
||||
"priveleged": "privileged",
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *Rev1) Down(op Operation) error {
|
||||
_, err := op.RenameColumns("repos", map[string]string{
|
||||
"privileged": "priveleged",
|
||||
})
|
||||
return err
|
||||
}
|
||||
11
pkg/database/migrate/all.go
Normal file
11
pkg/database/migrate/all.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package migrate
|
||||
|
||||
func (m *Migration) All() *Migration {
|
||||
|
||||
// List all migrations here
|
||||
m.Add(RenamePrivelegedToPrivileged)
|
||||
|
||||
// m.Add(...)
|
||||
// ...
|
||||
return m
|
||||
}
|
||||
@@ -13,7 +13,7 @@ const repoTable = "repos"
|
||||
// SQL Queries to retrieve a list of all repos belonging to a User.
|
||||
const repoStmt = `
|
||||
SELECT id, slug, host, owner, name, private, disabled, disabled_pr, scm, url, username, password,
|
||||
public_key, private_key, params, timeout, priveleged, created, updated, user_id, team_id
|
||||
public_key, private_key, params, timeout, privileged, created, updated, user_id, team_id
|
||||
FROM repos
|
||||
WHERE user_id = ? AND team_id = 0
|
||||
ORDER BY slug ASC
|
||||
@@ -22,7 +22,7 @@ ORDER BY slug ASC
|
||||
// SQL Queries to retrieve a list of all repos belonging to a Team.
|
||||
const repoTeamStmt = `
|
||||
SELECT id, slug, host, owner, name, private, disabled, disabled_pr, scm, url, username, password,
|
||||
public_key, private_key, params, timeout, priveleged, created, updated, user_id, team_id
|
||||
public_key, private_key, params, timeout, privileged, created, updated, user_id, team_id
|
||||
FROM repos
|
||||
WHERE team_id = ?
|
||||
ORDER BY slug ASC
|
||||
@@ -31,7 +31,7 @@ ORDER BY slug ASC
|
||||
// SQL Queries to retrieve a repo by id.
|
||||
const repoFindStmt = `
|
||||
SELECT id, slug, host, owner, name, private, disabled, disabled_pr, scm, url, username, password,
|
||||
public_key, private_key, params, timeout, priveleged, created, updated, user_id, team_id
|
||||
public_key, private_key, params, timeout, privileged, created, updated, user_id, team_id
|
||||
FROM repos
|
||||
WHERE id = ?
|
||||
`
|
||||
@@ -39,7 +39,7 @@ WHERE id = ?
|
||||
// SQL Queries to retrieve a repo by name.
|
||||
const repoFindSlugStmt = `
|
||||
SELECT id, slug, host, owner, name, private, disabled, disabled_pr, scm, url, username, password,
|
||||
public_key, private_key, params, timeout, priveleged, created, updated, user_id, team_id
|
||||
public_key, private_key, params, timeout, privileged, created, updated, user_id, team_id
|
||||
FROM repos
|
||||
WHERE slug = ?
|
||||
`
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/drone/drone/pkg/database"
|
||||
"github.com/drone/drone/pkg/database/encrypt"
|
||||
"github.com/drone/drone/pkg/database/migrate"
|
||||
. "github.com/drone/drone/pkg/model"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
@@ -31,6 +32,7 @@ func init() {
|
||||
|
||||
// notify meddler that we are working with sqlite
|
||||
meddler.Default = meddler.SQLite
|
||||
migrate.Driver = migrate.SQLite
|
||||
}
|
||||
|
||||
func Setup() {
|
||||
@@ -40,6 +42,9 @@ func Setup() {
|
||||
// make sure all the tables and indexes are created
|
||||
database.Set(db)
|
||||
|
||||
migration := migrate.New(db)
|
||||
migration.All().Migrate()
|
||||
|
||||
// create dummy user data
|
||||
user1 := User{
|
||||
Password: "$2a$10$b8d63QsTL38vx7lj0HEHfOdbu1PCAg6Gfca74UavkXooIBx9YxopS",
|
||||
|
||||
Reference in New Issue
Block a user