Remove cookie_patterns legacy, migrate to tracker_patterns
Delete coredata.CookiePattern and all associated CRUD methods, rename shared types (CookiePatternOrderField, CookiePatternFilter, CookiePatternMatchType) to TrackerPattern equivalents, and migrate all API surfaces (GraphQL, MCP, CLI, n8n) to tracker_pattern naming. The worker was already migrated in the base branch; this commit completes the removal by dropping the old GraphQL schema/resolvers, service methods, CLI commands, and n8n operations that operated on the legacy cookie_patterns table. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -1,794 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"go.gearno.de/kit/pg"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/page"
|
||||
)
|
||||
|
||||
type (
|
||||
CookiePattern struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
CookieBannerID gid.GID `db:"cookie_banner_id"`
|
||||
CookieCategoryID gid.GID `db:"cookie_category_id"`
|
||||
Pattern string `db:"pattern"`
|
||||
MatchType CookiePatternMatchType `db:"match_type"`
|
||||
DisplayName string `db:"display_name"`
|
||||
MaxAgeSeconds *int `db:"max_age_seconds"`
|
||||
Description string `db:"description"`
|
||||
Source CookieSource `db:"source"`
|
||||
Excluded bool `db:"excluded"`
|
||||
LastMatchedAt *time.Time `db:"last_matched_at"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
CookiePatterns []*CookiePattern
|
||||
)
|
||||
|
||||
func (cp *CookiePattern) CursorKey(field CookiePatternOrderField) page.CursorKey {
|
||||
switch field {
|
||||
case CookiePatternOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(cp.ID, cp.CreatedAt)
|
||||
case CookiePatternOrderFieldName:
|
||||
return page.NewCursorKey(cp.ID, cp.DisplayName)
|
||||
case CookiePatternOrderFieldLastMatchedAt:
|
||||
if cp.LastMatchedAt == nil {
|
||||
return page.NewCursorKey(cp.ID, time.Time{})
|
||||
}
|
||||
return page.NewCursorKey(cp.ID, *cp.LastMatchedAt)
|
||||
case CookiePatternOrderFieldUpdatedAt:
|
||||
return page.NewCursorKey(cp.ID, cp.UpdatedAt)
|
||||
case CookiePatternOrderFieldSource:
|
||||
return page.NewCursorKey(cp.ID, string(cp.Source))
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", field))
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) AuthorizationAttributes(ctx context.Context, conn pg.Querier) (map[string]string, error) {
|
||||
q := `SELECT organization_id FROM cookie_patterns WHERE id = $1 LIMIT 1;`
|
||||
|
||||
var organizationID gid.GID
|
||||
if err := conn.QueryRow(ctx, q, cp.ID).Scan(&organizationID); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query cookie pattern authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
return map[string]string{"organization_id": organizationID.String()}, nil
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookiePatternID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND id = @cookie_pattern_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"cookie_pattern_id": cookiePatternID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
pattern, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[CookiePattern])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
return fmt.Errorf("cannot collect cookie pattern: %w", err)
|
||||
}
|
||||
|
||||
*cp = pattern
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) LoadByBannerIDAndPattern(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
pattern string,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_banner_id = @cookie_banner_id
|
||||
AND pattern = @pattern
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"pattern": pattern,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
p, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[CookiePattern])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
return fmt.Errorf("cannot collect cookie pattern: %w", err)
|
||||
}
|
||||
|
||||
*cp = p
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) FindMatchingPattern(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
cookieName string,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_banner_id = @cookie_banner_id
|
||||
AND (
|
||||
(match_type = @match_type_prefix AND starts_with(@cookie_name, pattern))
|
||||
OR (match_type = @match_type_exact AND pattern = @cookie_name)
|
||||
)
|
||||
ORDER BY
|
||||
CASE WHEN match_type = @match_type_exact AND pattern = @cookie_name THEN 0
|
||||
WHEN match_type = @match_type_prefix THEN 1
|
||||
ELSE 2
|
||||
END,
|
||||
LENGTH(pattern) DESC
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"cookie_name": cookieName,
|
||||
"match_type_prefix": CookiePatternMatchTypePrefix,
|
||||
"match_type_exact": CookiePatternMatchTypeExact,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
pattern, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[CookiePattern])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
return fmt.Errorf("cannot collect cookie pattern: %w", err)
|
||||
}
|
||||
|
||||
*cp = pattern
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cps *CookiePatterns) LoadByCookieCategoryID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieCategoryID gid.GID,
|
||||
cursor *page.Cursor[CookiePatternOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_category_id = @cookie_category_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"cookie_category_id": cookieCategoryID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
patterns, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[CookiePattern])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
*cps = patterns
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cps *CookiePatterns) CountByCookieCategoryID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieCategoryID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_category_id = @cookie_category_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"cookie_category_id": cookieCategoryID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
if err := row.Scan(&count); err != nil {
|
||||
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (cps *CookiePatterns) LoadAllByCookieBannerID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
filter *CookiePatternFilter,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_banner_id = @cookie_banner_id
|
||||
AND %s
|
||||
ORDER BY
|
||||
created_at ASC, id ASC;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"cookie_banner_id": cookieBannerID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
patterns, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[CookiePattern])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
*cps = patterns
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) Insert(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO cookie_patterns (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@cookie_banner_id,
|
||||
@cookie_category_id,
|
||||
@pattern,
|
||||
@match_type,
|
||||
@display_name,
|
||||
@max_age_seconds,
|
||||
@description,
|
||||
@source,
|
||||
@excluded,
|
||||
@last_matched_at,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": cp.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"organization_id": cp.OrganizationID,
|
||||
"cookie_banner_id": cp.CookieBannerID,
|
||||
"cookie_category_id": cp.CookieCategoryID,
|
||||
"pattern": cp.Pattern,
|
||||
"match_type": cp.MatchType,
|
||||
"display_name": cp.DisplayName,
|
||||
"max_age_seconds": cp.MaxAgeSeconds,
|
||||
"description": cp.Description,
|
||||
"source": cp.Source,
|
||||
"excluded": cp.Excluded,
|
||||
"last_matched_at": cp.LastMatchedAt,
|
||||
"created_at": cp.CreatedAt,
|
||||
"updated_at": cp.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "idx_cookie_patterns_unique_pattern_per_banner" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("cannot insert cookie pattern: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) InsertIfNotExists(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
) (bool, error) {
|
||||
q := `
|
||||
INSERT INTO cookie_patterns (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@cookie_banner_id,
|
||||
@cookie_category_id,
|
||||
@pattern,
|
||||
@match_type,
|
||||
@display_name,
|
||||
@max_age_seconds,
|
||||
@description,
|
||||
@source,
|
||||
@excluded,
|
||||
@last_matched_at,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
ON CONFLICT (cookie_banner_id, pattern) DO NOTHING
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": cp.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"organization_id": cp.OrganizationID,
|
||||
"cookie_banner_id": cp.CookieBannerID,
|
||||
"cookie_category_id": cp.CookieCategoryID,
|
||||
"pattern": cp.Pattern,
|
||||
"match_type": cp.MatchType,
|
||||
"display_name": cp.DisplayName,
|
||||
"max_age_seconds": cp.MaxAgeSeconds,
|
||||
"description": cp.Description,
|
||||
"source": cp.Source,
|
||||
"excluded": cp.Excluded,
|
||||
"last_matched_at": cp.LastMatchedAt,
|
||||
"created_at": cp.CreatedAt,
|
||||
"updated_at": cp.UpdatedAt,
|
||||
}
|
||||
|
||||
result, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("cannot insert cookie pattern: %w", err)
|
||||
}
|
||||
|
||||
return result.RowsAffected() > 0, nil
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) Update(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE cookie_patterns
|
||||
SET
|
||||
cookie_category_id = @cookie_category_id,
|
||||
display_name = @display_name,
|
||||
max_age_seconds = @max_age_seconds,
|
||||
description = @description,
|
||||
excluded = @excluded,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": cp.ID,
|
||||
"cookie_category_id": cp.CookieCategoryID,
|
||||
"display_name": cp.DisplayName,
|
||||
"max_age_seconds": cp.MaxAgeSeconds,
|
||||
"description": cp.Description,
|
||||
"excluded": cp.Excluded,
|
||||
"updated_at": cp.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
result, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "idx_cookie_patterns_unique_pattern_per_banner" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("cannot update cookie pattern: %w", err)
|
||||
}
|
||||
|
||||
if result.RowsAffected() == 0 {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cp *CookiePattern) Delete(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
DELETE FROM cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"id": cp.ID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot delete cookie pattern: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cps *CookiePatterns) RefreshLastMatchedAtByCookieBannerID(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE cookie_patterns
|
||||
SET
|
||||
last_matched_at = sub.max_detected
|
||||
FROM (
|
||||
SELECT cookie_pattern_id, MAX(last_detected_at) AS max_detected
|
||||
FROM cookies
|
||||
WHERE %[1]s AND cookie_banner_id = @cookie_banner_id
|
||||
GROUP BY cookie_pattern_id
|
||||
) sub
|
||||
WHERE
|
||||
cookie_patterns.id = sub.cookie_pattern_id
|
||||
AND %[1]s
|
||||
AND cookie_patterns.cookie_banner_id = @cookie_banner_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"cookie_banner_id": cookieBannerID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot refresh last_matched_at for banner patterns: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cps *CookiePatterns) LoadUncategorisedByCookieBannerID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
cursor *page.Cursor[CookiePatternOrderField],
|
||||
filter *CookiePatternFilter,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
max_age_seconds,
|
||||
description,
|
||||
source,
|
||||
excluded,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_banner_id = @cookie_banner_id
|
||||
AND cookie_category_id = (
|
||||
SELECT id FROM cookie_categories
|
||||
WHERE cookie_banner_id = @cookie_banner_id
|
||||
AND kind = @category_kind
|
||||
AND %s
|
||||
LIMIT 1
|
||||
)
|
||||
AND %s
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), scope.SQLFragment(), filter.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"category_kind": CookieCategoryKindUncategorised,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query uncategorised cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
patterns, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[CookiePattern])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect uncategorised cookie patterns: %w", err)
|
||||
}
|
||||
|
||||
*cps = patterns
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cps *CookiePatterns) CountUncategorisedByCookieBannerID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
filter *CookiePatternFilter,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
cookie_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_banner_id = @cookie_banner_id
|
||||
AND cookie_category_id = (
|
||||
SELECT id FROM cookie_categories
|
||||
WHERE cookie_banner_id = @cookie_banner_id
|
||||
AND kind = @category_kind
|
||||
AND %s
|
||||
LIMIT 1
|
||||
)
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), scope.SQLFragment(), filter.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"category_kind": CookieCategoryKindUncategorised,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
if err := row.Scan(&count); err != nil {
|
||||
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (cps *CookiePatterns) MoveToCategoryByCookieCategoryID(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
sourceCategoryID gid.GID,
|
||||
targetCategoryID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE cookie_patterns
|
||||
SET
|
||||
cookie_category_id = @target_category_id,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_category_id = @source_category_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"source_category_id": sourceCategoryID,
|
||||
"target_category_id": targetCategoryID,
|
||||
"updated_at": time.Now(),
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot move cookie patterns to category: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package coredata
|
||||
|
||||
import "fmt"
|
||||
|
||||
type CookiePatternOrderField string
|
||||
|
||||
const (
|
||||
CookiePatternOrderFieldCreatedAt CookiePatternOrderField = "CREATED_AT"
|
||||
CookiePatternOrderFieldName CookiePatternOrderField = "NAME"
|
||||
CookiePatternOrderFieldLastMatchedAt CookiePatternOrderField = "LAST_MATCHED_AT"
|
||||
CookiePatternOrderFieldUpdatedAt CookiePatternOrderField = "UPDATED_AT"
|
||||
CookiePatternOrderFieldSource CookiePatternOrderField = "SOURCE"
|
||||
)
|
||||
|
||||
func (p CookiePatternOrderField) Column() string {
|
||||
switch p {
|
||||
case CookiePatternOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
case CookiePatternOrderFieldName:
|
||||
return "display_name"
|
||||
case CookiePatternOrderFieldLastMatchedAt:
|
||||
return "COALESCE(last_matched_at, '0001-01-01T00:00:00Z'::timestamptz)"
|
||||
case CookiePatternOrderFieldUpdatedAt:
|
||||
return "updated_at"
|
||||
case CookiePatternOrderFieldSource:
|
||||
return "source"
|
||||
}
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
func (p CookiePatternOrderField) IsValid() bool {
|
||||
switch p {
|
||||
case CookiePatternOrderFieldCreatedAt,
|
||||
CookiePatternOrderFieldName,
|
||||
CookiePatternOrderFieldLastMatchedAt,
|
||||
CookiePatternOrderFieldUpdatedAt,
|
||||
CookiePatternOrderFieldSource:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p CookiePatternOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p *CookiePatternOrderField) UnmarshalText(text []byte) error {
|
||||
*p = CookiePatternOrderField(text)
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid CookiePatternOrderField", string(text))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p CookiePatternOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
@@ -111,7 +111,7 @@ const (
|
||||
CookieEntityType uint16 = 85
|
||||
CookieBannerTranslationEntityType uint16 = 86
|
||||
AgentRunEntityType uint16 = 87
|
||||
CookiePatternEntityType uint16 = 88
|
||||
_ uint16 = 88 // CookiePatternEntityType - removed
|
||||
TrackerPatternEntityType uint16 = 89
|
||||
DetectedTrackerEntityType uint16 = 90
|
||||
)
|
||||
@@ -282,8 +282,6 @@ func NewEntityFromID(id gid.GID) (any, bool) {
|
||||
return &CookieBannerTranslation{ID: id}, true
|
||||
case AgentRunEntityType:
|
||||
return &AgentRun{ID: id}, true
|
||||
case CookiePatternEntityType:
|
||||
return &CookiePattern{ID: id}, true
|
||||
case TrackerPatternEntityType:
|
||||
return &TrackerPattern{ID: id}, true
|
||||
case DetectedTrackerEntityType:
|
||||
|
||||
@@ -30,40 +30,40 @@ import (
|
||||
|
||||
type (
|
||||
TrackerPattern struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
CookieBannerID gid.GID `db:"cookie_banner_id"`
|
||||
CookieCategoryID gid.GID `db:"cookie_category_id"`
|
||||
TrackerType TrackerType `db:"tracker_type"`
|
||||
Pattern string `db:"pattern"`
|
||||
MatchType CookiePatternMatchType `db:"match_type"`
|
||||
DisplayName string `db:"display_name"`
|
||||
Description string `db:"description"`
|
||||
Excluded bool `db:"excluded"`
|
||||
MaxAgeSeconds *int `db:"max_age_seconds"`
|
||||
Source *CookieSource `db:"source"`
|
||||
LastMatchedAt *time.Time `db:"last_matched_at"`
|
||||
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"`
|
||||
CookieCategoryID gid.GID `db:"cookie_category_id"`
|
||||
TrackerType TrackerType `db:"tracker_type"`
|
||||
Pattern string `db:"pattern"`
|
||||
MatchType TrackerPatternMatchType `db:"match_type"`
|
||||
DisplayName string `db:"display_name"`
|
||||
Description string `db:"description"`
|
||||
Excluded bool `db:"excluded"`
|
||||
MaxAgeSeconds *int `db:"max_age_seconds"`
|
||||
Source *CookieSource `db:"source"`
|
||||
LastMatchedAt *time.Time `db:"last_matched_at"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
TrackerPatterns []*TrackerPattern
|
||||
)
|
||||
|
||||
func (tp *TrackerPattern) CursorKey(field CookiePatternOrderField) page.CursorKey {
|
||||
func (tp *TrackerPattern) CursorKey(field TrackerPatternOrderField) page.CursorKey {
|
||||
switch field {
|
||||
case CookiePatternOrderFieldCreatedAt:
|
||||
case TrackerPatternOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(tp.ID, tp.CreatedAt)
|
||||
case CookiePatternOrderFieldName:
|
||||
case TrackerPatternOrderFieldName:
|
||||
return page.NewCursorKey(tp.ID, tp.DisplayName)
|
||||
case CookiePatternOrderFieldLastMatchedAt:
|
||||
case TrackerPatternOrderFieldLastMatchedAt:
|
||||
if tp.LastMatchedAt == nil {
|
||||
return page.NewCursorKey(tp.ID, time.Time{})
|
||||
}
|
||||
return page.NewCursorKey(tp.ID, *tp.LastMatchedAt)
|
||||
case CookiePatternOrderFieldUpdatedAt:
|
||||
case TrackerPatternOrderFieldUpdatedAt:
|
||||
return page.NewCursorKey(tp.ID, tp.UpdatedAt)
|
||||
case CookiePatternOrderFieldSource:
|
||||
case TrackerPatternOrderFieldSource:
|
||||
if tp.Source == nil {
|
||||
return page.NewCursorKey(tp.ID, "")
|
||||
}
|
||||
@@ -254,8 +254,8 @@ LIMIT 1;
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"tracker_type": trackerType,
|
||||
"identifier": identifier,
|
||||
"match_type_prefix": CookiePatternMatchTypePrefix,
|
||||
"match_type_exact": CookiePatternMatchTypeExact,
|
||||
"match_type_prefix": TrackerPatternMatchTypePrefix,
|
||||
"match_type_exact": TrackerPatternMatchTypeExact,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
@@ -504,7 +504,7 @@ func (tps *TrackerPatterns) LoadAllByCookieBannerID(
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
filter *CookiePatternFilter,
|
||||
filter *TrackerPatternFilter,
|
||||
trackerType *TrackerType,
|
||||
) error {
|
||||
trackerTypeFragment := "TRUE"
|
||||
@@ -605,8 +605,8 @@ func (tps *TrackerPatterns) LoadUncategorisedByCookieBannerID(
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
cursor *page.Cursor[CookiePatternOrderField],
|
||||
filter *CookiePatternFilter,
|
||||
cursor *page.Cursor[TrackerPatternOrderField],
|
||||
filter *TrackerPatternFilter,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -671,7 +671,7 @@ func (tps *TrackerPatterns) CountUncategorisedByCookieBannerID(
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
filter *CookiePatternFilter,
|
||||
filter *TrackerPatternFilter,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -709,3 +709,120 @@ WHERE
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (tps *TrackerPatterns) LoadByCookieCategoryID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieCategoryID gid.GID,
|
||||
cursor *page.Cursor[TrackerPatternOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
cookie_category_id,
|
||||
tracker_type,
|
||||
pattern,
|
||||
match_type,
|
||||
display_name,
|
||||
description,
|
||||
excluded,
|
||||
max_age_seconds,
|
||||
source,
|
||||
last_matched_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
tracker_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_category_id = @cookie_category_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"cookie_category_id": cookieCategoryID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query tracker patterns: %w", err)
|
||||
}
|
||||
|
||||
patterns, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[TrackerPattern])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect tracker patterns: %w", err)
|
||||
}
|
||||
|
||||
*tps = patterns
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tps *TrackerPatterns) CountByCookieCategoryID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieCategoryID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
tracker_patterns
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_category_id = @cookie_category_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"cookie_category_id": cookieCategoryID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
if err := row.Scan(&count); err != nil {
|
||||
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (tps *TrackerPatterns) MoveToCategoryByCookieCategoryID(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
sourceCategoryID gid.GID,
|
||||
targetCategoryID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE tracker_patterns
|
||||
SET
|
||||
cookie_category_id = @target_category_id,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_category_id = @source_category_id
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"source_category_id": sourceCategoryID,
|
||||
"target_category_id": targetCategoryID,
|
||||
"updated_at": time.Now(),
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot move tracker patterns to category: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,37 +19,37 @@ import (
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
)
|
||||
|
||||
type CookiePatternFilter struct {
|
||||
matchType *CookiePatternMatchType
|
||||
type TrackerPatternFilter struct {
|
||||
matchType *TrackerPatternMatchType
|
||||
cookieCategoryID *gid.GID
|
||||
excluded *bool
|
||||
query *string
|
||||
source *CookieSource
|
||||
}
|
||||
|
||||
func NewCookiePatternFilter(
|
||||
matchType *CookiePatternMatchType,
|
||||
func NewTrackerPatternFilter(
|
||||
matchType *TrackerPatternMatchType,
|
||||
cookieCategoryID *gid.GID,
|
||||
excluded *bool,
|
||||
) *CookiePatternFilter {
|
||||
return &CookiePatternFilter{
|
||||
) *TrackerPatternFilter {
|
||||
return &TrackerPatternFilter{
|
||||
matchType: matchType,
|
||||
cookieCategoryID: cookieCategoryID,
|
||||
excluded: excluded,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *CookiePatternFilter) WithQuery(query *string) *CookiePatternFilter {
|
||||
func (f *TrackerPatternFilter) WithQuery(query *string) *TrackerPatternFilter {
|
||||
f.query = query
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *CookiePatternFilter) WithSource(source *CookieSource) *CookiePatternFilter {
|
||||
func (f *TrackerPatternFilter) WithSource(source *CookieSource) *TrackerPatternFilter {
|
||||
f.source = source
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *CookiePatternFilter) SQLFragment() string {
|
||||
func (f *TrackerPatternFilter) SQLFragment() string {
|
||||
if f == nil {
|
||||
return "TRUE"
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (f *CookiePatternFilter) SQLFragment() string {
|
||||
)`
|
||||
}
|
||||
|
||||
func (f *CookiePatternFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
func (f *TrackerPatternFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
if f == nil {
|
||||
return pgx.StrictNamedArgs{}
|
||||
}
|
||||
@@ -19,25 +19,25 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CookiePatternMatchType string
|
||||
type TrackerPatternMatchType string
|
||||
|
||||
const (
|
||||
CookiePatternMatchTypeExact CookiePatternMatchType = "EXACT"
|
||||
CookiePatternMatchTypePrefix CookiePatternMatchType = "PREFIX"
|
||||
TrackerPatternMatchTypeExact TrackerPatternMatchType = "EXACT"
|
||||
TrackerPatternMatchTypePrefix TrackerPatternMatchType = "PREFIX"
|
||||
)
|
||||
|
||||
func CookiePatternMatchTypes() []CookiePatternMatchType {
|
||||
return []CookiePatternMatchType{
|
||||
CookiePatternMatchTypeExact,
|
||||
CookiePatternMatchTypePrefix,
|
||||
func TrackerPatternMatchTypes() []TrackerPatternMatchType {
|
||||
return []TrackerPatternMatchType{
|
||||
TrackerPatternMatchTypeExact,
|
||||
TrackerPatternMatchTypePrefix,
|
||||
}
|
||||
}
|
||||
|
||||
func (m CookiePatternMatchType) String() string {
|
||||
func (m TrackerPatternMatchType) String() string {
|
||||
return string(m)
|
||||
}
|
||||
|
||||
func (m *CookiePatternMatchType) Scan(value any) error {
|
||||
func (m *TrackerPatternMatchType) Scan(value any) error {
|
||||
var v string
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
@@ -45,26 +45,26 @@ func (m *CookiePatternMatchType) Scan(value any) error {
|
||||
case []byte:
|
||||
v = string(val)
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for CookiePatternMatchType: %T", value)
|
||||
return fmt.Errorf("unsupported type for TrackerPatternMatchType: %T", value)
|
||||
}
|
||||
|
||||
switch CookiePatternMatchType(v) {
|
||||
case CookiePatternMatchTypeExact:
|
||||
*m = CookiePatternMatchTypeExact
|
||||
case CookiePatternMatchTypePrefix:
|
||||
*m = CookiePatternMatchTypePrefix
|
||||
switch TrackerPatternMatchType(v) {
|
||||
case TrackerPatternMatchTypeExact:
|
||||
*m = TrackerPatternMatchTypeExact
|
||||
case TrackerPatternMatchTypePrefix:
|
||||
*m = TrackerPatternMatchTypePrefix
|
||||
default:
|
||||
return fmt.Errorf("invalid CookiePatternMatchType value: %q", v)
|
||||
return fmt.Errorf("invalid TrackerPatternMatchType value: %q", v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m CookiePatternMatchType) Value() (driver.Value, error) {
|
||||
func (m TrackerPatternMatchType) Value() (driver.Value, error) {
|
||||
switch m {
|
||||
case CookiePatternMatchTypeExact,
|
||||
CookiePatternMatchTypePrefix:
|
||||
case TrackerPatternMatchTypeExact,
|
||||
TrackerPatternMatchTypePrefix:
|
||||
return string(m), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid CookiePatternMatchType: %s", m)
|
||||
return nil, fmt.Errorf("invalid TrackerPatternMatchType: %s", m)
|
||||
}
|
||||
}
|
||||
71
pkg/coredata/tracker_pattern_order_field.go
Normal file
71
pkg/coredata/tracker_pattern_order_field.go
Normal file
@@ -0,0 +1,71 @@
|
||||
// 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.
|
||||
|
||||
package coredata
|
||||
|
||||
import "fmt"
|
||||
|
||||
type TrackerPatternOrderField string
|
||||
|
||||
const (
|
||||
TrackerPatternOrderFieldCreatedAt TrackerPatternOrderField = "CREATED_AT"
|
||||
TrackerPatternOrderFieldName TrackerPatternOrderField = "NAME"
|
||||
TrackerPatternOrderFieldLastMatchedAt TrackerPatternOrderField = "LAST_MATCHED_AT"
|
||||
TrackerPatternOrderFieldUpdatedAt TrackerPatternOrderField = "UPDATED_AT"
|
||||
TrackerPatternOrderFieldSource TrackerPatternOrderField = "SOURCE"
|
||||
)
|
||||
|
||||
func (p TrackerPatternOrderField) Column() string {
|
||||
switch p {
|
||||
case TrackerPatternOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
case TrackerPatternOrderFieldName:
|
||||
return "display_name"
|
||||
case TrackerPatternOrderFieldLastMatchedAt:
|
||||
return "COALESCE(last_matched_at, '0001-01-01T00:00:00Z'::timestamptz)"
|
||||
case TrackerPatternOrderFieldUpdatedAt:
|
||||
return "updated_at"
|
||||
case TrackerPatternOrderFieldSource:
|
||||
return "source"
|
||||
}
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
func (p TrackerPatternOrderField) IsValid() bool {
|
||||
switch p {
|
||||
case TrackerPatternOrderFieldCreatedAt,
|
||||
TrackerPatternOrderFieldName,
|
||||
TrackerPatternOrderFieldLastMatchedAt,
|
||||
TrackerPatternOrderFieldUpdatedAt,
|
||||
TrackerPatternOrderFieldSource:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p TrackerPatternOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p *TrackerPatternOrderField) UnmarshalText(text []byte) error {
|
||||
*p = TrackerPatternOrderField(text)
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid TrackerPatternOrderField", string(text))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p TrackerPatternOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
Reference in New Issue
Block a user