-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ar adm 52 add audio source type to cu types (#51)
* add type * create CU fror source * add validator * use source uid for cu uid * add to source link cu type source * fix testes * fix load cu * remove test file * after code review * fetch cu translation from source * move get i18n from source to client * code review changes * rename * fix * remove artefacts * use same uid for source and CU * use uid * filter parents sources * remove secure from create CU * create diff object * remove multi thread * compere data from .tar with data from DB and with data from file storage (Shirai) * fix test
- Loading branch information
Showing
11 changed files
with
462 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/Bnei-Baruch/mdb/importer/cusource" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var buildCUSourcesCmd = &cobra.Command{ | ||
Use: "cu_sources", | ||
Short: "Build audio_sources units", | ||
Run: buildCUSourcesCmdFn, | ||
} | ||
|
||
var buildCUSourcesValidatorCmd = &cobra.Command{ | ||
Use: "cu_sources_validator", | ||
Short: "Validate script audio_sources units", | ||
Run: buildCUSourcesValidatorCmdFn, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(buildCUSourcesCmd) | ||
RootCmd.AddCommand(buildCUSourcesValidatorCmd) | ||
} | ||
|
||
func buildCUSourcesCmdFn(cmd *cobra.Command, args []string) { | ||
cusource.InitBuildCUSources() | ||
} | ||
|
||
func buildCUSourcesValidatorCmdFn(cmd *cobra.Command, args []string) { | ||
new(cusource.ComparatorDbVsFolder).Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,3 @@ func StdLang(lang string) string { | |
|
||
return LANG_UNKNOWN | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,10 @@ consumer-secret="" | |
url="https://www.laitman.ru/" | ||
username="" | ||
password="" | ||
|
||
|
||
[source-import] | ||
source-dir = "/home/david/Downloads/sources.tar.gz" | ||
test-url = "postgres://mdb_dev:[email protected]/mdb_dev_2?sslmode=disable" | ||
output = "/home/david/Downloads/validation-results.csv" | ||
dont-remove-dir = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cusource | ||
|
||
import ( | ||
"database/sql" | ||
"encoding/json" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
"github.com/volatiletech/sqlboiler/boil" | ||
"github.com/volatiletech/sqlboiler/queries" | ||
"github.com/volatiletech/sqlboiler/queries/qm" | ||
"gopkg.in/volatiletech/null.v6" | ||
|
||
"github.com/Bnei-Baruch/mdb/common" | ||
"github.com/Bnei-Baruch/mdb/models" | ||
"github.com/Bnei-Baruch/mdb/utils" | ||
) | ||
|
||
func BuildCUSources(mdb *sql.DB) ([]*models.Source, []*models.ContentUnit) { | ||
|
||
rows, err := queries.Raw(mdb, | ||
`SELECT cu.properties->>'source_id' FROM content_units cu WHERE cu.type_id = $1`, | ||
common.CONTENT_TYPE_REGISTRY.ByName[common.CT_SOURCE].ID, | ||
).Query() | ||
|
||
utils.Must(err) | ||
defer rows.Close() | ||
ids := make([]int64, 0) | ||
for rows.Next() { | ||
var id int64 | ||
err := rows.Scan(&id) | ||
utils.Must(err) | ||
ids = append(ids, id) | ||
} | ||
mods := make([]qm.QueryMod, 0) | ||
if len(ids) > 0 { | ||
mods = append(mods, qm.WhereIn("uid NOT IN ?", utils.ConvertArgsInt64(ids)...)) | ||
} | ||
|
||
sources, err := models.Sources(mdb, mods...).All() | ||
utils.Must(err) | ||
|
||
for _, s := range sources { | ||
isParent := false | ||
for _, sl := range sources { | ||
if sl.ParentID.Int64 == s.ID { | ||
isParent = true | ||
} | ||
} | ||
if isParent { | ||
continue | ||
} | ||
_, err := createCU(s, mdb) | ||
if err != nil { | ||
log.Debug("Duplicate create CU", err) | ||
} | ||
} | ||
return sources, nil | ||
} | ||
|
||
func createCU(s *models.Source, mdb boil.Executor) (*models.ContentUnit, error) { | ||
props, _ := json.Marshal(map[string]string{"source_id": s.UID}) | ||
cu := &models.ContentUnit{ | ||
UID: s.UID, | ||
TypeID: common.CONTENT_TYPE_REGISTRY.ByName[common.CT_SOURCE].ID, | ||
Published: true, | ||
Properties: null.JSONFrom(props), | ||
} | ||
|
||
err := cu.Insert(mdb) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cu, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cusource | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/Bnei-Baruch/mdb/common" | ||
"github.com/Bnei-Baruch/mdb/utils" | ||
"github.com/spf13/viper" | ||
"github.com/volatiletech/sqlboiler/boil" | ||
) | ||
|
||
func InitBuildCUSources() { | ||
mdb, err := sql.Open("postgres", viper.GetString("mdb.url")) | ||
defer mdb.Close() | ||
utils.Must(err) | ||
utils.Must(mdb.Ping()) | ||
boil.SetDB(mdb) | ||
boil.DebugMode = true | ||
utils.Must(common.InitTypeRegistries(mdb)) | ||
|
||
BuildCUSources(mdb) | ||
} |
Oops, something went wrong.