feat(custom-roles): align chatwoot permissions

This commit is contained in:
2026-06-05 11:14:38 +08:00
parent b5f2a47ef8
commit 8b3b532c65
20 changed files with 681 additions and 226 deletions
+2 -2
View File
@@ -84,7 +84,7 @@ CREATE TABLE IF NOT EXISTS custom_roles (
account_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
description TEXT,
permissions JSONB NOT NULL DEFAULT '{}',
permissions JSONB NOT NULL DEFAULT '[]',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
deleted_at TIMESTAMP WITH TIME ZONE
@@ -444,4 +444,4 @@ CREATE TABLE IF NOT EXISTS channel_whatsapps (
deleted_at TIMESTAMP WITH TIME ZONE
);
CREATE INDEX idx_channel_whatsapps_inbox_id ON channel_whatsapps(inbox_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_channel_whatsapps_inbox_id ON channel_whatsapps(inbox_id) WHERE deleted_at IS NULL;
@@ -0,0 +1 @@
ALTER TABLE custom_roles ALTER COLUMN permissions SET DEFAULT '{}'::jsonb;
@@ -0,0 +1,7 @@
-- Align custom_roles.permissions with Chatwoot custom-role permission arrays.
-- Existing legacy JSON maps remain readable in Go code; new writes use arrays.
ALTER TABLE custom_roles ALTER COLUMN permissions SET DEFAULT '[]'::jsonb;
UPDATE custom_roles
SET permissions = '[]'::jsonb
WHERE permissions IS NULL OR permissions = '{}'::jsonb;