Skip to content

Commit

Permalink
Adding scaffold.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 26, 2024
1 parent 1d0a2c0 commit fa31580
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type PostgreSQLTable struct {
OptionalPrimaryKeyValStart string `yaml:"optionalPrimaryKeyValStart,omitempty"`
OptionalPrimaryKeyValEnd string `yaml:"optionalPrimaryKeyValEnd,omitempty"`
ExcludeColumns []string `yaml:"excludeColumns,omitempty"`
// IncludeColumns - List of columns that should be included in the change event record.
IncludeColumns []string `yaml:"includeColumns,omitempty"`
}

func (p *PostgreSQLTable) GetBatchSize() uint {
Expand Down Expand Up @@ -99,6 +101,11 @@ func (p *PostgreSQL) Validate() error {
if table.Schema == "" {
return fmt.Errorf("schema must be passed in")
}

// You should not be able to filter and exclude columns at the same time
if len(table.ExcludeColumns) > 0 && len(table.IncludeColumns) > 0 {
return fmt.Errorf("cannot exclude and include columns at the same time")
}
}

return nil
Expand Down
20 changes: 20 additions & 0 deletions config/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ func TestPostgreSQL_Validate(t *testing.T) {

assert.ErrorContains(t, p.Validate(), "schema must be passed in")
}
{
// Filtering and excluding at the same time
p := &PostgreSQL{
Host: "host",
Port: 1,
Username: "username",
Password: "password",
Database: "database",
Tables: []*PostgreSQLTable{
{
Name: "name",
Schema: "schema",
ExcludeColumns: []string{"a"},
IncludeColumns: []string{"b"},
},
},
}

assert.ErrorContains(t, p.Validate(), "cannot exclude and include columns at the same time")
}
{
// Valid
p := &PostgreSQL{
Expand Down

0 comments on commit fa31580

Please sign in to comment.