Add organization_id to cookie_banner_versions, cookie_categories, and cookie_consent_records so AuthorizationAttributes can return it directly without JOINing back to cookie_banners. Document the pattern in contrib/claude/coredata.md. Signed-off-by: Émile Ré <emile@getprobo.com>
53 lines
2.3 KiB
SQL
53 lines
2.3 KiB
SQL
-- 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.
|
|
|
|
-- Replace cookie_banner_state enum: DRAFT/PUBLISHED/DISABLED → ACTIVE/INACTIVE
|
|
CREATE TYPE cookie_banner_state_new AS ENUM ('ACTIVE', 'INACTIVE');
|
|
|
|
ALTER TABLE cookie_banners
|
|
ALTER COLUMN state TYPE cookie_banner_state_new
|
|
USING CASE
|
|
WHEN state::text = 'DISABLED' THEN 'INACTIVE'::cookie_banner_state_new
|
|
ELSE 'ACTIVE'::cookie_banner_state_new
|
|
END;
|
|
|
|
DROP TYPE cookie_banner_state;
|
|
ALTER TYPE cookie_banner_state_new RENAME TO cookie_banner_state;
|
|
|
|
-- Version state for cookie banner configuration snapshots
|
|
CREATE TYPE cookie_banner_version_state AS ENUM ('DRAFT', 'PUBLISHED');
|
|
|
|
CREATE TABLE cookie_banner_versions (
|
|
id TEXT PRIMARY KEY,
|
|
tenant_id TEXT NOT NULL,
|
|
organization_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
|
cookie_banner_id TEXT NOT NULL REFERENCES cookie_banners(id) ON DELETE CASCADE,
|
|
version INTEGER NOT NULL,
|
|
state cookie_banner_version_state NOT NULL,
|
|
snapshot JSONB NOT NULL,
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
CONSTRAINT cookie_banner_versions_banner_version_key
|
|
UNIQUE (cookie_banner_id, version)
|
|
);
|
|
|
|
-- Denormalize organization_id onto categories and consent records
|
|
ALTER TABLE cookie_categories
|
|
ADD COLUMN organization_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE;
|
|
|
|
ALTER TABLE cookie_consent_records
|
|
ADD COLUMN organization_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
|
ADD COLUMN cookie_banner_version_id TEXT NOT NULL REFERENCES cookie_banner_versions(id);
|