Skip to content

Commit 31a709a

Browse files
committed
feat: resource type dependencies
Adds a new `TypeDependencies` method to the `Resource` interface that enables resources to declare a dependency on all resources of a given type without having to use specific IDs. This is useful for ensuring that a particular resource is only updated after all resources of a particular type have been updated, or that a particular resource should be updated any time a resource of a specific type is updated. This will be used for a pg_service.conf resource in a subsequent PR. PLAT-417
1 parent 1c79e0e commit 31a709a

36 files changed

Lines changed: 308 additions & 65 deletions

server/internal/database/instance_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func (r *InstanceResource) Dependencies() []resource.Identifier {
7171
return dependencies
7272
}
7373

74+
func (r *InstanceResource) TypeDependencies() []resource.Type {
75+
return nil
76+
}
77+
7478
func (r *InstanceResource) Refresh(ctx context.Context, rc *resource.Context) error {
7579
if err := r.updateConnectionInfo(ctx, rc); err != nil {
7680
return resource.ErrNotFound

server/internal/database/lag_tracker_commit_ts_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (r *LagTrackerCommitTimestampResource) Dependencies() []resource.Identifier
6262
return deps
6363
}
6464

65+
func (r *LagTrackerCommitTimestampResource) TypeDependencies() []resource.Type {
66+
return nil
67+
}
68+
6569
func (r *LagTrackerCommitTimestampResource) Refresh(ctx context.Context, rc *resource.Context) error {
6670
// Connect to receiver node
6771
instance, err := GetPrimaryInstance(ctx, rc, r.ReceiverNode)

server/internal/database/node_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (n *NodeResource) Dependencies() []resource.Identifier {
5050
return dependencies
5151
}
5252

53+
func (n *NodeResource) TypeDependencies() []resource.Type {
54+
return nil
55+
}
56+
5357
func (n *NodeResource) Refresh(ctx context.Context, rc *resource.Context) error {
5458
if err := n.Create(ctx, rc); err != nil {
5559
return err

server/internal/database/operations/helpers_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ func (r *orchestratorResource) Dependencies() []resource.Identifier {
131131
return nil
132132
}
133133

134+
func (r *orchestratorResource) TypeDependencies() []resource.Type {
135+
return nil
136+
}
137+
134138
func (r *orchestratorResource) Refresh(ctx context.Context, rc *resource.Context) error {
135139
return nil
136140
}

server/internal/database/replication_slot_advance_from_cts_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func (r *ReplicationSlotAdvanceFromCTSResource) Dependencies() []resource.Identi
5151
}
5252
}
5353

54+
func (r *ReplicationSlotAdvanceFromCTSResource) TypeDependencies() []resource.Type {
55+
return nil
56+
}
57+
5458
func (r *ReplicationSlotAdvanceFromCTSResource) Refresh(ctx context.Context, rc *resource.Context) error {
5559
return nil
5660
}

server/internal/database/replication_slot_create_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func (r *ReplicationSlotCreateResource) Dependencies() []resource.Identifier {
4747
}
4848
}
4949

50+
func (r *ReplicationSlotCreateResource) TypeDependencies() []resource.Type {
51+
return nil
52+
}
53+
5054
func (r *ReplicationSlotCreateResource) Refresh(ctx context.Context, rc *resource.Context) error {
5155
instance, err := GetPrimaryInstance(ctx, rc, r.ProviderNode)
5256
if err != nil {

server/internal/database/replication_slot_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (r *ReplicationSlotResource) Dependencies() []resource.Identifier {
5252
}
5353
}
5454

55+
func (r *ReplicationSlotResource) TypeDependencies() []resource.Type {
56+
return nil
57+
}
58+
5559
func (r *ReplicationSlotResource) Refresh(ctx context.Context, rc *resource.Context) error {
5660
return nil
5761
}

server/internal/database/subscription_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func (s *SubscriptionResource) Dependencies() []resource.Identifier {
6161
return deps
6262
}
6363

64+
func (s *SubscriptionResource) TypeDependencies() []resource.Type {
65+
return nil
66+
}
67+
6468
func (s *SubscriptionResource) Refresh(ctx context.Context, rc *resource.Context) error {
6569
subscriber, err := GetPrimaryInstance(ctx, rc, s.SubscriberNode)
6670
if err != nil {

server/internal/database/switchover_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (s *SwitchoverResource) Dependencies() []resource.Identifier {
5252
}
5353
}
5454

55+
func (s *SwitchoverResource) TypeDependencies() []resource.Type {
56+
return nil
57+
}
58+
5559
func (s *SwitchoverResource) Refresh(ctx context.Context, rc *resource.Context) error {
5660
if !rc.State.HasResources(s.Dependencies()...) {
5761
return resource.ErrNotFound

server/internal/database/sync_event_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (r *SyncEventResource) Dependencies() []resource.Identifier {
5252
return deps
5353
}
5454

55+
func (r *SyncEventResource) TypeDependencies() []resource.Type {
56+
return nil
57+
}
58+
5559
// Confirm synchronization by sending sync_event from provider and waiting for it on subscriber
5660
func (r *SyncEventResource) Refresh(ctx context.Context, rc *resource.Context) error {
5761
// Get provider instance

0 commit comments

Comments
 (0)