Skip to content

Commit 4963afc

Browse files
committed
drop tables for cassandra
1 parent 7465af6 commit 4963afc

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

cmd/migrate-curio/yugabyte.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var cleanupYugabyteDBCmd = &cli.Command{
7272

7373
keyspace := "idx"
7474

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

91-
// Step 2: Drop the keyspace
91+
// Query to get all tables in the 'idx' keyspace
92+
tableQuesry := fmt.Sprintf(`SELECT table_name FROM system_schema.tables WHERE keyspace_name='%s';`, keyspace)
93+
iter = session.Query(tableQuesry).Iter()
94+
95+
var tableName string
96+
for iter.Scan(&tableName) {
97+
dropQuery := fmt.Sprintf("DROP TABLE idx.%s", tableName)
98+
fmt.Println("Executing:", dropQuery)
99+
100+
err := session.Query(dropQuery).Exec()
101+
if err != nil {
102+
return fmt.Errorf("failed to drop table %s: %w", tableName, err)
103+
}
104+
}
105+
106+
if err := iter.Close(); err != nil {
107+
return fmt.Errorf("error closing iterator: %v", err)
108+
}
109+
110+
fmt.Println("All tables in keyspace 'idx' have been dropped.")
111+
112+
// Drop the keyspace
92113
dropKeyspaceQuery := fmt.Sprintf("DROP KEYSPACE %s;", keyspace)
93114
fmt.Println("Executing:", dropKeyspaceQuery)
94115
if err := session.Query(dropKeyspaceQuery).Exec(); err != nil {

0 commit comments

Comments
 (0)