Store cookie durations as max_age_seconds
Replace the free-form duration TEXT column with a nullable max_age_seconds INTEGER on both cookies and cookie_patterns tables. The SDK detector now sends raw seconds instead of humanized strings, eliminating locale-dependent comparisons in the pattern merge worker. Humanization happens at display time in the widget and console UI. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -35,7 +35,7 @@ type (
|
||||
CookieBannerID gid.GID `db:"cookie_banner_id"`
|
||||
CookiePatternID gid.GID `db:"cookie_pattern_id"`
|
||||
Name string `db:"name"`
|
||||
Duration string `db:"duration"`
|
||||
MaxAgeSeconds *int `db:"max_age_seconds"`
|
||||
Source CookieSource `db:"source"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
@@ -81,7 +81,7 @@ SELECT
|
||||
cookie_banner_id,
|
||||
cookie_pattern_id,
|
||||
name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
source,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -130,7 +130,7 @@ SELECT
|
||||
cookie_banner_id,
|
||||
cookie_pattern_id,
|
||||
name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
source,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -208,7 +208,7 @@ SELECT
|
||||
cookie_banner_id,
|
||||
cookie_pattern_id,
|
||||
name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
source,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -289,7 +289,7 @@ SELECT
|
||||
cookie_banner_id,
|
||||
cookie_pattern_id,
|
||||
name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
source,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -335,7 +335,7 @@ INSERT INTO cookies (
|
||||
cookie_banner_id,
|
||||
cookie_pattern_id,
|
||||
name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
source,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -346,7 +346,7 @@ INSERT INTO cookies (
|
||||
@cookie_banner_id,
|
||||
@cookie_pattern_id,
|
||||
@name,
|
||||
@duration,
|
||||
@max_age_seconds,
|
||||
@source,
|
||||
@created_at,
|
||||
@updated_at
|
||||
@@ -360,7 +360,7 @@ INSERT INTO cookies (
|
||||
"cookie_banner_id": c.CookieBannerID,
|
||||
"cookie_pattern_id": c.CookiePatternID,
|
||||
"name": c.Name,
|
||||
"duration": c.Duration,
|
||||
"max_age_seconds": c.MaxAgeSeconds,
|
||||
"source": c.Source,
|
||||
"created_at": c.CreatedAt,
|
||||
"updated_at": c.UpdatedAt,
|
||||
@@ -392,7 +392,7 @@ INSERT INTO cookies (
|
||||
cookie_banner_id,
|
||||
cookie_pattern_id,
|
||||
name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
source,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -403,7 +403,7 @@ INSERT INTO cookies (
|
||||
@cookie_banner_id,
|
||||
@cookie_pattern_id,
|
||||
@name,
|
||||
@duration,
|
||||
@max_age_seconds,
|
||||
@source,
|
||||
@created_at,
|
||||
@updated_at
|
||||
@@ -420,7 +420,7 @@ ON CONFLICT (cookie_banner_id, name) DO UPDATE
|
||||
"cookie_banner_id": c.CookieBannerID,
|
||||
"cookie_pattern_id": c.CookiePatternID,
|
||||
"name": c.Name,
|
||||
"duration": c.Duration,
|
||||
"max_age_seconds": c.MaxAgeSeconds,
|
||||
"source": c.Source,
|
||||
"source_script": CookieSourceScript,
|
||||
"created_at": c.CreatedAt,
|
||||
@@ -444,7 +444,7 @@ func (c *Cookie) Update(
|
||||
UPDATE cookies
|
||||
SET
|
||||
cookie_pattern_id = @cookie_pattern_id,
|
||||
duration = @duration,
|
||||
max_age_seconds = @max_age_seconds,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
@@ -456,7 +456,7 @@ WHERE
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": c.ID,
|
||||
"cookie_pattern_id": c.CookiePatternID,
|
||||
"duration": c.Duration,
|
||||
"max_age_seconds": c.MaxAgeSeconds,
|
||||
"updated_at": c.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
@@ -31,9 +31,9 @@ import (
|
||||
|
||||
type (
|
||||
CookieItem struct {
|
||||
Name string `json:"name"`
|
||||
Duration string `json:"duration"`
|
||||
Description string `json:"description"`
|
||||
Name string `json:"name"`
|
||||
MaxAgeSeconds *int `json:"max_age_seconds"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
CookieItems []CookieItem
|
||||
|
||||
@@ -37,7 +37,7 @@ type (
|
||||
Pattern string `db:"pattern"`
|
||||
MatchType CookiePatternMatchType `db:"match_type"`
|
||||
DisplayName string `db:"display_name"`
|
||||
Duration string `db:"duration"`
|
||||
MaxAgeSeconds *int `db:"max_age_seconds"`
|
||||
Description string `db:"description"`
|
||||
Source CookieSource `db:"source"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
@@ -86,7 +86,7 @@ SELECT
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
created_at,
|
||||
@@ -138,7 +138,7 @@ SELECT
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
created_at,
|
||||
@@ -201,7 +201,7 @@ SELECT
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
created_at,
|
||||
@@ -281,7 +281,7 @@ SELECT
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
created_at,
|
||||
@@ -330,7 +330,7 @@ INSERT INTO cookie_patterns (
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
created_at,
|
||||
@@ -344,7 +344,7 @@ INSERT INTO cookie_patterns (
|
||||
@pattern,
|
||||
@match_type,
|
||||
@display_name,
|
||||
@duration,
|
||||
@max_age_seconds,
|
||||
@description,
|
||||
@source,
|
||||
@created_at,
|
||||
@@ -361,7 +361,7 @@ INSERT INTO cookie_patterns (
|
||||
"pattern": cp.Pattern,
|
||||
"match_type": cp.MatchType,
|
||||
"display_name": cp.DisplayName,
|
||||
"duration": cp.Duration,
|
||||
"max_age_seconds": cp.MaxAgeSeconds,
|
||||
"description": cp.Description,
|
||||
"source": cp.Source,
|
||||
"created_at": cp.CreatedAt,
|
||||
@@ -396,7 +396,7 @@ INSERT INTO cookie_patterns (
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
duration,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
created_at,
|
||||
@@ -410,7 +410,7 @@ INSERT INTO cookie_patterns (
|
||||
@pattern,
|
||||
@match_type,
|
||||
@display_name,
|
||||
@duration,
|
||||
@max_age_seconds,
|
||||
@description,
|
||||
@source,
|
||||
@created_at,
|
||||
@@ -428,7 +428,7 @@ ON CONFLICT (cookie_banner_id, pattern) DO NOTHING
|
||||
"pattern": cp.Pattern,
|
||||
"match_type": cp.MatchType,
|
||||
"display_name": cp.DisplayName,
|
||||
"duration": cp.Duration,
|
||||
"max_age_seconds": cp.MaxAgeSeconds,
|
||||
"description": cp.Description,
|
||||
"source": cp.Source,
|
||||
"created_at": cp.CreatedAt,
|
||||
@@ -453,7 +453,7 @@ UPDATE cookie_patterns
|
||||
SET
|
||||
cookie_category_id = @cookie_category_id,
|
||||
display_name = @display_name,
|
||||
duration = @duration,
|
||||
max_age_seconds = @max_age_seconds,
|
||||
description = @description,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
@@ -467,7 +467,7 @@ WHERE
|
||||
"id": cp.ID,
|
||||
"cookie_category_id": cp.CookieCategoryID,
|
||||
"display_name": cp.DisplayName,
|
||||
"duration": cp.Duration,
|
||||
"max_age_seconds": cp.MaxAgeSeconds,
|
||||
"description": cp.Description,
|
||||
"updated_at": cp.UpdatedAt,
|
||||
}
|
||||
|
||||
19
pkg/coredata/migrations/20260429T135250Z.sql
Normal file
19
pkg/coredata/migrations/20260429T135250Z.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- 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 cookies DROP COLUMN duration;
|
||||
ALTER TABLE cookies ADD COLUMN max_age_seconds INTEGER;
|
||||
|
||||
ALTER TABLE cookie_patterns DROP COLUMN duration;
|
||||
ALTER TABLE cookie_patterns ADD COLUMN max_age_seconds INTEGER;
|
||||
Reference in New Issue
Block a user