From efdbfb9428a7988e5cb0870817128f312ae3f5ff Mon Sep 17 00:00:00 2001 From: Elom Gomez Date: Tue, 1 Dec 2026 22:24:11 -0600 Subject: [PATCH 1/3] Add --multiple-admins-required-for-deletion to database update Co-Authored-By: Claude Opus 5.5 --- internal/cmd/database/database.go | 59 +++++++++++----------- internal/cmd/database/update.go | 28 ++++++----- internal/cmd/database/update_test.go | 3 ++ internal/planetscale/databases.go | 68 +++++++++++++------------- internal/planetscale/databases_test.go | 28 ++++++----- 5 files changed, 101 insertions(+), 85 deletions(-) diff --git a/internal/cmd/database/database.go b/internal/cmd/database/database.go index dd76de3c2..13ef14727 100644 --- a/internal/cmd/database/database.go +++ b/internal/cmd/database/database.go @@ -64,21 +64,22 @@ func (d *databaseListItem) MarshalCSVValue() interface{} { // Database is the human table for show/create/update, including settings. type Database struct { - Name string `header:"name" json:"name"` - Kind string `header:"kind" json:"kind"` - DefaultBranch string `header:"default_branch" json:"default_branch"` - RequireApprovalForDeploy bool `header:"require_approval_for_deploy" json:"require_approval_for_deploy"` - RestrictBranchRegion bool `header:"restrict_branch_region" json:"restrict_branch_region"` - AllowDataBranching bool `header:"allow_data_branching" json:"allow_data_branching"` - ForeignKeysEnabled bool `header:"foreign_keys_enabled" json:"foreign_keys_enabled"` - AutomaticMigrations string `header:"automatic_migrations" json:"automatic_migrations"` - MigrationFramework string `header:"migration_framework" json:"migration_framework"` - MigrationTableName string `header:"migration_table_name" json:"migration_table_name"` - InsightsRawQueries bool `header:"insights_raw_queries" json:"insights_raw_queries"` - InsightsEnabled bool `header:"insights_enabled" json:"insights_enabled"` - ProductionBranchWebConsole bool `header:"production_branch_web_console" json:"production_branch_web_console"` - CreatedAt int64 `header:"created_at,timestamp(ms|utc|human)" json:"created_at"` - UpdatedAt int64 `header:"updated_at,timestamp(ms|utc|human)" json:"updated_at"` + Name string `header:"name" json:"name"` + Kind string `header:"kind" json:"kind"` + DefaultBranch string `header:"default_branch" json:"default_branch"` + RequireApprovalForDeploy bool `header:"require_approval_for_deploy" json:"require_approval_for_deploy"` + RestrictBranchRegion bool `header:"restrict_branch_region" json:"restrict_branch_region"` + AllowDataBranching bool `header:"allow_data_branching" json:"allow_data_branching"` + ForeignKeysEnabled bool `header:"foreign_keys_enabled" json:"foreign_keys_enabled"` + AutomaticMigrations string `header:"automatic_migrations" json:"automatic_migrations"` + MigrationFramework string `header:"migration_framework" json:"migration_framework"` + MigrationTableName string `header:"migration_table_name" json:"migration_table_name"` + InsightsRawQueries bool `header:"insights_raw_queries" json:"insights_raw_queries"` + InsightsEnabled bool `header:"insights_enabled" json:"insights_enabled"` + ProductionBranchWebConsole bool `header:"production_branch_web_console" json:"production_branch_web_console"` + MultipleAdminsRequiredForDeletion bool `header:"multiple_admins_required_for_deletion" json:"multiple_admins_required_for_deletion"` + CreatedAt int64 `header:"created_at,timestamp(ms|utc|human)" json:"created_at"` + UpdatedAt int64 `header:"updated_at,timestamp(ms|utc|human)" json:"updated_at"` orig *ps.Database } @@ -87,19 +88,20 @@ type Database struct { // database model, including settings. func toDatabase(db *ps.Database) *Database { out := &Database{ - Name: db.Name, - Kind: string(db.Kind), - DefaultBranch: db.DefaultBranch, - RequireApprovalForDeploy: db.RequireApprovalForDeploy, - RestrictBranchRegion: db.RestrictBranchRegion, - AllowDataBranching: db.AllowDataBranching, - ForeignKeysEnabled: db.ForeignKeysEnabled, - InsightsRawQueries: db.InsightsRawQueries, - InsightsEnabled: db.InsightsEnabled, - ProductionBranchWebConsole: db.ProductionBranchWebConsole, - CreatedAt: db.CreatedAt.UTC().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)), - UpdatedAt: db.UpdatedAt.UTC().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)), - orig: db, + Name: db.Name, + Kind: string(db.Kind), + DefaultBranch: db.DefaultBranch, + RequireApprovalForDeploy: db.RequireApprovalForDeploy, + RestrictBranchRegion: db.RestrictBranchRegion, + AllowDataBranching: db.AllowDataBranching, + ForeignKeysEnabled: db.ForeignKeysEnabled, + InsightsRawQueries: db.InsightsRawQueries, + InsightsEnabled: db.InsightsEnabled, + ProductionBranchWebConsole: db.ProductionBranchWebConsole, + MultipleAdminsRequiredForDeletion: db.MultipleAdminsRequiredForDeletion, + CreatedAt: db.CreatedAt.UTC().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)), + UpdatedAt: db.UpdatedAt.UTC().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)), + orig: db, } if db.AutomaticMigrations != nil { @@ -161,6 +163,7 @@ func printDatabaseHuman(p *printer.Printer, db *Database) { p.Printf("%-32s %t\n", "Restrict Branch Region", db.RestrictBranchRegion) p.Printf("%-32s %t\n", "Insights Enabled", db.InsightsEnabled) p.Printf("%-32s %t\n", "Production Branch Web Console", db.ProductionBranchWebConsole) + p.Printf("%-32s %t\n", "Multi-Admin Deletion", db.MultipleAdminsRequiredForDeletion) if vitess { p.Printf("%-32s %t\n", "Insights Raw Queries", db.InsightsRawQueries) diff --git a/internal/cmd/database/update.go b/internal/cmd/database/update.go index 2ad738fec..d9b15f7dd 100644 --- a/internal/cmd/database/update.go +++ b/internal/cmd/database/update.go @@ -13,17 +13,18 @@ import ( // UpdateCmd updates configurable database settings. func UpdateCmd(ch *cmdutil.Helper) *cobra.Command { var flags struct { - newName string - defaultBranch string - requireApprovalForDeploy bool - restrictBranchRegion bool - allowDataBranching bool - allowForeignKeyConstraints bool - automaticMigrations bool - migrationFramework string - migrationTableName string - insightsRawQueries bool - productionBranchWebConsole bool + newName string + defaultBranch string + requireApprovalForDeploy bool + restrictBranchRegion bool + allowDataBranching bool + allowForeignKeyConstraints bool + automaticMigrations bool + migrationFramework string + migrationTableName string + insightsRawQueries bool + productionBranchWebConsole bool + multipleAdminsRequiredForDeletion bool } cmd := &cobra.Command{ @@ -67,6 +68,10 @@ Flags marked "Vitess only" are rejected for PostgreSQL databases.`, req.ProductionBranchWebConsole = &flags.productionBranchWebConsole changed = true } + if cmd.Flags().Changed("multiple-admins-required-for-deletion") { + req.MultipleAdminsRequiredForDeletion = &flags.multipleAdminsRequiredForDeletion + changed = true + } if cmd.Flags().Changed("insights-raw-queries") { req.InsightsRawQueries = &flags.insightsRawQueries @@ -163,6 +168,7 @@ Flags marked "Vitess only" are rejected for PostgreSQL databases.`, cmd.Flags().StringVar(&flags.defaultBranch, "default-branch", "", "The default branch of the database (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.restrictBranchRegion, "restrict-branch-region", false, "Limit branch creation to the database region (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.productionBranchWebConsole, "production-branch-web-console", false, "Allow the web console on the production branch (PostgreSQL and Vitess)") + cmd.Flags().BoolVar(&flags.multipleAdminsRequiredForDeletion, "multiple-admins-required-for-deletion", false, "Require requests from two people to delete the database or one of its keyspaces (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.insightsRawQueries, "insights-raw-queries", false, "Collect full SQL queries for Insights (Vitess only; PostgreSQL uses pgconf.pginsights.raw_queries)") cmd.Flags().BoolVar(&flags.requireApprovalForDeploy, "require-approval-for-deploy", false, "Require admin approval for deploy requests (Vitess only)") diff --git a/internal/cmd/database/update_test.go b/internal/cmd/database/update_test.go index 19f8b25e8..825f36dd1 100644 --- a/internal/cmd/database/update_test.go +++ b/internal/cmd/database/update_test.go @@ -67,6 +67,8 @@ func TestDatabase_UpdateCmd(t *testing.T) { c.Assert(*req.InsightsRawQueries, qt.IsFalse) c.Assert(req.ProductionBranchWebConsole, qt.IsNotNil) c.Assert(*req.ProductionBranchWebConsole, qt.IsFalse) + c.Assert(req.MultipleAdminsRequiredForDeletion, qt.IsNotNil) + c.Assert(*req.MultipleAdminsRequiredForDeletion, qt.IsTrue) return res, nil }, } @@ -97,6 +99,7 @@ func TestDatabase_UpdateCmd(t *testing.T) { "--migration-table-name", tableName, "--insights-raw-queries=false", "--production-branch-web-console=false", + "--multiple-admins-required-for-deletion=true", }) err := cmd.Execute() diff --git a/internal/planetscale/databases.go b/internal/planetscale/databases.go index 77f57dcc7..d2aad5e73 100644 --- a/internal/planetscale/databases.go +++ b/internal/planetscale/databases.go @@ -68,19 +68,20 @@ type DeleteDatabaseRequest struct { // UpdateDatabaseSettingsRequest encapsulates the request for updating // database settings. type UpdateDatabaseSettingsRequest struct { - Organization string `json:"-"` - Database string `json:"-"` - NewName *string `json:"new_name,omitempty"` - AutomaticMigrations *bool `json:"automatic_migrations,omitempty"` - MigrationFramework *string `json:"migration_framework,omitempty"` - MigrationTableName *string `json:"migration_table_name,omitempty"` - RequireApprovalForDeploy *bool `json:"require_approval_for_deploy,omitempty"` - RestrictBranchRegion *bool `json:"restrict_branch_region,omitempty"` - AllowDataBranching *bool `json:"allow_data_branching,omitempty"` - AllowForeignKeyConstraints *bool `json:"allow_foreign_key_constraints,omitempty"` - InsightsRawQueries *bool `json:"insights_raw_queries,omitempty"` - ProductionBranchWebConsole *bool `json:"production_branch_web_console,omitempty"` - DefaultBranch *string `json:"default_branch,omitempty"` + Organization string `json:"-"` + Database string `json:"-"` + NewName *string `json:"new_name,omitempty"` + AutomaticMigrations *bool `json:"automatic_migrations,omitempty"` + MigrationFramework *string `json:"migration_framework,omitempty"` + MigrationTableName *string `json:"migration_table_name,omitempty"` + RequireApprovalForDeploy *bool `json:"require_approval_for_deploy,omitempty"` + RestrictBranchRegion *bool `json:"restrict_branch_region,omitempty"` + AllowDataBranching *bool `json:"allow_data_branching,omitempty"` + AllowForeignKeyConstraints *bool `json:"allow_foreign_key_constraints,omitempty"` + InsightsRawQueries *bool `json:"insights_raw_queries,omitempty"` + ProductionBranchWebConsole *bool `json:"production_branch_web_console,omitempty"` + MultipleAdminsRequiredForDeletion *bool `json:"multiple_admins_required_for_deletion,omitempty"` + DefaultBranch *string `json:"default_branch,omitempty"` } // GetDatabaseThrottlerRequest gets the database-level Vitess migration throttler. @@ -156,26 +157,27 @@ const ( // Database represents a PlanetScale database type Database struct { - Name string `json:"name"` - Notes string `json:"notes"` - Region Region `json:"region"` - State DatabaseState `json:"state"` - Kind DatabaseEngine `json:"kind"` - HtmlURL string `json:"html_url"` - DefaultBranch string `json:"default_branch"` - RequireApprovalForDeploy bool `json:"require_approval_for_deploy"` - RestrictBranchRegion bool `json:"restrict_branch_region"` - AllowDataBranching bool `json:"allow_data_branching"` - ForeignKeysEnabled bool `json:"foreign_keys_enabled"` - AutomaticMigrations *bool `json:"automatic_migrations"` - InsightsRawQueries bool `json:"insights_raw_queries"` - InsightsEnabled bool `json:"insights_enabled"` - ProductionBranchWebConsole bool `json:"production_branch_web_console"` - MigrationTableName *string `json:"migration_table_name"` - MigrationFramework *string `json:"migration_framework"` - EncryptionKeyID string `json:"encryption_key_id,omitempty"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + Name string `json:"name"` + Notes string `json:"notes"` + Region Region `json:"region"` + State DatabaseState `json:"state"` + Kind DatabaseEngine `json:"kind"` + HtmlURL string `json:"html_url"` + DefaultBranch string `json:"default_branch"` + RequireApprovalForDeploy bool `json:"require_approval_for_deploy"` + RestrictBranchRegion bool `json:"restrict_branch_region"` + AllowDataBranching bool `json:"allow_data_branching"` + ForeignKeysEnabled bool `json:"foreign_keys_enabled"` + AutomaticMigrations *bool `json:"automatic_migrations"` + InsightsRawQueries bool `json:"insights_raw_queries"` + InsightsEnabled bool `json:"insights_enabled"` + ProductionBranchWebConsole bool `json:"production_branch_web_console"` + MultipleAdminsRequiredForDeletion bool `json:"multiple_admins_required_for_deletion"` + MigrationTableName *string `json:"migration_table_name"` + MigrationFramework *string `json:"migration_framework"` + EncryptionKeyID string `json:"encryption_key_id,omitempty"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } // Database represents a list of PlanetScale databases diff --git a/internal/planetscale/databases_test.go b/internal/planetscale/databases_test.go index 1dcf8bc65..b81b7b8af 100644 --- a/internal/planetscale/databases_test.go +++ b/internal/planetscale/databases_test.go @@ -529,6 +529,7 @@ func TestDatabases_UpdateSettings(t *testing.T) { c.Assert(body["migration_framework"], qt.Equals, framework) c.Assert(body["migration_table_name"], qt.Equals, tableName) c.Assert(body["production_branch_web_console"], qt.Equals, disabled) + c.Assert(body["multiple_admins_required_for_deletion"], qt.Equals, requireApproval) w.WriteHeader(200) out := `{ @@ -559,19 +560,20 @@ func TestDatabases_UpdateSettings(t *testing.T) { ctx := context.Background() db, err := client.Databases.UpdateSettings(ctx, &UpdateDatabaseSettingsRequest{ - Organization: testOrg, - Database: testDatabase, - NewName: &newName, - DefaultBranch: &defaultBranch, - RequireApprovalForDeploy: &requireApproval, - RestrictBranchRegion: &disabled, - AllowDataBranching: &disabled, - AllowForeignKeyConstraints: &disabled, - AutomaticMigrations: &disabled, - MigrationFramework: &framework, - MigrationTableName: &tableName, - InsightsRawQueries: &insightsRaw, - ProductionBranchWebConsole: &disabled, + Organization: testOrg, + Database: testDatabase, + NewName: &newName, + DefaultBranch: &defaultBranch, + RequireApprovalForDeploy: &requireApproval, + RestrictBranchRegion: &disabled, + AllowDataBranching: &disabled, + AllowForeignKeyConstraints: &disabled, + AutomaticMigrations: &disabled, + MigrationFramework: &framework, + MigrationTableName: &tableName, + InsightsRawQueries: &insightsRaw, + ProductionBranchWebConsole: &disabled, + MultipleAdminsRequiredForDeletion: &requireApproval, }) c.Assert(err, qt.IsNil) From 307c4d9aa57567abe4b4c1b5c33d186b2ffb222e Mon Sep 17 00:00:00 2001 From: Elom Gomez Date: Tue, 1 Dec 2026 22:24:59 -0600 Subject: [PATCH 2/3] Say two admins in the deletion flag's help Co-Authored-By: Claude Opus 5.5 --- internal/cmd/database/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/database/update.go b/internal/cmd/database/update.go index d9b15f7dd..e9cee72d7 100644 --- a/internal/cmd/database/update.go +++ b/internal/cmd/database/update.go @@ -168,7 +168,7 @@ Flags marked "Vitess only" are rejected for PostgreSQL databases.`, cmd.Flags().StringVar(&flags.defaultBranch, "default-branch", "", "The default branch of the database (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.restrictBranchRegion, "restrict-branch-region", false, "Limit branch creation to the database region (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.productionBranchWebConsole, "production-branch-web-console", false, "Allow the web console on the production branch (PostgreSQL and Vitess)") - cmd.Flags().BoolVar(&flags.multipleAdminsRequiredForDeletion, "multiple-admins-required-for-deletion", false, "Require requests from two people to delete the database or one of its keyspaces (PostgreSQL and Vitess)") + cmd.Flags().BoolVar(&flags.multipleAdminsRequiredForDeletion, "multiple-admins-required-for-deletion", false, "Require two admins to delete the database or one of its keyspaces (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.insightsRawQueries, "insights-raw-queries", false, "Collect full SQL queries for Insights (Vitess only; PostgreSQL uses pgconf.pginsights.raw_queries)") cmd.Flags().BoolVar(&flags.requireApprovalForDeploy, "require-approval-for-deploy", false, "Require admin approval for deploy requests (Vitess only)") From 3f10ae318e2f1ec2ae3f378ef5f9f70f8cac30cd Mon Sep 17 00:00:00 2001 From: Elom Gomez Date: Tue, 1 Dec 2026 22:30:57 -0600 Subject: [PATCH 3/3] Say approval from two admins in the deletion flag's help Co-Authored-By: Claude Opus 5.5 --- internal/cmd/database/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/database/update.go b/internal/cmd/database/update.go index e9cee72d7..21a0d5328 100644 --- a/internal/cmd/database/update.go +++ b/internal/cmd/database/update.go @@ -168,7 +168,7 @@ Flags marked "Vitess only" are rejected for PostgreSQL databases.`, cmd.Flags().StringVar(&flags.defaultBranch, "default-branch", "", "The default branch of the database (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.restrictBranchRegion, "restrict-branch-region", false, "Limit branch creation to the database region (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.productionBranchWebConsole, "production-branch-web-console", false, "Allow the web console on the production branch (PostgreSQL and Vitess)") - cmd.Flags().BoolVar(&flags.multipleAdminsRequiredForDeletion, "multiple-admins-required-for-deletion", false, "Require two admins to delete the database or one of its keyspaces (PostgreSQL and Vitess)") + cmd.Flags().BoolVar(&flags.multipleAdminsRequiredForDeletion, "multiple-admins-required-for-deletion", false, "Require approval from two admins to delete the database (PostgreSQL and Vitess)") cmd.Flags().BoolVar(&flags.insightsRawQueries, "insights-raw-queries", false, "Collect full SQL queries for Insights (Vitess only; PostgreSQL uses pgconf.pginsights.raw_queries)") cmd.Flags().BoolVar(&flags.requireApprovalForDeploy, "require-approval-for-deploy", false, "Require admin approval for deploy requests (Vitess only)")