From 5f35fdf21732a58f265c2c7c026120c57b690799 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 20 Jul 2026 12:14:44 +0200 Subject: [PATCH] :recycle: Replace uuid-ossp defaults with gen_random_uuid() and add missing :id on insert (#10591) * :paperclip: Add postgresql client tool wrapper for devenv * :recycle: 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 --- backend/src/app/migrations.clj | 5 ++- ...prove-uuid-defaults-and-drop-extension.sql | 31 +++++++++++++++++++ backend/src/app/rpc/commands/projects.clj | 4 ++- backend/src/app/rpc/commands/teams.clj | 5 +-- backend/src/app/srepl/binfile.clj | 4 ++- 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 backend/src/app/migrations/sql/0152-improve-uuid-defaults-and-drop-extension.sql diff --git a/backend/src/app/migrations.clj b/backend/src/app/migrations.clj index c6fed68e39..150e69ced2 100644 --- a/backend/src/app/migrations.clj +++ b/backend/src/app/migrations.clj @@ -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] diff --git a/backend/src/app/migrations/sql/0152-improve-uuid-defaults-and-drop-extension.sql b/backend/src/app/migrations/sql/0152-improve-uuid-defaults-and-drop-extension.sql new file mode 100644 index 0000000000..c389e9430d --- /dev/null +++ b/backend/src/app/migrations/sql/0152-improve-uuid-defaults-and-drop-extension.sql @@ -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"; diff --git a/backend/src/app/rpc/commands/projects.clj b/backend/src/app/rpc/commands/projects.clj index 0cb1b46e57..12da9bb7c5 100644 --- a/backend/src/app/rpc/commands/projects.clj +++ b/backend/src/app/rpc/commands/projects.clj @@ -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 diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index 5efc564daa..b091516586 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -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)))) diff --git a/backend/src/app/srepl/binfile.clj b/backend/src/app/srepl/binfile.clj index c1792321f7..0fbc09c460 100644 --- a/backend/src/app/srepl/binfile.clj +++ b/backend/src/app/srepl/binfile.clj @@ -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