Sql Flush command implementation to be used in tests, local tests for tutorial data

This commit is contained in:
DanB
2014-08-05 01:09:05 +02:00
parent ac3bbfe5a2
commit 33e3f3fd66
8 changed files with 162 additions and 10 deletions

View File

@@ -34,8 +34,5 @@ func NewMySQLStorage(host, port, name, user, password string) (Storage, error) {
if err != nil {
return nil, err
}
/*if err := db.Ping(); err != nil {
return nil, err
}*/
return &MySQLStorage{&SQLStorage{db}}, nil
}

View File

@@ -24,12 +24,14 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"path"
"strconv"
"strings"
"time"
"github.com/go-sql-driver/mysql"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
@@ -42,7 +44,18 @@ func (self *SQLStorage) Close() {
}
func (self *SQLStorage) Flush() (err error) {
return
cfg := config.CgrConfig()
for _, scriptName := range []string{CREATE_CDRS_TABLES_SQL, CREATE_TARIFFPLAN_TABLES_SQL} {
if err := self.CreateTablesFromScript(path.Join(cfg.DataFolderPath, "storage", "mysql", scriptName)); err != nil {
return err
}
}
for _, tbl := range []string{utils.TBL_CDRS_PRIMARY, utils.TBL_CDRS_EXTRA} {
if _, err := self.Db.Query(fmt.Sprintf("SELECT 1 from %s", tbl)); err != nil {
return err
}
}
return nil
}
func (self *SQLStorage) CreateTablesFromScript(scriptPath string) error {