func (seed Seeder) ApplyTo(db *database.Connection) error {
	systemLogger := logging.GetSystemLogger()
	systemLogger.Log("msg", "Applying seed data", "firstUser", seed.Users[0].FirstName)
	logging.SetSystemLogger(logging.NewNopLogger())
	defer logging.SetSystemLogger(systemLogger)
	err := db.WithTx(context.Background(), func(tx *database.Transactable) {
		tx.BatchInsert("finding_categories", len(seed.FindingCategories), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":         seed.FindingCategories[i].ID,
				"category":   seed.FindingCategories[i].Category,
				"created_at": seed.FindingCategories[i].CreatedAt,
				"updated_at": seed.FindingCategories[i].UpdatedAt,
				"deleted_at": seed.FindingCategories[i].DeletedAt,
			}
		})
		tx.BatchInsert("users", len(seed.Users), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":         seed.Users[i].ID,
				"slug":       seed.Users[i].Slug,
				"first_name": seed.Users[i].FirstName,
				"last_name":  seed.Users[i].LastName,
				"email":      seed.Users[i].Email,
				"admin":      seed.Users[i].Admin,
				"headless":   seed.Users[i].Headless,
				"disabled":   seed.Users[i].Disabled,
				"created_at": seed.Users[i].CreatedAt,
				"updated_at": seed.Users[i].UpdatedAt,
				"deleted_at": seed.Users[i].DeletedAt,
			}
		})
		tx.BatchInsert("api_keys", len(seed.APIKeys), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":         seed.APIKeys[i].ID,
				"access_key": seed.APIKeys[i].AccessKey,
				"secret_key": seed.APIKeys[i].SecretKey,
				"user_id":    seed.APIKeys[i].UserID,
				"created_at": seed.APIKeys[i].CreatedAt,
				"updated_at": seed.APIKeys[i].UpdatedAt,
			}
		})
		tx.BatchInsert("auth_scheme_data", len(seed.Users), func(i int) map[string]interface{} {
			if seed.Users[i].DeletedAt != nil || seed.Users[i].Headless {
				return map[string]interface{}{}
			}
			encryptedPassword, _ := bcrypt.GenerateFromPassword([]byte(strings.ToLower(seed.Users[i].FirstName)), bcrypt.DefaultCost)
			return map[string]interface{}{
				"id":                 seed.Users[i].ID,
				"auth_scheme":        localConsts.Code,
				"auth_type":          localConsts.Code,
				"user_key":           seed.Users[i].FirstName,
				"user_id":            seed.Users[i].ID,
				"encrypted_password": encryptedPassword,  
				"created_at":         seed.Users[i].CreatedAt,
				"updated_at":         seed.Users[i].UpdatedAt,
			}
		})
		tx.BatchInsert("operations", len(seed.Operations), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":         seed.Operations[i].ID,
				"slug":       seed.Operations[i].Slug,
				"name":       seed.Operations[i].Name,
				"status":     seed.Operations[i].Status,
				"created_at": seed.Operations[i].CreatedAt,
				"updated_at": seed.Operations[i].UpdatedAt,
			}
		})
		tx.BatchInsert("user_operation_permissions", len(seed.UserOpMap), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"user_id":      seed.UserOpMap[i].UserID,
				"operation_id": seed.UserOpMap[i].OperationID,
				"role":         seed.UserOpMap[i].Role,
				"created_at":   seed.UserOpMap[i].CreatedAt,
				"updated_at":   seed.UserOpMap[i].UpdatedAt,
			}
		})
		tx.BatchInsert("tags", len(seed.Tags), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":           seed.Tags[i].ID,
				"operation_id": seed.Tags[i].OperationID,
				"name":         seed.Tags[i].Name,
				"color_name":   seed.Tags[i].ColorName,
				"created_at":   seed.Tags[i].CreatedAt,
				"updated_at":   seed.Tags[i].UpdatedAt,
			}
		})
		tx.BatchInsert("evidence", len(seed.Evidences), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":              seed.Evidences[i].ID,
				"uuid":            seed.Evidences[i].UUID,
				"operation_id":    seed.Evidences[i].OperationID,
				"operator_id":     seed.Evidences[i].OperatorID,
				"description":     seed.Evidences[i].Description,
				"content_type":    seed.Evidences[i].ContentType,
				"full_image_key":  seed.Evidences[i].FullImageKey,
				"thumb_image_key": seed.Evidences[i].ThumbImageKey,
				"occurred_at":     seed.Evidences[i].OccurredAt,
				"created_at":      seed.Evidences[i].CreatedAt,
				"updated_at":      seed.Evidences[i].UpdatedAt,
			}
		})
		tx.BatchInsert("findings", len(seed.Findings), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":              seed.Findings[i].ID,
				"uuid":            seed.Findings[i].UUID,
				"operation_id":    seed.Findings[i].OperationID,
				"ready_to_report": seed.Findings[i].ReadyToReport,
				"ticket_link":     seed.Findings[i].TicketLink,
				"category_id":     seed.Findings[i].CategoryID,
				"title":           seed.Findings[i].Title,
				"description":     seed.Findings[i].Description,
				"created_at":      seed.Findings[i].CreatedAt,
				"updated_at":      seed.Findings[i].UpdatedAt,
			}
		})
		tx.BatchInsert("evidence_finding_map", len(seed.EviFindingsMap), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"evidence_id": seed.EviFindingsMap[i].EvidenceID,
				"finding_id":  seed.EviFindingsMap[i].FindingID,
				"created_at":  seed.EviFindingsMap[i].CreatedAt,
				"updated_at":  seed.EviFindingsMap[i].UpdatedAt,
			}
		})
		tx.BatchInsert("tag_evidence_map", len(seed.TagEviMap), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"tag_id":      seed.TagEviMap[i].TagID,
				"evidence_id": seed.TagEviMap[i].EvidenceID,
				"created_at":  seed.TagEviMap[i].CreatedAt,
				"updated_at":  seed.TagEviMap[i].UpdatedAt,
			}
		})
		tx.BatchInsert("queries", len(seed.Queries), func(i int) map[string]interface{} {
			return map[string]interface{}{
				"id":           seed.Queries[i].ID,
				"operation_id": seed.Queries[i].OperationID,
				"name":         seed.Queries[i].Name,
				"query":        seed.Queries[i].Query,
				"type":         seed.Queries[i].Type,
				"created_at":   seed.Queries[i].CreatedAt,
				"updated_at":   seed.Queries[i].UpdatedAt,
			}
		})
	})
	return err
}
ApplyTo takes the configured Seeder and writes these values to the database.
package seeding
import (
	"context"
	"strings"
	"time"
	localConsts "github.com/theparanoids/ashirt-server/backend/authschemes/localauth/constants"
	"github.com/theparanoids/ashirt-server/backend/database"
	"github.com/theparanoids/ashirt-server/backend/logging"
	"github.com/theparanoids/ashirt-server/backend/models"
	"github.com/theparanoids/ashirt-server/backend/policy"
	"golang.org/x/crypto/bcrypt"
)
type Seeder struct {
	FindingCategories []models.FindingCategory
	APIKeys           []models.APIKey
	Findings          []models.Finding
	Evidences         []models.Evidence
	Users             []models.User
	Operations        []models.Operation
	Tags              []models.Tag
	UserOpMap         []models.UserOperationPermission
	TagEviMap         []models.TagEvidenceMap
	EviFindingsMap    []models.EvidenceFindingMap
	Queries           []models.Query
}
func (seed Seeder) AllInitialTagIds() []int64 {
	return TagIDsFromTags(seed.Tags...)
}