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

     1  package migrate
     2  
     3  type rev1st struct{}
     4  
     5  var SetupTables = &rev1st{}
     6  
     7  func (r *rev1st) Revision() int64 {
     8  	return 1
     9  }
    10  
    11  func (r *rev1st) Up(mg *MigrationDriver) error {
    12  	t := mg.T
    13  	if _, err := mg.CreateTable("users", []string{
    14  		t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
    15  		t.String("email", UNIQUE),
    16  		t.String("password"),
    17  		t.String("token", UNIQUE),
    18  		t.String("name"),
    19  		t.String("gravatar"),
    20  		t.Timestamp("created"),
    21  		t.Timestamp("updated"),
    22  		t.Bool("admin"),
    23  		t.String("github_login"),
    24  		t.String("github_token"),
    25  		t.String("bitbucket_login"),
    26  		t.String("bitbucket_token"),
    27  		t.String("bitbucket_secret"),
    28  	}); err != nil {
    29  		return err
    30  	}
    31  
    32  	if _, err := mg.CreateTable("teams", []string{
    33  		t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
    34  		t.String("slug", UNIQUE),
    35  		t.String("name"),
    36  		t.String("email"),
    37  		t.String("gravatar"),
    38  		t.Timestamp("created"),
    39  		t.Timestamp("updated"),
    40  	}); err != nil {
    41  		return err
    42  	}
    43  
    44  	if _, err := mg.CreateTable("members", []string{
    45  		t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
    46  		t.Integer("team_id"),
    47  		t.Integer("user_id"),
    48  		t.String("role"),
    49  	}); err != nil {
    50  		return err
    51  	}
    52  
    53  	if _, err := mg.CreateTable("repos", []string{
    54  		t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
    55  		t.String("slug", UNIQUE),
    56  		t.String("host"),
    57  		t.String("owner"),
    58  		t.String("name"),
    59  		t.Bool("private"),
    60  		t.Bool("disabled"),
    61  		t.Bool("disabled_pr"),
    62  		t.Bool("priveleged"),
    63  		t.Integer("timeout"),
    64  		t.Varchar("scm", 25),
    65  		t.Varchar("url", 1024),
    66  		t.String("username"),
    67  		t.String("password"),
    68  		t.Varchar("public_key", 1024),
    69  		t.Varchar("private_key", 1024),
    70  		t.Blob("params"),
    71  		t.Timestamp("created"),
    72  		t.Timestamp("updated"),
    73  		t.Integer("user_id"),
    74  		t.Integer("team_id"),
    75  	}); err != nil {
    76  		return err
    77  	}
    78  
    79  	if _, err := mg.CreateTable("commits", []string{
    80  		t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
    81  		t.Integer("repo_id"),
    82  		t.String("status"),
    83  		t.Timestamp("started"),
    84  		t.Timestamp("finished"),
    85  		t.Integer("duration"),
    86  		t.Integer("attempts"),
    87  		t.String("hash"),
    88  		t.String("branch"),
    89  		t.String("pull_request"),
    90  		t.String("author"),
    91  		t.String("gravatar"),
    92  		t.String("timestamp"),
    93  		t.String("message"),
    94  		t.Timestamp("created"),
    95  		t.Timestamp("updated"),
    96  	}); err != nil {
    97  		return err
    98  	}
    99  
   100  	if _, err := mg.CreateTable("builds", []string{
   101  		t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
   102  		t.Integer("commit_id"),
   103  		t.String("slug"),
   104  		t.String("status"),
   105  		t.Timestamp("started"),
   106  		t.Timestamp("finished"),
   107  		t.Integer("duration"),
   108  		t.Timestamp("created"),
   109  		t.Timestamp("updated"),
   110  		t.Text("stdout"),
   111  	}); err != nil {
   112  		return err
   113  	}
   114  
   115  	_, err := mg.CreateTable("settings", []string{
   116  		t.Integer("id", PRIMARYKEY, AUTOINCREMENT),
   117  		t.String("github_key"),
   118  		t.String("github_secret"),
   119  		t.String("bitbucket_key"),
   120  		t.String("bitbucket_secret"),
   121  		t.Varchar("smtp_server", 1024),
   122  		t.Varchar("smtp_port", 5),
   123  		t.Varchar("smtp_address", 1024),
   124  		t.Varchar("smtp_username", 1024),
   125  		t.Varchar("smtp_password", 1024),
   126  		t.Varchar("hostname", 1024),
   127  		t.Varchar("scheme", 5),
   128  	})
   129  	return err
   130  }
   131  
   132  func (r *rev1st) Down(mg *MigrationDriver) error {
   133  	if _, err := mg.DropTable("settings"); err != nil {
   134  		return err
   135  	}
   136  	if _, err := mg.DropTable("builds"); err != nil {
   137  		return err
   138  	}
   139  	if _, err := mg.DropTable("commits"); err != nil {
   140  		return err
   141  	}
   142  	if _, err := mg.DropTable("repos"); err != nil {
   143  		return err
   144  	}
   145  	if _, err := mg.DropTable("members"); err != nil {
   146  		return err
   147  	}
   148  	if _, err := mg.DropTable("teams"); err != nil {
   149  		return err
   150  	}
   151  	_, err := mg.DropTable("users")
   152  	return err
   153  }