| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | package migrations | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | func addTeamMigrations(mg *Migrator) { | 
					
						
							|  |  |  | 	teamV1 := Table{ | 
					
						
							|  |  |  | 		Name: "team", | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 		Columns: []*Column{ | 
					
						
							|  |  |  | 			{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true}, | 
					
						
							| 
									
										
										
										
											2017-12-18 20:38:29 +08:00
										 |  |  | 			{Name: "name", Type: DB_NVarchar, Length: 190, Nullable: false}, | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 			{Name: "org_id", Type: DB_BigInt}, | 
					
						
							|  |  |  | 			{Name: "created", Type: DB_DateTime, Nullable: false}, | 
					
						
							|  |  |  | 			{Name: "updated", Type: DB_DateTime, Nullable: false}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Indices: []*Index{ | 
					
						
							|  |  |  | 			{Cols: []string{"org_id"}}, | 
					
						
							|  |  |  | 			{Cols: []string{"org_id", "name"}, Type: UniqueIndex}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | 	mg.AddMigration("create team table", NewAddTableMigration(teamV1)) | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//-------  indexes ------------------
 | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | 	mg.AddMigration("add index team.org_id", NewAddIndexMigration(teamV1, teamV1.Indices[0])) | 
					
						
							|  |  |  | 	mg.AddMigration("add unique index team_org_id_name", NewAddIndexMigration(teamV1, teamV1.Indices[1])) | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | 	teamMemberV1 := Table{ | 
					
						
							|  |  |  | 		Name: "team_member", | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 		Columns: []*Column{ | 
					
						
							|  |  |  | 			{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true}, | 
					
						
							|  |  |  | 			{Name: "org_id", Type: DB_BigInt}, | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | 			{Name: "team_id", Type: DB_BigInt}, | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 			{Name: "user_id", Type: DB_BigInt}, | 
					
						
							|  |  |  | 			{Name: "created", Type: DB_DateTime, Nullable: false}, | 
					
						
							|  |  |  | 			{Name: "updated", Type: DB_DateTime, Nullable: false}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Indices: []*Index{ | 
					
						
							|  |  |  | 			{Cols: []string{"org_id"}}, | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | 			{Cols: []string{"org_id", "team_id", "user_id"}, Type: UniqueIndex}, | 
					
						
							| 
									
										
										
										
											2020-06-26 21:13:53 +08:00
										 |  |  | 			{Cols: []string{"team_id"}}, | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | 	mg.AddMigration("create team member table", NewAddTableMigration(teamMemberV1)) | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//-------  indexes ------------------
 | 
					
						
							| 
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 |  |  | 	mg.AddMigration("add index team_member.org_id", NewAddIndexMigration(teamMemberV1, teamMemberV1.Indices[0])) | 
					
						
							|  |  |  | 	mg.AddMigration("add unique index team_member_org_id_team_id_user_id", NewAddIndexMigration(teamMemberV1, teamMemberV1.Indices[1])) | 
					
						
							| 
									
										
										
										
											2020-06-26 21:13:53 +08:00
										 |  |  | 	mg.AddMigration("add index team_member.team_id", NewAddIndexMigration(teamMemberV1, teamMemberV1.Indices[2])) | 
					
						
							| 
									
										
										
										
											2017-12-21 04:20:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// add column email
 | 
					
						
							|  |  |  | 	mg.AddMigration("Add column email to team table", NewAddColumnMigration(teamV1, &Column{ | 
					
						
							|  |  |  | 		Name: "email", Type: DB_NVarchar, Nullable: true, Length: 190, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2018-07-01 22:01:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 23:27:36 +08:00
										 |  |  | 	mg.AddMigration("Add column external to team_member table", NewAddColumnMigration(teamMemberV1, &Column{ | 
					
						
							|  |  |  | 		Name: "external", Type: DB_Bool, Nullable: true, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2019-03-06 18:47:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mg.AddMigration("Add column permission to team_member table", NewAddColumnMigration(teamMemberV1, &Column{ | 
					
						
							| 
									
										
										
										
											2019-03-14 16:08:48 +08:00
										 |  |  | 		Name: "permission", Type: DB_SmallInt, Nullable: true, | 
					
						
							| 
									
										
										
										
											2019-03-06 18:47:18 +08:00
										 |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2017-03-27 20:36:28 +08:00
										 |  |  | } |