Files
apskel-pos-backend/migrations/000096_create_customer_devices.up.sql
2026-09-30 15:31:11 +07:00

18 lines
867 B
SQL

-- Devices of the customer app, so customers can get push notifications through FCM
-- (docs/prd-point-coin.md F5: the recipient of a transfer is notified). user_devices
-- only holds staff devices.
CREATE TABLE customer_devices (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
customer_id UUID NOT NULL REFERENCES customers(id) ON DELETE CASCADE,
device_id VARCHAR(255) NOT NULL,
platform VARCHAR(50) CHECK (platform IN ('android', 'ios', 'web')),
fcm_token VARCHAR(512) NOT NULL,
app_version VARCHAR(50),
last_active_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE UNIQUE INDEX idx_customer_devices_customer_device ON customer_devices(customer_id, device_id);
CREATE INDEX idx_customer_devices_fcm_token ON customer_devices(fcm_token);