Skip to content

Commit

Permalink
updates to use named strategies, updates the model mappings for the p…
Browse files Browse the repository at this point in the history
…erst layer'
  • Loading branch information
nickzelei committed Nov 1, 2024
1 parent e282c74 commit 6532258
Show file tree
Hide file tree
Showing 11 changed files with 2,000 additions and 1,726 deletions.
2,879 changes: 1,483 additions & 1,396 deletions backend/gen/go/protos/mgmt/v1alpha1/job.pb.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions backend/protos/mgmt/v1alpha1/job.proto
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ message PostgresSourceConnectionOptions {
message NewColumnAdditionStrategy {
oneof strategy {
// halt job if a new column is detected. This is equiavlent to the old halt_on_new_column_addition
bool halt_job = 1;
HaltJob halt_job = 1;
// neosync will automatically anonymize unmapped columns. View the docs page for details on this strategy
bool use_auto_map = 2;
AutoMap auto_map = 2;
// space for more discrete strategies in the future
}
message HaltJob {}
message AutoMap {}
}
}

Expand Down
69 changes: 65 additions & 4 deletions backend/sql/postgresql/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,50 @@ type MysqlSourceOptions struct {
ConnectionId string `json:"connectionId"`
}
type PostgresSourceOptions struct {
HaltOnNewColumnAddition bool `json:"haltOnNewColumnAddition"`
SubsetByForeignKeyConstraints bool `json:"subsetByForeignKeyConstraints"`
Schemas []*PostgresSourceSchemaOption `json:"schemas"`
ConnectionId string `json:"connectionId"`
// @deprecated
HaltOnNewColumnAddition bool `json:"haltOnNewColumnAddition"`
SubsetByForeignKeyConstraints bool `json:"subsetByForeignKeyConstraints"`
Schemas []*PostgresSourceSchemaOption `json:"schemas"`
ConnectionId string `json:"connectionId"`
NewColumnAdditionStrategy *PostgresNewColumnAdditionStrategy `json:"newColumnAdditionStrategy,omitempty"`
}

type PostgresNewColumnAdditionStrategy struct {
HaltJob *PostgresHaltJobStrategy `json:"haltJob,omitempty"`
AutoMap *PostgresAutoMapStrategy `json:"autoMap,omitempty"`
}

func (p *PostgresNewColumnAdditionStrategy) ToDto() *mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy {
if p.HaltJob != nil {
return &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy{
Strategy: &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_HaltJob_{
HaltJob: &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_HaltJob{},
},
}
} else if p.AutoMap != nil {
return &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy{
Strategy: &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_AutoMap_{
AutoMap: &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_AutoMap{},
},
}
}
return nil
}
func (p *PostgresNewColumnAdditionStrategy) FromDto(dto *mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy) {
if dto == nil {
dto = &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy{}
}
switch dto.GetStrategy().(type) {
case *mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_AutoMap_:
p.AutoMap = &PostgresAutoMapStrategy{}
case *mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_HaltJob_:
p.HaltJob = &PostgresHaltJobStrategy{}
}
}

type PostgresHaltJobStrategy struct{}
type PostgresAutoMapStrategy struct{}

type GenerateSourceOptions struct {
Schemas []*GenerateSourceSchemaOption `json:"schemas"`
FkSourceConnectionId *string `json:"fkSourceConnectionId,omitempty"`
Expand Down Expand Up @@ -1071,13 +1109,36 @@ func (s *PostgresSourceOptions) ToDto() *mgmtv1alpha1.PostgresSourceConnectionOp
}
}

if s.NewColumnAdditionStrategy != nil {
dto.NewColumnAdditionStrategy = s.NewColumnAdditionStrategy.ToDto()
}

if dto.NewColumnAdditionStrategy == nil && s.HaltOnNewColumnAddition {
// HaltOnNewColumnAddition is deprecated, so we are also populating the new strategy automatically to move the api forward
dto.NewColumnAdditionStrategy = &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy{
Strategy: &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_HaltJob_{
HaltJob: &mgmtv1alpha1.PostgresSourceConnectionOptions_NewColumnAdditionStrategy_HaltJob{},
},
}
}

