Example #1
0
func addAgentMigrations(mg *migrator.Migrator) {
	agentV1 := migrator.Table{
		Name: "agent",
		Columns: []*migrator.Column{
			{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "name", Type: migrator.DB_NVarchar, Length: 255},
			{Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "enabled", Type: migrator.DB_Bool},
			{Name: "enabled_change", Type: migrator.DB_DateTime},
			{Name: "online", Type: migrator.DB_Bool},
			{Name: "online_change", Type: migrator.DB_DateTime},
			{Name: "public", Type: migrator.DB_Bool},
			{Name: "created", Type: migrator.DB_DateTime},
			{Name: "updated", Type: migrator.DB_DateTime},
		},
		Indices: []*migrator.Index{
			{Cols: []string{"org_id", "public"}},
			{Cols: []string{"name", "org_id"}, Type: migrator.UniqueIndex},
		},
	}
	mg.AddMigration("create agent table v1", migrator.NewAddTableMigration(agentV1))
	for _, index := range agentV1.Indices {
		migrationId := fmt.Sprintf("create index %s - %s", index.XName(agentV1.Name), "v1")
		mg.AddMigration(migrationId, migrator.NewAddIndexMigration(agentV1, index))
	}
}
func addAgentMetricMigrations(mg *migrator.Migrator) {
	agentMetricV1 := migrator.Table{
		Name: "agent_metric",
		Columns: []*migrator.Column{
			{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "agent_id", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "namespace", Type: migrator.DB_NVarchar, Length: 255, Nullable: false},
			{Name: "version", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "created", Type: migrator.DB_DateTime},
		},
		Indices: []*migrator.Index{
			{Cols: []string{"agent_id", "namespace", "version"}, Type: migrator.UniqueIndex},
		},
	}
	mg.AddMigration("create agent_metric table v1", migrator.NewAddTableMigration(agentMetricV1))
	for _, index := range agentMetricV1.Indices {
		migrationId := fmt.Sprintf("create index %s - %s", index.XName(agentMetricV1.Name), "v1")
		mg.AddMigration(migrationId, migrator.NewAddIndexMigration(agentMetricV1, index))
	}
}
Example #3
0
func addAgentTagMigrations(mg *migrator.Migrator) {
	agentTagV1 := migrator.Table{
		Name: "agent_tag",
		Columns: []*migrator.Column{
			{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "agent_id", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "tag", Type: migrator.DB_NVarchar, Length: 255},
			{Name: "created", Type: migrator.DB_DateTime},
		},
		Indices: []*migrator.Index{
			{Cols: []string{"org_id", "agent_id"}},
			{Cols: []string{"org_id", "tag"}},
		},
	}
	mg.AddMigration("create agent_tag table v1", migrator.NewAddTableMigration(agentTagV1))
	for _, index := range agentTagV1.Indices {
		migrationId := fmt.Sprintf("create index %s - %s", index.XName(agentTagV1.Name), "v1")
		mg.AddMigration(migrationId, migrator.NewAddIndexMigration(agentTagV1, index))
	}
}
func addAgentSessionMigrations(mg *migrator.Migrator) {
	agentSessionV1 := migrator.Table{
		Name: "agent_session",
		Columns: []*migrator.Column{
			{Name: "id", Type: migrator.DB_NVarchar, Length: 64, IsPrimaryKey: true},
			{Name: "agent_id", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "version", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "server", Type: migrator.DB_NVarchar, Length: 255},
			{Name: "remote_ip", Type: migrator.DB_NVarchar, Length: 255},
			{Name: "created", Type: migrator.DB_DateTime},
		},
		Indices: []*migrator.Index{
			{Cols: []string{"agent_id"}},
			{Cols: []string{"server"}},
		},
	}
	mg.AddMigration("create agent_session table v1", migrator.NewAddTableMigration(agentSessionV1))
	for _, index := range agentSessionV1.Indices {
		migrationId := fmt.Sprintf("create index %s - %s", index.XName(agentSessionV1.Name), "v1")
		mg.AddMigration(migrationId, migrator.NewAddIndexMigration(agentSessionV1, index))
	}
}
Example #5
0
func addTaskMigrations(mg *migrator.Migrator) {
	taskV1 := migrator.Table{
		Name: "task",
		Columns: []*migrator.Column{
			{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "name", Type: migrator.DB_NVarchar, Length: 255},
			{Name: "config", Type: migrator.DB_Text},
			{Name: "interval", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},
			{Name: "enabled", Type: migrator.DB_Bool},
			{Name: "route", Type: migrator.DB_Text, Nullable: false},
			{Name: "created", Type: migrator.DB_DateTime},
			{Name: "updated", Type: migrator.DB_DateTime},
		},
		Indices: []*migrator.Index{
			{Cols: []string{"org_id", "name"}, Type: migrator.UniqueIndex},
		},
	}
	mg.AddMigration("create task table v1", migrator.NewAddTableMigration(taskV1))
	for _, index := range taskV1.Indices {
		migrationId := fmt.Sprintf("create index %s - %s", index.XName(taskV1.Name), "v1")
		mg.AddMigration(migrationId, migrator.NewAddIndexMigration(taskV1, index))
	}
}