Skip to content

Commit c2b4d78

Browse files
committed
Edit token update to work with views
1 parent 7880cb6 commit c2b4d78

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,18 @@ async fn generate_token_command(
156156
}
157157
}
158158

159-
// Insert into database
159+
// Delete existing token with same name (if any), then insert new one
160+
// Note: Using DELETE + INSERT instead of ON CONFLICT for view compatibility
161+
sqlx::query("DELETE FROM postgate_tokens WHERE database_id = $1 AND name = $2")
162+
.bind(db_id)
163+
.bind(name)
164+
.execute(&pool)
165+
.await?;
166+
160167
sqlx::query(
161168
r#"
162169
INSERT INTO postgate_tokens (database_id, name, token_hash, token_prefix, allowed_operations)
163170
VALUES ($1, $2, $3, $4, $5)
164-
ON CONFLICT (database_id, name) DO UPDATE SET
165-
token_hash = EXCLUDED.token_hash,
166-
token_prefix = EXCLUDED.token_prefix,
167-
allowed_operations = EXCLUDED.allowed_operations,
168-
created_at = NOW()
169171
"#,
170172
)
171173
.bind(db_id)

0 commit comments

Comments
 (0)