Skip to content

Commit e8ad3ec

Browse files
committed
create channel parent/child relationship when importing parent
Signed-off-by: Ricardo Mateus <[email protected]>
1 parent 22da837 commit e8ad3ec

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

entityDumper/channelDataDumper.go

+18
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ func processChannel(db *sql.DB, writer *bufio.Writer, channelLabel string,
233233
tableData, printOptions)
234234
log.Debug().Msg("finished print table order")
235235

236+
generateChannelChildLink(db, channelLabel, writer)
237+
236238
generateCacheCalculation(channelLabel, writer)
237239

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

244246
}
245247

248+
func generateChannelChildLink(db *sql.DB, channelLabel string, writer *bufio.Writer) {
249+
childrenChannels := sqlUtil.ExecuteQueryWithResults(db, childChannelSql, channelLabel)
250+
childChannelChildLabels := make([]string, 0)
251+
for _, cChannel := range childrenChannels {
252+
cLabel := fmt.Sprintf("'%v'", cChannel[0].Value)
253+
fmt.Println(cLabel)
254+
childChannelChildLabels = append(childChannelChildLabels, cLabel)
255+
}
256+
257+
// recreate the relationship to child channels if any
258+
if len(childChannelChildLabels) > 0 {
259+
updateChildChannels := fmt.Sprintf("update rhnchannel set parent_channel = (select id from rhnchannel where label = '%s') where label in (%s);", channelLabel, strings.Join(childChannelChildLabels, ","))
260+
writer.WriteString(updateChildChannels + "\n")
261+
}
262+
}
263+
246264
func generateCacheCalculation(channelLabel string, writer *bufio.Writer) {
247265
// need to update channel modify since it's use to run repo metadata generation
248266
updateChannelModifyDate := fmt.Sprintf("update rhnchannel set modified = current_timestamp where label = '%s';", channelLabel)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- create channel parent/child relationship when importing parent

0 commit comments

Comments
 (0)