CREATE TABLE `ur_ingest_session` (
`ur_ingest_session_id` text PRIMARY KEY NOT NULL,
`device_id` text NOT NULL,
`behavior_id` text,
`behavior_json` text,
`ingest_started_at` TIMESTAMPTZ NOT NULL,
`ingest_finished_at` TIMESTAMPTZ,
`session_agent` text NOT NULL,
`elaboration` text,
`created_at` TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
`created_by` text DEFAULT 'UNKNOWN',
`updated_at` TIMESTAMPTZ,
`updated_by` text,
`deleted_at` TIMESTAMPTZ,
`deleted_by` text,
`activity_log` text,
FOREIGN KEY (`device_id`) REFERENCES `device`(`device_id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`behavior_id`) REFERENCES `behavior`(`behavior_id`) ON UPDATE no action ON DELETE no action,
CONSTRAINT "behavior_json_check_valid_json" CHECK(json_valid("ur_ingest_session"."behavior_json") OR "ur_ingest_session"."behavior_json" IS NULL),
CONSTRAINT "session_agent_check_valid_json" CHECK(json_valid("ur_ingest_session"."session_agent") OR "ur_ingest_session"."session_agent" IS NULL),
CONSTRAINT "elaboration_check_valid_json" CHECK(json_valid("ur_ingest_session"."elaboration") OR "ur_ingest_session"."elaboration" IS NULL)
)