in cmd/apply_comments.go [43:67]
func runApplyComments(cmd *cobra.Command, sqlFilePath string, db *database.DB) error {
dbConfig := database.GetConfig()
if dbConfig == nil {
return fmt.Errorf("database config is not initialized")
}
//Set default input file if not provided
inputFile := sqlFilePath // Use the function parameter
if inputFile == "" {
inputFile = fmt.Sprintf("%s_comments.sql", dbConfig.DBName) // Default input file name
}
log.Println("INFO: Starting apply-comments operation from file:", inputFile)
sqlStatements, err := utils.ReadSQLStatementsFromFile(inputFile)
if err != nil {
return fmt.Errorf("failed to read SQL statements from file: %w", err)
}
ctx := cmd.Context()
if execErr := db.ExecuteSQLStatements(ctx, sqlStatements); execErr != nil {
return fmt.Errorf("failed to apply comments from SQL file: %w", execErr)
}
log.Println("INFO: Apply comments operation completed")
return nil
}