@artil-ai/connect 0.0.0-stage → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,118 @@
1
+ CREATE TABLE `access` (
2
+ `account_id` text NOT NULL,
3
+ `channel` text NOT NULL,
4
+ `admit` text NOT NULL,
5
+ `senders` text NOT NULL,
6
+ PRIMARY KEY(`account_id`, `channel`),
7
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade
8
+ );
9
+ --> statement-breakpoint
10
+ CREATE TABLE `accounts` (
11
+ `id` text PRIMARY KEY NOT NULL,
12
+ `name` text NOT NULL,
13
+ `created_at` integer NOT NULL
14
+ );
15
+ --> statement-breakpoint
16
+ CREATE UNIQUE INDEX `accounts_name_idx` ON `accounts` (lower("name"));--> statement-breakpoint
17
+ CREATE TABLE `addresses` (
18
+ `id` text PRIMARY KEY NOT NULL,
19
+ `account_id` text NOT NULL,
20
+ `channel` text NOT NULL,
21
+ `value` text NOT NULL,
22
+ `credentials` text,
23
+ `created_at` integer NOT NULL,
24
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade
25
+ );
26
+ --> statement-breakpoint
27
+ CREATE UNIQUE INDEX `addresses_channel_value_idx` ON `addresses` (`channel`,`value`) WHERE "addresses"."credentials" is not null;--> statement-breakpoint
28
+ CREATE INDEX `addresses_account_id_idx` ON `addresses` (`account_id`);--> statement-breakpoint
29
+ CREATE TABLE `connections` (
30
+ `account_id` text PRIMARY KEY NOT NULL,
31
+ `id` text NOT NULL,
32
+ `token_hash` text NOT NULL,
33
+ `client` text NOT NULL,
34
+ `machine` text,
35
+ `starts_after` integer NOT NULL,
36
+ `listened_at` integer,
37
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade,
38
+ FOREIGN KEY (`token_hash`) REFERENCES `tokens`(`hash`) ON UPDATE no action ON DELETE cascade
39
+ );
40
+ --> statement-breakpoint
41
+ CREATE TABLE `events` (
42
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
43
+ `account_id` text NOT NULL,
44
+ `type` text NOT NULL,
45
+ `channel` text NOT NULL,
46
+ `message_id` text NOT NULL,
47
+ `text` text,
48
+ `sender` text,
49
+ `thread` text,
50
+ `to_thread` text,
51
+ `client` text,
52
+ `created_at` integer NOT NULL,
53
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade
54
+ );
55
+ --> statement-breakpoint
56
+ CREATE INDEX `events_account_id_id_idx` ON `events` (`account_id`,`id`);--> statement-breakpoint
57
+ CREATE TABLE `files` (
58
+ `id` text PRIMARY KEY NOT NULL,
59
+ `account_id` text NOT NULL,
60
+ `message_id` text NOT NULL,
61
+ `name` text NOT NULL,
62
+ `type` text NOT NULL,
63
+ `size` integer NOT NULL,
64
+ `key` text,
65
+ `expires_at` integer,
66
+ `created_at` integer NOT NULL,
67
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade
68
+ );
69
+ --> statement-breakpoint
70
+ CREATE INDEX `files_message_id_idx` ON `files` (`message_id`);--> statement-breakpoint
71
+ CREATE TABLE `messages` (
72
+ `id` text PRIMARY KEY NOT NULL,
73
+ `account_id` text NOT NULL,
74
+ `address_id` text NOT NULL,
75
+ `channel` text NOT NULL,
76
+ `direction` text NOT NULL,
77
+ `external_id` text,
78
+ `counterpart` text NOT NULL,
79
+ `counterpart_name` text,
80
+ `to` text NOT NULL,
81
+ `text` text NOT NULL,
82
+ `status` text NOT NULL,
83
+ `refusal` text,
84
+ `admission` text,
85
+ `error` text,
86
+ `created_at` integer NOT NULL,
87
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade,
88
+ FOREIGN KEY (`address_id`) REFERENCES `addresses`(`id`) ON UPDATE no action ON DELETE cascade
89
+ );
90
+ --> statement-breakpoint
91
+ CREATE INDEX `messages_account_id_created_at_idx` ON `messages` (`account_id`,`created_at`);--> statement-breakpoint
92
+ CREATE UNIQUE INDEX `messages_address_id_external_id_idx` ON `messages` (`address_id`,`direction`,`external_id`) WHERE "messages"."external_id" is not null;--> statement-breakpoint
93
+ CREATE TABLE `sign_ins` (
94
+ `id` text PRIMARY KEY NOT NULL,
95
+ `kind` text NOT NULL,
96
+ `client_id` text,
97
+ `client_name` text NOT NULL,
98
+ `redirect_uri` text NOT NULL,
99
+ `challenge` text NOT NULL,
100
+ `state` text,
101
+ `account_id` text,
102
+ `code_hash` text,
103
+ `expires_at` integer NOT NULL,
104
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade
105
+ );
106
+ --> statement-breakpoint
107
+ CREATE UNIQUE INDEX `sign_ins_code_hash_unique` ON `sign_ins` (`code_hash`);--> statement-breakpoint
108
+ CREATE TABLE `tokens` (
109
+ `id` text PRIMARY KEY NOT NULL,
110
+ `account_id` text NOT NULL,
111
+ `hash` text NOT NULL,
112
+ `name` text NOT NULL,
113
+ `created_at` integer NOT NULL,
114
+ FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade
115
+ );
116
+ --> statement-breakpoint
117
+ CREATE UNIQUE INDEX `tokens_hash_unique` ON `tokens` (`hash`);--> statement-breakpoint
118
+ CREATE INDEX `tokens_account_id_idx` ON `tokens` (`account_id`);
@@ -0,0 +1,2 @@
1
+ ALTER TABLE `messages` ADD `author` text;--> statement-breakpoint
2
+ ALTER TABLE `messages` ADD `author_name` text;
@@ -0,0 +1 @@
1
+ ALTER TABLE `messages` ADD `client_thread` text;
@@ -0,0 +1,8 @@
1
+ -- A message the Message URL relayed kept its sender's thread only on the event the recipient got.
2
+ -- The sender's copy keeps it now, so an answer to the message still wakes that thread.
3
+ UPDATE `messages` SET `client_thread` = (
4
+ SELECT `events`.`thread` FROM `events`
5
+ WHERE `events`.`message_id` = `messages`.`external_id`
6
+ AND json_extract(`events`.`sender`, '$.id') = `messages`.`account_id`
7
+ )
8
+ WHERE `channel` = 'url' AND `direction` = 'outbound' AND `client_thread` IS NULL;
@@ -0,0 +1,4 @@
1
+ ALTER TABLE `events` DROP COLUMN `text`;--> statement-breakpoint
2
+ ALTER TABLE `events` DROP COLUMN `sender`;--> statement-breakpoint
3
+ ALTER TABLE `events` DROP COLUMN `thread`;--> statement-breakpoint
4
+ ALTER TABLE `events` DROP COLUMN `client`;
@@ -0,0 +1 @@
1
+ ALTER TABLE `messages` ADD `external_thread` text;
@@ -0,0 +1 @@
1
+ ALTER TABLE `messages` ADD `answered_at` integer;