pub const POSTGRES_PUSH_DEVICES_MIGRATION_SQL: &str = "-- Reference schema for baukit-push\'s PostgresDeviceRegistry.\n--\n-- Copy this file into the product\'s own ordered migrations. Products own\n-- migration execution; baukit-push deliberately does not migrate on startup.\n--\n-- Baukit does not own the owner table and cannot name it here. Join ownership\n-- in a product migration so erasing an owner erases their devices:\n--\n-- ALTER TABLE push_devices\n-- ADD CONSTRAINT push_devices_owner_fk\n-- FOREIGN KEY (owner_id) REFERENCES <owner table> (id) ON DELETE CASCADE;\n--\n-- The token is the primary key, so one device token belongs to at most one\n-- owner. The registry enforces the per-owner cap in code, not here.\n\nCREATE TABLE push_devices (\n token TEXT PRIMARY KEY CHECK (\n octet_length(token) BETWEEN 1 AND 512 AND token ~ \'^[!-~]+$\'\n ),\n owner_id UUID NOT NULL,\n platform TEXT NOT NULL CHECK (platform IN (\'ios\', \'android\')),\n time_zone TEXT CHECK (\n octet_length(time_zone) BETWEEN 1 AND 64 AND time_zone ~ \'^[A-Za-z0-9/_+-]+$\'\n ),\n created_at TIMESTAMPTZ NOT NULL,\n last_registered_at TIMESTAMPTZ NOT NULL,\n CHECK (last_registered_at >= created_at)\n);\n\nCOMMENT ON TABLE push_devices IS\n \'Push device tokens stored by baukit-push::PostgresDeviceRegistry; a token addresses one device and must never be logged\';\n\nCREATE INDEX push_devices_owner_registered_idx\n ON push_devices (owner_id, last_registered_at DESC, created_at DESC, token DESC);\n";Expand description
Reference PostgreSQL schema for the sqlx-postgres feature’s PostgresDeviceRegistry.
Copy this SQL into a product migration; do not execute it dynamically during
application startup. Then add the product’s owner foreign key with
ON DELETE CASCADE, as the file’s header describes.