Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add settings to drop table #459

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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