Skip to content

Commit

Permalink
chore: Remove the owner field
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Nenciarini <[email protected]>
  • Loading branch information
mnencia committed Oct 31, 2024
1 parent df39b69 commit 2165625
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 136 deletions.
4 changes: 0 additions & 4 deletions api/v1/publication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ type PublicationSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="dbname is immutable"
DBName string `json:"dbname"`

// The owner
// +optional
Owner string `json:"owner,omitempty"`

// Parameters
// +optional
Parameters map[string]string `json:"parameters,omitempty"`
Expand Down
4 changes: 0 additions & 4 deletions api/v1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ type SubscriptionSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
Name string `json:"name"`

// The owner
// +optional
Owner string `json:"owner,omitempty"`

// The name of the database
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="dbname is immutable"
DBName string `json:"dbname"`
Expand Down
3 changes: 0 additions & 3 deletions config/crd/bases/postgresql.cnpg.io_publications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ spec:
x-kubernetes-validations:
- message: name is immutable
rule: self == oldSelf
owner:
description: The owner
type: string
parameters:
additionalProperties:
type: string
Expand Down
3 changes: 0 additions & 3 deletions config/crd/bases/postgresql.cnpg.io_subscriptions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ spec:
x-kubernetes-validations:
- message: name is immutable
rule: self == oldSelf
owner:
description: The owner
type: string
parameters:
additionalProperties:
type: string
Expand Down
14 changes: 0 additions & 14 deletions docs/src/cloudnative-pg.v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4101,13 +4101,6 @@ the primary server of the cluster as part of rolling updates</p>
<p>The name of the database</p>
</td>
</tr>
<tr><td><code>owner</code><br/>
<i>string</i>
</td>
<td>
<p>The owner</p>
</td>
</tr>
<tr><td><code>parameters</code><br/>
<i>map[string]string</i>
</td>
Expand Down Expand Up @@ -5182,13 +5175,6 @@ Size cannot be decreased.</p>
<p>The name inside PostgreSQL</p>
</td>
</tr>
<tr><td><code>owner</code> <B>[Required]</B><br/>
<i>string</i>
</td>
<td>
<p>The owner</p>
</td>
</tr>
<tr><td><code>dbname</code> <B>[Required]</B><br/>
<i>string</i>
</td>
Expand Down
27 changes: 2 additions & 25 deletions internal/management/controller/publication_controller_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ func (r *PublicationReconciler) createPublication(
}

