Skip to content

Commit

Permalink
🔨 fix: repair broken init_manuscript table selection (#82)
Browse files Browse the repository at this point in the history
* 🐛 Fix: fix database table selection

 This commit reworks and simplifies the selectTable() function in `init_manuscript.go` - this function was previously demonstrating problematic behavior by showing the same table set over and over regardless of which chain was selected.

* ⚰️ [chore] remove version from docker compose template

Per the repeated warning, docker compose does not require version specification in the template. I have removed that to get rid of the pesky warning.
  • Loading branch information
KagemniKarimu authored Dec 10, 2024
1 parent 5b8690e commit 5a36374
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
30 changes: 24 additions & 6 deletions commands/init_manuscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func InitManuscript() {
}

selectedChain, selectedDatabase := selectChain(chains, "🏂 3. Please select a chainbase network dataset from the list below: ", defaultDatabase)
selectedTable := selectTable(chains, selectedChain, "🧲 4. Please select a table from the list below: ", defaultTable)
selectedTable := selectTable(chains, selectedChain, defaultDatabase, "🧲 4. Please select a table from the list below: ", defaultTable)

outputChoice := promptOutputTarget()
fmt.Printf("\n\033[33m🏄🏄 Summary of your selections:\033[0m\n")
Expand Down Expand Up @@ -354,23 +354,41 @@ func selectChain(chains []*client.ChainBaseDatasetListItem, prompt, defaultChain
return chains[index-1].Name, chains[index-1].DatabaseName
}

func selectTable(chains []*client.ChainBaseDatasetListItem, selectedChain, prompt, defaultTable string) string {
defaultChainIndex := 1
func selectTable(chains []*client.ChainBaseDatasetListItem, selectedChain, defaultChain, prompt, defaultTable string) string {
fmt.Println("\r\033[33m" + prompt + "\u001B[0m")
for i, table := range chains[defaultChainIndex].Tables {

// Find the chain in the list
var chainIndex int
for i, chain := range chains {
if chain.Name == selectedChain || chain.DatabaseName == selectedChain {
chainIndex = i
break
}
}

// Display available tables
availableTables := chains[chainIndex].Tables
for i, table := range availableTables {
fmt.Printf("%d: %s\n", i+1, table)
}

// Prompt user for table choice
tableChoice := promptInput("Enter your choice(default is blocks)\u001B[0m: ", "")
if tableChoice == "" {
fmt.Printf("\u001B[32m✓ Defaulting to table: %s\u001B[0m\n\n", defaultTable)
return defaultTable
}

// Validate user input
index, err := strconv.Atoi(tableChoice)
if err != nil || index < 1 || index > len(chains[defaultChainIndex].Tables) {
if err != nil || index < 1 || index > len(availableTables) {
fmt.Printf("Invalid choice. Defaulting to table: %s\n", defaultTable)
return defaultTable
}
tableName := chains[defaultChainIndex].Tables[index-1]

// Return selected table
tableName := availableTables[index-1]
// Handle special case if transaction logs is selected
if tableName == "transactionLogs" {
tableName = "transaction_logs"
}
Expand Down
4 changes: 1 addition & 3 deletions static/docker_compose_template.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package static

var DockerComposeTemplate = `
version: '3.2'
name: {{.Name}}
services:
jobmanager:
jobmanager:
image: repository.chainbase.com/manuscript-node/manuscript-node:latest
user: "flink"
command: "standalone-job --job-classname com.chainbase.manuscript.ETLProcessor /opt/flink/manuscript.yaml --fromSavepoint /opt/flink/savepoint"
Expand Down Expand Up @@ -37,7 +36,6 @@ networks:
ms_network:`

var DockerComposeWithPostgresqlContent = `
version: '3.2'
name: {{.Name}}
services:
jobmanager:
Expand Down

0 comments on commit 5a36374

Please sign in to comment.