forked from wultra/powerauth-push-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_push_server_schema.sql
More file actions
96 lines (75 loc) · 2.77 KB
/
Copy pathcreate_push_server_schema.sql
File metadata and controls
96 lines (75 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
--- DB Sequences
---
CREATE SEQUENCE push_credentials_seq;
CREATE SEQUENCE push_device_registration_seq;
CREATE SEQUENCE push_message_seq;
CREATE SEQUENCE push_campaign_seq;
CREATE SEQUENCE push_campaign_user_seq;
---
--- DB Tables
---
-- Create table for application credentials used for APNS and FCM
CREATE TABLE push_app_credentials (
id INTEGER NOT NULL CONSTRAINT push_app_credentials_pkey PRIMARY KEY,
app_id INTEGER NOT NULL,
ios_key_id VARCHAR(255),
ios_private_key BYTEA,
ios_team_id VARCHAR(255),
ios_bundle VARCHAR(255),
ios_environment VARCHAR(32),
android_private_key BYTEA,
android_project_id VARCHAR(255)
);
-- Create table for registered devices
CREATE TABLE push_device_registration (
id INTEGER NOT NULL CONSTRAINT push_device_registration_pkey PRIMARY KEY,
activation_id VARCHAR(37),
user_id VARCHAR(255),
app_id INTEGER NOT NULL,
platform VARCHAR(255) NOT NULL,
push_token VARCHAR(255) NOT NULL,
timestamp_last_registered TIMESTAMP(6) NOT NULL,
is_active BOOLEAN
);
-- Create table for optional auditing of sent push messages
CREATE TABLE push_message (
id INTEGER NOT NULL CONSTRAINT push_message_pkey PRIMARY KEY,
device_registration_id INTEGER NOT NULL,
user_id VARCHAR(255) NOT NULL,
activation_id VARCHAR(37),
is_silent BOOLEAN DEFAULT false NOT NULL,
is_personal BOOLEAN DEFAULT false NOT NULL,
message_body VARCHAR(2048) NOT NULL,
timestamp_created TIMESTAMP(6) NOT NULL,
status INTEGER NOT NULL
);
-- Create table for push message campaigns
CREATE TABLE push_campaign (
id INTEGER NOT NULL CONSTRAINT push_campaign_pkey PRIMARY KEY,
app_id INTEGER NOT NULL,
message VARCHAR(4000) NOT NULL,
is_sent BOOLEAN DEFAULT false NOT NULL,
timestamp_created TIMESTAMP(6) NOT NULL,
timestamp_sent TIMESTAMP(6),
timestamp_completed TIMESTAMP(6)
);
-- Create table for push campaign user list
CREATE TABLE push_campaign_user (
id INTEGER NOT NULL CONSTRAINT push_campaign_user_pkey PRIMARY KEY,
campaign_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
timestamp_created TIMESTAMP(6) NOT NULL
);
--
-- DB Indexes (recommended for better performance)
--
CREATE UNIQUE INDEX push_app_cred_app ON push_app_credentials (app_id);
CREATE INDEX push_device_app_token ON push_device_registration (app_id, push_token);
CREATE INDEX push_device_user_app ON push_device_registration (user_id, app_id);
CREATE UNIQUE INDEX push_device_activation ON push_device_registration (activation_id);
CREATE UNIQUE INDEX push_device_activation_token ON push_device_registration (activation_id, push_token);
CREATE INDEX push_message_status ON push_message (status);
CREATE INDEX push_campaign_sent ON push_campaign (is_sent);
CREATE INDEX push_campaign_user_campaign ON push_campaign_user (campaign_id, user_id);
CREATE INDEX push_campaign_user_detail ON push_campaign_user (user_id);