func toPublicationCreateSQL(obj *apiv1.Publication) []string {
result := make([]string, 0, 2)

createQuery := fmt.Sprintf(
"CREATE PUBLICATION %s %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
Expand All @@ -104,23 +102,12 @@ func toPublicationCreateSQL(obj *apiv1.Publication) []string {
if len(obj.Spec.Parameters) > 0 {
createQuery = fmt.Sprintf("%s WITH (%s)", createQuery, toPostgresParameters(obj.Spec.Parameters))
}
result = append(result, createQuery)

if len(obj.Spec.Owner) > 0 {
result = append(result,
fmt.Sprintf(
"ALTER PUBLICATION %s OWNER to %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
pgx.Identifier{obj.Spec.Owner}.Sanitize(),
),
)
}

return result
return []string{createQuery}
}

func toPublicationAlterSQL(obj *apiv1.Publication) []string {
result := make([]string, 0, 3)
result := make([]string, 0, 2)

if len(obj.Spec.Target.Objects) > 0 {
result = append(result,
Expand All @@ -132,16 +119,6 @@ func toPublicationAlterSQL(obj *apiv1.Publication) []string {
)
}

if len(obj.Spec.Owner) > 0 {
result = append(result,
fmt.Sprintf(
"ALTER PUBLICATION %s OWNER TO %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
pgx.Identifier{obj.Spec.Owner}.Sanitize(),
),
)
}

if len(obj.Spec.Parameters) > 0 {
result = append(result,
fmt.Sprintf(
Expand Down
26 changes: 0 additions & 26 deletions internal/management/controller/publication_controller_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ var _ = Describe("publication sql", func() {
Expect(sqls).To(ContainElement(`ALTER PUBLICATION "test_pub" SET TABLES IN SCHEMA "public"`))
})

It("generates correct SQL for altering publication with owner", func() {
obj := &apiv1.Publication{
Spec: apiv1.PublicationSpec{
Name: "test_pub",
Owner: "new_owner",
},
}

sqls := toPublicationAlterSQL(obj)
Expect(sqls).To(ContainElement(`ALTER PUBLICATION "test_pub" OWNER TO "new_owner"`))
})

It("generates correct SQL for altering publication with parameters", func() {
obj := &apiv1.Publication{
Spec: apiv1.PublicationSpec{
Expand Down Expand Up @@ -159,20 +147,6 @@ var _ = Describe("publication sql", func() {
Expect(sqls).To(ContainElement(`CREATE PUBLICATION "test_pub" FOR TABLE "test"."table" ("a", "b")`))
})

It("generates correct SQL for creating publication with owner", func() {
obj := &apiv1.Publication{
Spec: apiv1.PublicationSpec{
Name: "test_pub",
Owner: "new_owner",
Target: apiv1.PublicationTarget{AllTables: true},
},
}

sqls := toPublicationCreateSQL(obj)
Expect(sqls).To(ContainElement(`CREATE PUBLICATION "test_pub" FOR ALL TABLES`))
Expect(sqls).To(ContainElement(`ALTER PUBLICATION "test_pub" OWNER to "new_owner"`))
})

It("generates correct SQL for creating publication with parameters", func() {
obj := &apiv1.Publication{
Spec: apiv1.PublicationSpec{
Expand Down
27 changes: 2 additions & 25 deletions internal/management/controller/subscription_controller_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ func (r *SubscriptionReconciler) createSubscription(
}

func toSubscriptionCreateSQL(obj *apiv1.Subscription, connString string) []string {
result := make([]string, 0, 2)

createQuery := fmt.Sprintf(
"CREATE SUBSCRIPTION %s CONNECTION %s PUBLICATION %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
Expand All @@ -112,23 +110,12 @@ func toSubscriptionCreateSQL(obj *apiv1.Subscription, connString string) []strin
if len(obj.Spec.Parameters) > 0 {
createQuery = fmt.Sprintf("%s WITH (%s)", createQuery, toPostgresParameters(obj.Spec.Parameters))
}
result = append(result, createQuery)

if len(obj.Spec.Owner) > 0 {
result = append(result,
fmt.Sprintf(
"ALTER SUBSCRIPTION %s OWNER TO %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
pgx.Identifier{obj.Spec.Owner}.Sanitize(),
),
)
}

return result
return []string{createQuery}
}

func toSubscriptionAlterSQL(obj *apiv1.Subscription, connString string) []string {
result := make([]string, 0, 4)
result := make([]string, 0, 3)

setPublicationSQL := fmt.Sprintf(
"ALTER SUBSCRIPTION %s SET PUBLICATION %s",
Expand All @@ -143,16 +130,6 @@ func toSubscriptionAlterSQL(obj *apiv1.Subscription, connString string) []string
)
result = append(result, setPublicationSQL, setConnStringSQL)

if len(obj.Spec.Owner) > 0 {
result = append(result,
fmt.Sprintf(
"ALTER SUBSCRIPTION %s OWNER TO %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
pgx.Identifier{obj.Spec.Owner}.Sanitize(),
),
)
}

if len(obj.Spec.Parameters) > 0 {
result = append(result,
fmt.Sprintf(
Expand Down
32 changes: 0 additions & 32 deletions internal/management/controller/subscription_controller_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,6 @@ var _ = Describe("subscription sql", func() {
Expect(sqls).To(ContainElement(expectedElement))
})

It("generates correct SQL for creating subscription with owner", func() {
obj := &apiv1.Subscription{
Spec: apiv1.SubscriptionSpec{
Name: "test_sub",
PublicationName: "test_pub",
Owner: "new_owner",
},
}
connString := "host=localhost user=test dbname=test"

sqls := toSubscriptionCreateSQL(obj, connString)
Expect(sqls).To(ContainElement(
`CREATE SUBSCRIPTION "test_sub" CONNECTION 'host=localhost user=test dbname=test' PUBLICATION "test_pub"`))
Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" OWNER TO "new_owner"`))
})

It("returns correct SQL for creating subscription with no owner or parameters", func() {
obj := &apiv1.Subscription{
Spec: apiv1.SubscriptionSpec{
Expand Down Expand Up @@ -150,22 +134,6 @@ var _ = Describe("subscription sql", func() {
Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" CONNECTION 'host=localhost user=test dbname=test'`))
})

It("generates correct SQL for altering subscription with owner", func() {
obj := &apiv1.Subscription{
Spec: apiv1.SubscriptionSpec{
Name: "test_sub",
PublicationName: "test_pub",
Owner: "new_owner",
},
}
connString := "host=localhost user=test dbname=test"

sqls := toSubscriptionAlterSQL(obj, connString)
Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" SET PUBLICATION "test_pub"`))
Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" CONNECTION 'host=localhost user=test dbname=test'`))
Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" OWNER TO "new_owner"`))
})

It("generates correct SQL for altering subscription with parameters", func() {
obj := &apiv1.Subscription{
Spec: apiv1.SubscriptionSpec{
Expand Down

0 comments on commit 2165625

Please sign in to comment.