fix: make migration 032 idempotent and fix UUID type in credentials bootstrap
- Migration 032: add NOT EXISTS check to avoid duplicate key violation - CredentialsBootstrap: use NULLIF for updated_by UUID column, pass empty string instead of system_bootstrap
This commit is contained in:
parent
fee98a651b
commit
1c29e469a7
2 changed files with 6 additions and 3 deletions
|
|
@ -33,7 +33,7 @@ func NewCredentialsService(db *sql.DB) *CredentialsService {
|
|||
func (s *CredentialsService) SaveCredentials(ctx context.Context, serviceName, encryptedPayload, updatedBy string) error {
|
||||
query := `
|
||||
INSERT INTO external_services_credentials (service_name, encrypted_payload, updated_by, updated_at)
|
||||
VALUES ($1, $2, $3, NOW())
|
||||
VALUES ($1, $2, NULLIF($3, '')::uuid, NOW())
|
||||
ON CONFLICT (service_name)
|
||||
DO UPDATE SET
|
||||
encrypted_payload = EXCLUDED.encrypted_payload,
|
||||
|
|
@ -334,7 +334,7 @@ func (s *CredentialsService) BootstrapCredentials(ctx context.Context) error {
|
|||
fmt.Printf("[CredentialsBootstrap] Failed to encrypt %s: %v\n", service, err)
|
||||
continue
|
||||
}
|
||||
if err := s.SaveCredentials(ctx, service, encrypted, "system_bootstrap"); err != nil {
|
||||
if err := s.SaveCredentials(ctx, service, encrypted, ""); err != nil {
|
||||
fmt.Printf("[CredentialsBootstrap] Failed to save %s: %v\n", service, err)
|
||||
} else {
|
||||
fmt.Printf("[CredentialsBootstrap] Successfully migrated %s\n", service)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
-- Migration: Update Super Admin to 'lol' and force password reset
|
||||
-- Description: Updates the superadmin identifier, email, name, and sets status to enforce password change.
|
||||
-- Made idempotent: only runs if target identifier doesn't already exist.
|
||||
|
||||
-- Increase status column length to support 'force_change_password' (21 chars)
|
||||
ALTER TABLE users ALTER COLUMN status TYPE VARCHAR(50);
|
||||
|
||||
-- Only update if 'lol' identifier doesn't already exist
|
||||
UPDATE users
|
||||
SET
|
||||
identifier = 'lol',
|
||||
|
|
@ -12,4 +14,5 @@ SET
|
|||
name = 'Dr. Horse Expert',
|
||||
status = 'force_change_password',
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE identifier = 'superadmin' OR email = 'admin@gohorsejobs.com';
|
||||
WHERE (identifier = 'superadmin' OR email = 'admin@gohorsejobs.com')
|
||||
AND NOT EXISTS (SELECT 1 FROM users WHERE identifier = 'lol');
|
||||
|
|
|
|||
Loading…
Reference in a new issue