Skip to content

Commit

Permalink
fix: add settings to drop table (#459)
Browse files Browse the repository at this point in the history
Add support for settings in drop table


FOR SigNoz/signoz#5713
  • Loading branch information
nityanandagohain authored Nov 20, 2024
1 parent 7829748 commit 37049dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/signozschemamigrator/schema_migrator/table_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type DropTableOperation struct {
cluster string
Database string
Table string
Settings TableSettings
}

func (d DropTableOperation) OnCluster(cluster string) Operation {
Expand Down Expand Up @@ -132,6 +133,10 @@ func (d DropTableOperation) ToSQL() string {
sql.WriteString(" ON CLUSTER ")
sql.WriteString(d.cluster)
}
if len(d.Settings) > 0 {
sql.WriteString(" SETTINGS ")
sql.WriteString(d.Settings.ToSQL())
}
return sql.String()
}

Expand Down
32 changes: 32 additions & 0 deletions cmd/signozschemamigrator/schema_migrator/table_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,38 @@ func TestCreateTable(t *testing.T) {
}
}

func TestDropTable(t *testing.T) {
testCases := []struct {
name string
op Operation
want string
}{
{
name: "drop-table",
op: DropTableOperation{
Database: "db",
Table: "table",
},
want: "DROP TABLE IF EXISTS db.table",
},
{
name: "drop-table-with-settings",
op: DropTableOperation{
Database: "db",
Table: "table",
Settings: TableSettings{{Name: "max_table_size_to_drop", Value: "0"}},
},
want: "DROP TABLE IF EXISTS db.table SETTINGS max_table_size_to_drop = 0",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.want, tc.op.ToSQL())
})
}
}

func TestCreateMaterializedView(t *testing.T) {
testCases := []struct {
name string
Expand Down

0 comments on commit 37049dc

Please sign in to comment.