1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/pkg/database/migrate/1_setup_tables.go
Nurahmadie 7cf4f2eb89 Preliminary MySQL support. Barely tested.
Requirements:
MySQL/MariaDB need to be configured with this settings:

  innodb_file_format = Barracuda
  innodb_file_per_table = On
  innodb_large_prefix = On

to support key prefix length up to 3042 bytes.

MySQL/MariaDB DSN will need this parameter:

  parseTime=true

as per [1]

The migration system itself mostly inspired by Rails (ActiveRecord),
but it still rough at the edges. Could use some inputs.

Next Todo: more testing!

[1]  https://github.com/go-sql-driver/mysql#parsetime
2014-03-14 02:28:10 +07:00

154 lines
3.5 KiB
Go

package migrate
type rev1st struct{}
var SetupTables = &rev1st{}
func (r *rev1st) Revision() int64 {
return 1
}
func (r *rev1st) Up(mg *MigrationDriver) error {
t := mg.T
if _, err := mg.CreateTable("users", []string{
t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
t.String("email", UNIQUE),
t.String("password"),
t.String("token", UNIQUE),
t.String("name"),
t.String("gravatar"),
t.Timestamp("created"),
t.Timestamp("updated"),
t.Bool("admin"),
t.String("github_login"),
t.String("github_token"),
t.String("bitbucket_login"),
t.String("bitbucket_token"),
t.String("bitbucket_secret"),
}); err != nil {
return err
}
if _, err := mg.CreateTable("teams", []string{
t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
t.String("slug", UNIQUE),
t.String("name"),
t.String("email"),
t.String("gravatar"),
t.Timestamp("created"),
t.Timestamp("updated"),
}); err != nil {
return err
}
if _, err := mg.CreateTable("members", []string{
t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
t.Integer("team_id"),
t.Integer("user_id"),
t.Integer("role"),
}); err != nil {
return err
}
if _, err := mg.CreateTable("repos", []string{
t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
t.String("slug", UNIQUE),
t.String("host"),
t.String("owner"),
t.String("name"),
t.Bool("private"),
t.Bool("disabled"),
t.Bool("disabled_pr"),
t.Bool("priveleged"),
t.Integer("timeout"),
t.Varchar("scm", 25),
t.Varchar("url", 1024),
t.String("username"),
t.String("password"),
t.Varchar("public_key", 1024),
t.Varchar("private_key", 1024),
t.Varchar("params", 2000),
t.Timestamp("created"),
t.Timestamp("updated"),
t.Integer("user_id"),
t.Integer("team_id"),
}); err != nil {
return err
}
if _, err := mg.CreateTable("commits", []string{
t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
t.Integer("repo_id"),
t.String("status"),
t.Timestamp("started"),
t.Timestamp("finished"),
t.Integer("duration"),
t.Integer("attempts"),
t.String("hash"),
t.String("branch"),
t.String("pull_request"),
t.String("author"),
t.String("gravatar"),
t.String("timestamp"),
t.String("message"),
t.Timestamp("created"),
t.Timestamp("updated"),
}); err != nil {
return err
}
if _, err := mg.CreateTable("builds", []string{
t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
t.Integer("commit_id"),
t.String("slug"),
t.String("status"),
t.Timestamp("started"),
t.Timestamp("finished"),
t.Integer("duration"),
t.Timestamp("created"),
t.Timestamp("updated"),
t.Text("stdout"),
}); err != nil {
return err
}
_, err := mg.CreateTable("settings", []string{
t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
t.String("github_key"),
t.String("github_secret"),
t.String("bitbucket_key"),
t.String("bitbucket_secret"),
t.Varchar("smtp_server", 1024),
t.Varchar("smtp_port", 5),
t.Varchar("smtp_address", 1024),
t.Varchar("smtp_username", 1024),
t.Varchar("smtp_password", 1024),
t.Varchar("hostname", 1024),
t.Varchar("scheme", 5),
})
return err
}
func (r *rev1st) Down(mg *MigrationDriver) error {
if _, err := mg.DropTable("settings"); err != nil {
return err
}
if _, err := mg.DropTable("builds"); err != nil {
return err
}
if _, err := mg.DropTable("commits"); err != nil {
return err
}
if _, err := mg.DropTable("repos"); err != nil {
return err
}
if _, err := mg.DropTable("members"); err != nil {
return err
}
if _, err := mg.DropTable("teams"); err != nil {
return err
}
_, err := mg.DropTable("users")
return err
}