func createTable(db *sql.DB, dataType string) (err error) {
	table, err := whatTable(dataType)
	if err != nil {
		return err
	}
	_, err = db.Exec(createTableMap[table])
	if err != nil {
		return errors.Wrapf(err, "erro ao criar tabela '%s'", table)
	}
	err = createIndexes(db, table)
	if err != nil {
		return errors.Wrap(err, "erro ao criar índice para table "+table)
	}
	if strings.ToUpper(dataType) == "STATUS" {
		return nil
	}
	version := currentDbVersion
	switch dataType {
	case "fii_details":
		version = currentFIIDbVersion
	case "fii_dividends":
		version = currentFIIDbVersion
	case "stock_codes":
		version = currentStockCodesVersion
	case "stock_quotes":
		version = currentStockQuotesVersion
	}
	_, err = db.Exec(fmt.Sprintf(`INSERT OR REPLACE INTO status (table_name, version) VALUES ("%s",%d)`, table, version))
	if err != nil {
		return errors.Wrap(err, "erro ao atualizar tabela "+table)
	}
	return nil
}
createTable creates the table if not created yet
package parsers
import (
	"database/sql"
	"fmt"
	"strings"
	"github.com/pkg/errors"
)
const currentDbVersion = 210514
const currentFIIDbVersion = 210426
const currentStockCodesVersion = 210518
const currentStockQuotesVersion = 210305
var createTableMap = map[string]string{
	"dfp": `CREATE TABLE IF NOT EXISTS dfp
	(
		"ID" PRIMARY KEY,
		"ID_CIA" integer,
		"CODE" integer,
		"YEAR" string,
		"DATA_TYPE" string,
		"VERSAO" integer,
		"MOEDA" varchar(4),
		"ESCALA_MOEDA" varchar(7),
		"DT_FIM_EXERC" integer,
		"CD_CONTA" varchar(18),
		"DS_CONTA" varchar(100),
		"VL_CONTA" real
	);`,
	"itr": `CREATE TABLE IF NOT EXISTS itr
	(
		"ID" PRIMARY KEY,
		"ID_CIA" integer,
		"CODE" integer,
		"YEAR" string,
		"DATA_TYPE" string,
		"VERSAO" integer,
		"MOEDA" varchar(4),
		"ESCALA_MOEDA" varchar(7),
		"DT_FIM_EXERC" integer,
		"CD_CONTA" varchar(18),
		"DS_CONTA" varchar(100),
		"VL_CONTA" real
	);`,
	"fre": `CREATE TABLE IF NOT EXISTS fre
	(
		"ID" PRIMARY KEY,
		"ID_CIA" integer,
		"YEAR" string,
		"Versao" integer,
		"Quantidade_Total_Acoes_Circulacao" integer,
		"Percentual_Total_Acoes_Circulacao" real
	);`,
	"codes": `CREATE TABLE IF NOT EXISTS codes
	(
		"CODE" INTEGER NOT NULL PRIMARY KEY,
		"NAME" varchar(100)
	);`,
	"companies": `CREATE TABLE IF NOT EXISTS companies
	(
		"ID" INTEGER NOT NULL PRIMARY KEY,
		"CNPJ" varchar(20),
		"NAME" varchar(100)
	);`,
	"stock_codes": `CREATE TABLE IF NOT EXISTS stock_codes
	(
		"trading_code"  VARCHAR NOT NULL PRIMARY KEY,
		"company_name"  VARCHAR,
		"SpcfctnCd"     VARCHAR,
		"CorpGovnLvlNm" VARCHAR
	);`,
	"md5": `CREATE TABLE IF NOT EXISTS md5
	(
		md5 NOT NULL PRIMARY KEY
	);`,
	"fii_details": `CREATE TABLE IF NOT EXISTS fii_details
	(
		cnpj TEXT NOT NULL PRIMARY KEY,
		acronym varchar(4),
		trading_code varchar(6),
		json varchar
	);`,
	"stock_quotes": `CREATE TABLE IF NOT EXISTS stock_quotes
	(
		stock varchar(12) NOT NULL,
		date   varchar(10) NOT NULL,
		open   real,
		high   real,
		low    real,
		close  real,
		volume real
	);`,
	"fii_dividends": `CREATE TABLE IF NOT EXISTS fii_dividends
	(
		trading_code varchar(12) NOT NULL, 
		base_date varchar(10) NOT NULL, 
		payment_date varchar(10), 
		value real
	);`,
	"status": `CREATE TABLE IF NOT EXISTS status
	(
		table_name TEXT NOT NULL PRIMARY KEY,
		version integer
	);`,
}
func allTables() []string {
	keys := make([]string, len(createTableMap))
	i := 0
	for k := range createTableMap {
		keys[i] = k
		i++
	}
	return keys
}
func whatTable(dataType string) (table string, err error) {
	switch dataType {
	case "dfp", "BPA", "BPP", "DRE", "DFC_MD", "DFC_MI", "DVA":
		table = "dfp"
	case "itr", "BPA_ITR", "BPP_ITR", "DRE_ITR", "DFC_MD_ITR", "DFC_MI_ITR", "DVA_ITR":
		table = "itr"
	case "fre", "FRE":
		table = "fre"
	case "codes", "CODES":
		table = "codes"
	case "md5", "MD5":
		table = "md5"
	case "status", "STATUS":
		table = "status"
	case "companies", "COMPANIES":
		table = "companies"
	case "fii_details":
		table = dataType
	case "fii_dividends":
		table = dataType
	case "stock_codes":
		table = dataType
	case "stock_quotes":
		table = dataType
	default:
		return "", errors.Wrapf(err, "tipo de informação inexistente: %s", dataType)
	}
	return
}