♻️ Replace uuid-ossp defaults with gen_random_uuid() and add missing :id on insert (#10591)

* 📎 Add postgresql client tool wrapper for devenv

* ♻️ Replace uuid-ossp defaults with gen_random_uuid() and add missing :id on insert

- Switch all DEFAULT uuid_generate_v4() to gen_random_uuid()
  (built-in PG 13+, no extension required)
- Add explicit :id (uuid/next) to 4 db/insert! calls that were
  relying on the DB default (team-profile-rel, project-profile-rel,
  team-project-profile-rel)
- Drop uuid-ossp extension (no longer needed)
- Add missing uuid require to projects.clj and srepl/binfile.clj

AI-assisted-by: deepseek-v4-flash

---------

Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Andrey Antukh 2026-07-20 12:14:44 +02:00 committed by GitHub
parent 5dadda0f2b
commit 5f35fdf217
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 44 additions and 5 deletions

View File

@ -493,7 +493,10 @@
:fn (mg/resource "app/migrations/sql/0150-mod-storage-object-table.sql")}
{:name "0151-mod-file-tagged-object-thumbnail-table"
:fn (mg/resource "app/migrations/sql/0151-mod-file-tagged-object-thumbnail-table.sql")}])
:fn (mg/resource "app/migrations/sql/0151-mod-file-tagged-object-thumbnail-table.sql")}
{:name "0152-improve-uuid-defaults-and-drop-extension"
:fn (mg/resource "app/migrations/sql/0152-improve-uuid-defaults-and-drop-extension.sql")}])
(defn apply-migrations!
[pool name migrations]

View File

@ -0,0 +1,31 @@
-- Migration: Replace uuid_generate_v4() defaults with gen_random_uuid()
-- and remove uuid-ossp extension.
--
-- gen_random_uuid() is built into PostgreSQL >= 13 and requires no extension.
-- The application already generates IDs explicitly via uuid/next in all
-- code paths; this migration adds gen_random_uuid() as a safety-net default
-- instead of the extension-dependent uuid_generate_v4().
ALTER TABLE access_token ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE audit_log ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE comment ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE comment_thread ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE file ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE file_change ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE file_media_object ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE profile ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE project ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE project_profile_rel ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE scheduled_task_history ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE share_link ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE storage_object ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE task ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE team ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE team_access_request ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE team_font_variant ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE team_invitation ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE team_profile_rel ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE team_project_profile_rel ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE usage_quote ALTER COLUMN id SET DEFAULT gen_random_uuid();
DROP EXTENSION IF EXISTS "uuid-ossp";

View File

@ -10,6 +10,7 @@
[app.common.exceptions :as ex]
[app.common.schema :as sm]
[app.common.time :as ct]
[app.common.uuid :as uuid]
[app.db :as db]
[app.db.sql :as-alias sql]
[app.features.logical-deletion :as ldel]
@ -184,7 +185,8 @@
timestamp (::rpc/request-at params)]
(teams/create-project-role conn profile-id (:id project) :owner)
(db/insert! conn :team-project-profile-rel
{:project-id (:id project)
{:id (uuid/next)
:project-id (:id project)
:profile-id profile-id
:created-at timestamp
:modified-at timestamp

View File

@ -628,7 +628,7 @@
(some? (:organization-id membership)) ;; the team do belong to an organization
(not (:is-member membership))) ;; the user is not a member of the org yet
(initialize-user-in-nitrate-org cfg profile-id (:organization-id membership)))))
(db/insert! conn :team-profile-rel params options)))
(db/insert! conn :team-profile-rel (assoc params :id (uuid/next)) options)))
(defn create-team
"This is a complete team creation process, it creates the team
@ -699,7 +699,8 @@
(defn create-project-role
[conn profile-id project-id role]
(let [params {:project-id project-id
:profile-id profile-id}]
:profile-id profile-id
:id (uuid/next)}]
(->> (perms/assign-role-flags params role)
(db/insert! conn :project-profile-rel))))

View File

@ -7,6 +7,7 @@
(ns app.srepl.binfile
(:require
[app.binfile.v2 :as binfile.v2]
[app.common.uuid :as uuid]
[app.db :as db]
[app.main :as main]
[app.srepl.helpers :as h]
@ -30,7 +31,8 @@
(when owner
(db/insert! cfg :team-profile-rel
{:team-id (:id team)
{:id (uuid/next)
:team-id (:id team)
:profile-id (:id owner)
:is-admin true
:is-owner true