CREATE TABLE "device" (
"device_id" VARCHAR PRIMARY KEY NOT NULL,
"name" TEXT NOT NULL,
"state" TEXT CHECK(json_valid(state)) NOT NULL,
"boundary" TEXT NOT NULL,
"segmentation" TEXT CHECK(json_valid(segmentation) OR segmentation IS NULL),
"state_sysinfo" TEXT CHECK(json_valid(state_sysinfo) OR state_sysinfo IS NULL),
"elaboration" TEXT CHECK(json_valid(elaboration) OR elaboration IS NULL),
"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,
UNIQUE("name", "state", "boundary")
)