if (!exists("SomLivre"))
# ------
   SomLivre <- data.table(structure(list(artist = structure(c(1L, 2L, 5L, 3L, 6L, 7L, 4L), .Label = c("Arsenic", "Baia", "Dom La Nena", "Gabriel Moura","Jesulton", "Tereza", "Tiago Iorc"), class = "factor"), upc = c("7891430261023","7891430289621", "7891430260125", "7891430298326", "7891430296322","7891430290627", "7891430275921"), track = structure(c(3L, 1L,6L, 5L, 2L, 4L, 7L), .Label = c("Com a certeza de quem nao sabe nada","Endorfinar", "Eu Quero (Foge Comigo)", "Musica Inedita", "No meu pais","Us", "Vou te Pegar"), class = "factor"), isrc = structure(c(4L,6L, 2L, 7L, 1L, 5L, 3L), .Label = c("BR77Z1300001", "BRRGE1200342","BRRGE1200466", "BRRGE1200471", "BRRGE1300015", "BRUR21300005","US6DR1201806"), class = "factor"), date = structure(c(15921,15770, 15731, 15745, 15971, 16047, 15902), class = "Date")), .Names = c("artist","upc", "track", "isrc", "date"), class = c("data.table", "data.frame"), row.names = c(NA, -7L))) 
# ------


## -------------------------------- ##
##         QUERY PARAMETERS         ##
## -------------------------------- ##
  RELEASE.DATES  <- TRUE ## Whether to also pull release dates from infinitDB
  TEST.RUN <-  FALSE # 15

  q.nm.prefx <- "SOTW_" # NULL


  useProduction <- TRUE  # FALSE
  schema <- NULL # "production"
  TBL <- "staging_raw_itunes"   

  colsToPull <- c("vendor_identifier", "upc", "isrc", "artist", "title", "record_company", 
                  "product_type_identifier", "units", "royalty_price", "download_date", 
                  "order_id", "postal_code", "customer_identifier", 
                  "sale_return", "customer_currency", "country_code", "royalty_currency", 
                  "preorder", "isan", "customer_price", "cma", "asset", 
                  "vendor_offer_code", "grid", "promo_code", "parent_id", "season_pass", 
                  "belongs_to_ioda", "attributable_purchase", "primary_genre")

  date_col <- "download_date" # "processedDayTime" 
  upc_col  <- "upc" #  if(grepl("itunes", TBL, ignore.case=TRUE)) "releaseId" else "upc"


  whereIn <- list(   upc = removeNA(SomLivre[, upc])
                  # , name = c("ex1", "ex2")
                 )
  names(whereIn)[names(whereIn) == "upc"] <- upc_col


  dateMin <- min(SomLivre[!is.na(get(upc_col)), date]) - 400
  dateMax <- NULL

  showWarnings = TRUE
  limit = NULL
## ------------------------------ ##

## ACTUAL VALUES FOR THIS RUN 
# TBLS.itunes <- c("production.staging_raw_itunes", "public.staging_raw_itunes", "production.staging_raw_itunes_test")
# TBL <- TBLS.itunes
# TEST.RUN    <- FALSE



