mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-03 00:52:32 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
74 lines
2.7 KiB
SQL
74 lines
2.7 KiB
SQL
-- Temporary validation table for the personinsights-writer service.
|
|
--
|
|
-- This table mirrors insights_person (minus is_user_id) and is used during the
|
|
-- validation phase to verify that personinsights's write pipeline produces correct
|
|
-- person state. It is NOT the production write target.
|
|
--
|
|
-- Once validation is complete and we're ready to cut over, the writer switches
|
|
-- to writing directly to insights_person (via PG_TARGET_TABLE config), and this
|
|
-- table can be dropped.
|
|
--
|
|
-- This migration is idempotent and safe to re-run.
|
|
|
|
CREATE SEQUENCE IF NOT EXISTS personinsights_person_tmp_id_seq;
|
|
|
|
CREATE TABLE IF NOT EXISTS personinsights_person_tmp (
|
|
id BIGINT NOT NULL DEFAULT nextval('personinsights_person_tmp_id_seq'),
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
properties_last_updated_at JSONB,
|
|
properties_last_operation JSONB,
|
|
properties JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
is_identified BOOLEAN NOT NULL DEFAULT false,
|
|
uuid UUID NOT NULL,
|
|
version BIGINT,
|
|
team_id INTEGER NOT NULL,
|
|
last_seen_at TIMESTAMP WITH TIME ZONE
|
|
) PARTITION BY HASH (team_id);
|
|
|
|
-- Tie the sequence lifecycle to the table so DROP TABLE also drops the
|
|
-- sequence. Idempotent — re-running with the same owner is a no-op.
|
|
ALTER SEQUENCE personinsights_person_tmp_id_seq OWNED BY personinsights_person_tmp.id;
|
|
|
|
-- Primary key (idempotent: only add if not exists)
|
|
DO $$
|
|
BEGIN
|
|
IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'personinsights_person_tmp_pkey'
|
|
AND conrelid = 'personinsights_person_tmp'::regclass
|
|
) THEN
|
|
ALTER TABLE personinsights_person_tmp
|
|
ADD CONSTRAINT personinsights_person_tmp_pkey PRIMARY KEY (team_id, id);
|
|
END IF;
|
|
END $$;
|
|
|
|
CREATE UNIQUE INDEX IF NOT EXISTS personinsights_person_tmp_uuid_idx
|
|
ON personinsights_person_tmp (team_id, uuid);
|
|
|
|
-- 64 hash partitions matching the existing insights_person scheme
|
|
DO $$
|
|
DECLARE
|
|
num_partitions INTEGER := 64;
|
|
i INTEGER;
|
|
BEGIN
|
|
FOR i IN 0..(num_partitions - 1) LOOP
|
|
EXECUTE format(
|
|
'CREATE TABLE IF NOT EXISTS personinsights_person_tmp_p%s PARTITION OF personinsights_person_tmp FOR VALUES WITH (MODULUS %s, REMAINDER %s)',
|
|
i, num_partitions, i
|
|
);
|
|
END LOOP;
|
|
END $$;
|
|
|
|
-- Properties size check matching the existing constraint
|
|
DO $$
|
|
BEGIN
|
|
IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'personinsights_person_tmp_check_properties_size'
|
|
AND conrelid = 'personinsights_person_tmp'::regclass
|
|
) THEN
|
|
ALTER TABLE personinsights_person_tmp ADD CONSTRAINT personinsights_person_tmp_check_properties_size
|
|
CHECK (pg_column_size(properties) <= 655360) NOT VALID;
|
|
END IF;
|
|
END $$;
|