Skip to content

Commit

Permalink
drop tables for cassandra
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Nov 7, 2024
1 parent 7465af6 commit f35e0e5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions cmd/migrate-curio/yugabyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var cleanupYugabyteDBCmd = &cli.Command{

keyspace := "idx"

// Step 1: Drop all indexes
// Drop all indexes
var indexName string
indexesQuery := fmt.Sprintf("SELECT index_name FROM system_schema.indexes WHERE keyspace_name='%s';", keyspace)
iter := session.Query(indexesQuery).Iter()
Expand All @@ -88,7 +88,27 @@ var cleanupYugabyteDBCmd = &cli.Command{
return fmt.Errorf("failed to iterate over indexes: %w", err)
}

// Step 2: Drop the keyspace
// Query to get all tables in the 'idx' keyspace
iter = session.Query(`SELECT table_name FROM system_schema.tables WHERE keyspace_name='%s';`, keyspace).Iter()

var tableName string
for iter.Scan(&tableName) {
dropQuery := fmt.Sprintf("DROP TABLE idx.%s", tableName)
fmt.Println("Executing:", dropQuery)

err := session.Query(dropQuery).Exec()
if err != nil {
return fmt.Errorf("failed to drop table %s: %w", tableName, err)
}
}

if err := iter.Close(); err != nil {
return fmt.Errorf("error closing iterator: %v", err)
}

fmt.Println("All tables in keyspace 'idx' have been dropped.")

// Drop the keyspace
dropKeyspaceQuery := fmt.Sprintf("DROP KEYSPACE %s;", keyspace)
fmt.Println("Executing:", dropKeyspaceQuery)
if err := session.Query(dropKeyspaceQuery).Exec(); err != nil {
Expand Down

0 comments on commit f35e0e5

Please sign in to comment.