Skip to content

Commit 3367045

Browse files
committed
feat(store): persist instance Source for engine-routed teardown
1 parent 36ade42 commit 3367045

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

store/mongo/models.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,22 @@ func fromTenantModel(m *tenantModel) *admin.Tenant {
6969
type instanceModel struct {
7070
grove.BaseModel `grove:"table:cp_instances"`
7171

72-
ID string `bson:"_id" grove:"id,pk"`
73-
TenantID string `bson:"tenant_id" grove:"tenant_id"`
74-
Slug string `bson:"slug" grove:"slug"`
75-
Name string `bson:"name" grove:"name"`
76-
State string `bson:"state" grove:"state"`
77-
ProviderName string `bson:"provider_name" grove:"provider_name"`
78-
ProviderRef string `bson:"provider_ref,omitempty" grove:"provider_ref"`
79-
Region string `bson:"region,omitempty" grove:"region"`
80-
Kind string `bson:"kind,omitempty" grove:"kind"`
81-
Services []provider.ServiceSpec `bson:"services,omitempty" grove:"services"`
82-
ServiceRefs map[string]string `bson:"service_refs,omitempty" grove:"service_refs"`
83-
Endpoints []endpointModel `bson:"endpoints,omitempty" grove:"endpoints"`
84-
Labels map[string]string `bson:"labels,omitempty" grove:"labels"`
85-
CreatedAt time.Time `bson:"created_at" grove:"created_at"`
86-
UpdatedAt time.Time `bson:"updated_at" grove:"updated_at"`
72+
ID string `bson:"_id" grove:"id,pk"`
73+
TenantID string `bson:"tenant_id" grove:"tenant_id"`
74+
Slug string `bson:"slug" grove:"slug"`
75+
Name string `bson:"name" grove:"name"`
76+
State string `bson:"state" grove:"state"`
77+
ProviderName string `bson:"provider_name" grove:"provider_name"`
78+
ProviderRef string `bson:"provider_ref,omitempty" grove:"provider_ref"`
79+
Region string `bson:"region,omitempty" grove:"region"`
80+
Kind string `bson:"kind,omitempty" grove:"kind"`
81+
Services []provider.ServiceSpec `bson:"services,omitempty" grove:"services"`
82+
ServiceRefs map[string]string `bson:"service_refs,omitempty" grove:"service_refs"`
83+
Endpoints []endpointModel `bson:"endpoints,omitempty" grove:"endpoints"`
84+
Labels map[string]string `bson:"labels,omitempty" grove:"labels"`
85+
Source provider.DeploymentSource `bson:"source,omitempty"`
86+
CreatedAt time.Time `bson:"created_at" grove:"created_at"`
87+
UpdatedAt time.Time `bson:"updated_at" grove:"updated_at"`
8788
}
8889

8990
// endpointModel is the bson form of provider.Endpoint.
@@ -110,6 +111,7 @@ func toInstanceModel(inst *instance.Instance) *instanceModel {
110111
ServiceRefs: inst.ServiceRefs,
111112
Endpoints: toEndpointModels(inst.Endpoints),
112113
Labels: inst.Labels,
114+
Source: inst.Source,
113115
CreatedAt: inst.CreatedAt,
114116
UpdatedAt: inst.UpdatedAt,
115117
}
@@ -134,6 +136,7 @@ func fromInstanceModel(m *instanceModel) *instance.Instance {
134136
ServiceRefs: m.ServiceRefs,
135137
Endpoints: fromEndpointModels(m.Endpoints),
136138
Labels: m.Labels,
139+
Source: m.Source,
137140
}
138141

139142
return out

store/postgres/models.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type instanceModel struct {
5454
Config []byte `grove:"config,type:jsonb"`
5555
Metadata []byte `grove:"metadata,type:jsonb"`
5656
Endpoints []byte `grove:"endpoints,type:jsonb"`
57+
Source []byte `grove:"source,type:jsonb"`
5758
CreatedAt time.Time `grove:"created_at,notnull"`
5859
UpdatedAt time.Time `grove:"updated_at,notnull"`
5960
}
@@ -300,6 +301,7 @@ func toInstanceModel(inst *instance.Instance) *instanceModel {
300301
ServiceRefs: marshalJSONB(inst.ServiceRefs),
301302
Labels: marshalJSONB(inst.Labels),
302303
Endpoints: marshalJSONB(inst.Endpoints),
304+
Source: marshalJSONB(inst.Source),
303305
CreatedAt: inst.CreatedAt,
304306
UpdatedAt: inst.UpdatedAt,
305307
}
@@ -326,6 +328,7 @@ func fromInstanceModel(m *instanceModel) *instance.Instance {
326328
unmarshalJSONB(m.ServiceRefs, &out.ServiceRefs)
327329
unmarshalJSONB(m.Labels, &out.Labels)
328330
unmarshalJSONB(m.Endpoints, &out.Endpoints)
331+
unmarshalJSONB(m.Source, &out.Source)
329332

330333
return out
331334
}

store/sqlite/models.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type instanceModel struct {
5454
Endpoints []byte `grove:"endpoints"`
5555
Config []byte `grove:"config"`
5656
Metadata []byte `grove:"metadata"`
57+
Source []byte `grove:"source"`
5758
CreatedAt time.Time `grove:"created_at,notnull"`
5859
UpdatedAt time.Time `grove:"updated_at,notnull"`
5960
}
@@ -300,6 +301,7 @@ func toInstanceModel(inst *instance.Instance) *instanceModel {
300301
ServiceRefs: marshalJSON(inst.ServiceRefs),
301302
Labels: marshalJSON(inst.Labels),
302303
Endpoints: marshalJSON(inst.Endpoints),
304+
Source: marshalJSON(inst.Source),
303305
CreatedAt: inst.CreatedAt,
304306
UpdatedAt: inst.UpdatedAt,
305307
}
@@ -326,6 +328,7 @@ func fromInstanceModel(m *instanceModel) *instance.Instance {
326328
unmarshalJSON(m.ServiceRefs, &out.ServiceRefs)
327329
unmarshalJSON(m.Labels, &out.Labels)
328330
unmarshalJSON(m.Endpoints, &out.Endpoints)
331+
unmarshalJSON(m.Source, &out.Source)
329332

330333
return out
331334
}

0 commit comments

Comments
 (0)