return dto
}
func (s *PostgresSourceOptions) FromDto(dto *mgmtv1alpha1.PostgresSourceConnectionOptions) {
s.HaltOnNewColumnAddition = dto.HaltOnNewColumnAddition
s.SubsetByForeignKeyConstraints = dto.SubsetByForeignKeyConstraints
s.Schemas = FromDtoPostgresSourceSchemaOptions(dto.Schemas)
s.ConnectionId = dto.ConnectionId
if dto.GetNewColumnAdditionStrategy().GetStrategy() != nil {
s.NewColumnAdditionStrategy = &PostgresNewColumnAdditionStrategy{}
s.NewColumnAdditionStrategy.FromDto(dto.GetNewColumnAdditionStrategy())
} else if dto.GetHaltOnNewColumnAddition() {
// halt on new column addition is deprecated, so if the new column strat is nil but the deprecated value is true,

Check failure on line 1136 in backend/sql/postgresql/models/models.go

View workflow job for this annotation

GitHub Actions / golang-lint

`strat` is a misspelling of `start` (misspell)
// we are going to store it in the new strategy format.
s.NewColumnAdditionStrategy = &PostgresNewColumnAdditionStrategy{
HaltJob: &PostgresHaltJobStrategy{},
}
}
}

func FromDtoPostgresSourceSchemaOptions(dtos []*mgmtv1alpha1.PostgresSourceSchemaOption) []*PostgresSourceSchemaOption {
Expand Down
40 changes: 25 additions & 15 deletions docs/openapi/mgmt/v1alpha1/job.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3791,37 +3791,47 @@ components:
allOf:
- anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
- not:
anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
- not:
anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
properties:
haltJob:
type: boolean
title: halt_job
description: halt job if a new column is detected. This is equiavlent to the old halt_on_new_column_addition
useAutoMap:
type: boolean
title: use_auto_map
description: neosync will automatically anonymize unmapped columns. View the docs page for details on this strategy space for more discrete strategies in the future
allOf:
- title: halt_job
description: halt job if a new column is detected. This is equiavlent to the old halt_on_new_column_addition
- $ref: '#/components/schemas/mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.HaltJob'
autoMap:
allOf:
- title: auto_map
description: neosync will automatically anonymize unmapped columns. View the docs page for details on this strategy space for more discrete strategies in the future
- $ref: '#/components/schemas/mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.AutoMap'
title: NewColumnAdditionStrategy
additionalProperties: false
mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.AutoMap:
type: object
title: AutoMap
additionalProperties: false
mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.HaltJob:
type: object
title: HaltJob
additionalProperties: false
mgmt.v1alpha1.PostgresSourceSchemaOption:
type: object
properties:
Expand Down
52 changes: 32 additions & 20 deletions docs/openapi/neosync.mgmt.v1alpha1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10369,42 +10369,54 @@ components:
allOf:
- anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
- not:
anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
- not:
anyOf:
- required:
- haltJob
- autoMap
- required:
- useAutoMap
- haltJob
properties:
haltJob:
type: boolean
title: halt_job
description: >-
halt job if a new column is detected. This is equiavlent to the old
halt_on_new_column_addition
useAutoMap:
type: boolean
title: use_auto_map
description: >-
neosync will automatically anonymize unmapped columns. View the docs
page for details on this strategy space for more discrete strategies
in the future
allOf:
- title: halt_job
description: >-
halt job if a new column is detected. This is equiavlent to the
old halt_on_new_column_addition
- $ref: >-
#/components/schemas/mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.HaltJob
autoMap:
allOf:
- title: auto_map
description: >-
neosync will automatically anonymize unmapped columns. View the
docs page for details on this strategy space for more discrete
strategies in the future
- $ref: >-
#/components/schemas/mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.AutoMap
title: NewColumnAdditionStrategy
additionalProperties: false
mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.AutoMap:
type: object
title: AutoMap
additionalProperties: false
mgmt.v1alpha1.PostgresSourceConnectionOptions.NewColumnAdditionStrategy.HaltJob:
type: object
title: HaltJob
additionalProperties: false
mgmt.v1alpha1.PostgresSourceSchemaOption:
type: object
properties:
Expand Down
Loading

0 comments on commit 6532258

Please sign in to comment.