Skip to content

Commit

Permalink
create channel parent/child relationship when importing parent
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Mateus <[email protected]>
  • Loading branch information
rjmateus committed May 10, 2024
1 parent 22da837 commit c0a8acd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions entityDumper/channelDataDumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ func processChannel(db *sql.DB, writer *bufio.Writer, channelLabel string,
tableData, printOptions)
log.Debug().Msg("finished print table order")

generateChannelChildLink(db, channelLabel, writer)

generateCacheCalculation(channelLabel, writer)

if !options.MetadataOnly {
Expand All @@ -243,6 +245,22 @@ func processChannel(db *sql.DB, writer *bufio.Writer, channelLabel string,

}

func generateChannelChildLink(db *sql.DB, channelLabel string, writer *bufio.Writer) {
childrenChannels := sqlUtil.ExecuteQueryWithResults(db, childChannelSql, channelLabel)
childChannelChildLabels := make([]string, 0)
for _, cChannel := range childrenChannels {
cLabel := fmt.Sprintf("'%v'", cChannel[0].Value)
fmt.Println(cLabel)
childChannelChildLabels = append(childChannelChildLabels, cLabel)
}

// recreate the relationship to child channels if any
if len(childChannelChildLabels) > 0 {
updateChildChannels := fmt.Sprintf("update rhnchannel set parent_channel = (select id from rhnchannel where label = '%s') where label in (%s);", channelLabel, strings.Join(childChannelChildLabels, ","))
writer.WriteString(updateChildChannels + "\n")
}
}

func generateCacheCalculation(channelLabel string, writer *bufio.Writer) {
// need to update channel modify since it's use to run repo metadata generation
updateChannelModifyDate := fmt.Sprintf("update rhnchannel set modified = current_timestamp where label = '%s';", channelLabel)
Expand Down
1 change: 1 addition & 0 deletions inter-server-sync.changes.rmateus.main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- create channel parent/child relationship when importing parent

0 comments on commit c0a8acd

Please sign in to comment.