github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/database/migrate/20140328201430_add_gitlab_columns.go (about)

     1  package migrate
     2  
     3  type rev20140328201430 struct{}
     4  
     5  var AddGitlabColumns = &rev20140328201430{}
     6  
     7  func (r *rev20140328201430) Revision() int64 {
     8  	return 20140328201430
     9  }
    10  
    11  func (r *rev20140328201430) Up(mg *MigrationDriver) error {
    12  	// Migration steps here
    13  	if _, err := mg.AddColumn("settings", mg.T.String("gitlab_domain")); err != nil {
    14  		return err
    15  	}
    16  	if _, err := mg.AddColumn("settings", mg.T.String("gitlab_apiurl")); err != nil {
    17  		return err
    18  	}
    19  
    20  	if _, err := mg.Tx.Exec(`update settings set gitlab_domain=?`, "gitlab.com"); err != nil {
    21  		return err
    22  	}
    23  
    24  	if _, err := mg.Tx.Exec(`update settings set gitlab_apiurl=?`, "https://gitlab.com"); err != nil {
    25  		return err
    26  	}
    27  
    28  	if _, err := mg.AddColumn("users", mg.T.String("gitlab_token")); err != nil {
    29  		return err
    30  	}
    31  
    32  	_, err := mg.Tx.Exec(`update users set gitlab_token=?`, "")
    33  	return err
    34  }
    35  
    36  func (r *rev20140328201430) Down(mg *MigrationDriver) error {
    37  	// Revert migration steps here
    38  	if _, err := mg.DropColumns("users", "gitlab_token"); err != nil {
    39  		return err
    40  	}
    41  	_, err := mg.DropColumns("settings", "gitlab_domain", "gitlab_apiurl")
    42  	return err
    43  }