Add gcm_consent_types column to cookie_categories

Stores the Google Consent Mode v2 consent type mapping
per cookie category so each category can declare which
GCM signals it controls (e.g. analytics_storage,
ad_storage).

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-24 13:40:28 +04:00
parent ab5654f6e5
commit 2b15a1684c
2 changed files with 52 additions and 26 deletions

View File

@@ -39,16 +39,17 @@ type (
CookieItems []CookieItem
CookieCategory struct {
ID gid.GID `db:"id"`
OrganizationID gid.GID `db:"organization_id"`
CookieBannerID gid.GID `db:"cookie_banner_id"`
Name string `db:"name"`
Slug string `db:"slug"`
Description string `db:"description"`
Kind CookieCategoryKind `db:"kind"`
Rank int `db:"rank"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
ID gid.GID `db:"id"`
OrganizationID gid.GID `db:"organization_id"`
CookieBannerID gid.GID `db:"cookie_banner_id"`
Name string `db:"name"`
Slug string `db:"slug"`
Description string `db:"description"`
Kind CookieCategoryKind `db:"kind"`
Rank int `db:"rank"`
GCMConsentTypes []string `db:"gcm_consent_types"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
CookieCategories []*CookieCategory
@@ -109,6 +110,7 @@ SELECT
description,
kind,
rank,
gcm_consent_types,
created_at,
updated_at
FROM
@@ -159,6 +161,7 @@ SELECT
description,
kind,
rank,
gcm_consent_types,
created_at,
updated_at
FROM
@@ -237,6 +240,7 @@ SELECT
description,
kind,
rank,
gcm_consent_types,
created_at,
updated_at
FROM
@@ -284,6 +288,7 @@ INSERT INTO cookie_categories (
description,
kind,
rank,
gcm_consent_types,
created_at,
updated_at
) VALUES (
@@ -296,23 +301,25 @@ INSERT INTO cookie_categories (
@description,
@kind,
@rank,
@gcm_consent_types,
@created_at,
@updated_at
)
`
args := pgx.StrictNamedArgs{
"id": c.ID,
"tenant_id": scope.GetTenantID(),
"organization_id": c.OrganizationID,
"cookie_banner_id": c.CookieBannerID,
"name": c.Name,
"slug": c.Slug,
"description": c.Description,
"kind": c.Kind,
"rank": c.Rank,
"created_at": c.CreatedAt,
"updated_at": c.UpdatedAt,
"id": c.ID,
"tenant_id": scope.GetTenantID(),
"organization_id": c.OrganizationID,
"cookie_banner_id": c.CookieBannerID,
"name": c.Name,
"slug": c.Slug,
"description": c.Description,
"kind": c.Kind,
"rank": c.Rank,
"gcm_consent_types": c.GCMConsentTypes,
"created_at": c.CreatedAt,
"updated_at": c.UpdatedAt,
}
_, err := tx.Exec(ctx, q, args)
@@ -339,6 +346,7 @@ SET
name = @name,
slug = @slug,
description = @description,
gcm_consent_types = @gcm_consent_types,
updated_at = @updated_at
WHERE
%s
@@ -348,11 +356,12 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"id": c.ID,
"name": c.Name,
"slug": c.Slug,
"description": c.Description,
"updated_at": c.UpdatedAt,
"id": c.ID,
"name": c.Name,
"slug": c.Slug,
"description": c.Description,
"gcm_consent_types": c.GCMConsentTypes,
"updated_at": c.UpdatedAt,
}
maps.Copy(args, scope.SQLArguments())
@@ -467,6 +476,7 @@ SELECT
description,
kind,
rank,
gcm_consent_types,
created_at,
updated_at
FROM

View File

@@ -0,0 +1,16 @@
-- Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
ALTER TABLE cookie_categories ADD COLUMN gcm_consent_types TEXT[] NOT NULL DEFAULT '{}';
ALTER TABLE cookie_categories ALTER COLUMN gcm_consent_types DROP DEFAULT;