@hollware/server 0.1.0 → 0.3.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,57 @@
1
+ CREATE TABLE `deliveries` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `site_id` text NOT NULL,
4
+ `event_id` text NOT NULL,
5
+ `subscriber` text NOT NULL,
6
+ `attempts` integer NOT NULL,
7
+ `delivered_at` text,
8
+ `last_error` text,
9
+ `created_at` text NOT NULL,
10
+ `updated_at` text NOT NULL,
11
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
12
+ FOREIGN KEY (`event_id`,`site_id`) REFERENCES `outbox`(`id`,`site_id`) ON UPDATE no action ON DELETE no action,
13
+ CONSTRAINT "deliveries_attempts" CHECK("deliveries"."attempts" >= 0)
14
+ );
15
+ --> statement-breakpoint
16
+ CREATE UNIQUE INDEX `deliveries_id_site` ON `deliveries` (`id`,`site_id`);--> statement-breakpoint
17
+ CREATE UNIQUE INDEX `deliveries_event_subscriber` ON `deliveries` (`event_id`,`subscriber`);--> statement-breakpoint
18
+ CREATE TABLE `outbox` (
19
+ `id` text PRIMARY KEY NOT NULL,
20
+ `site_id` text NOT NULL,
21
+ `kind` text NOT NULL,
22
+ `entry_id` text NOT NULL,
23
+ `payload` text NOT NULL,
24
+ `sent_at` text,
25
+ `created_at` text NOT NULL,
26
+ `updated_at` text NOT NULL,
27
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
28
+ CONSTRAINT "outbox_kind" CHECK("outbox"."kind" IN ('entry.published', 'entry.unpublished')),
29
+ CONSTRAINT "outbox_json" CHECK(json_valid("outbox"."payload") AND json_type("outbox"."payload") = 'object')
30
+ );
31
+ --> statement-breakpoint
32
+ CREATE INDEX `outbox_unsent` ON `outbox` (`sent_at`,`created_at`);--> statement-breakpoint
33
+ CREATE UNIQUE INDEX `outbox_id_site` ON `outbox` (`id`,`site_id`);--> statement-breakpoint
34
+ CREATE TABLE `schedules` (
35
+ `id` text PRIMARY KEY NOT NULL,
36
+ `site_id` text NOT NULL,
37
+ `entry_id` text NOT NULL,
38
+ `scheduled_at` text NOT NULL,
39
+ `version` integer NOT NULL,
40
+ `acknowledged` text NOT NULL,
41
+ `actor_kind` text NOT NULL,
42
+ `actor_user_id` text NOT NULL,
43
+ `actor_token_id` text,
44
+ `actor_meta` text,
45
+ `created_at` text NOT NULL,
46
+ `updated_at` text NOT NULL,
47
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
48
+ FOREIGN KEY (`entry_id`,`site_id`) REFERENCES `entries`(`id`,`site_id`) ON UPDATE no action ON DELETE no action,
49
+ FOREIGN KEY (`actor_user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
50
+ FOREIGN KEY (`actor_token_id`,`site_id`) REFERENCES `tokens`(`id`,`site_id`) ON UPDATE no action ON DELETE no action,
51
+ CONSTRAINT "schedules_actor_kind" CHECK("schedules"."actor_kind" IN ('token', 'user', 'oauth_client')),
52
+ CONSTRAINT "schedules_json" CHECK(json_valid("schedules"."acknowledged") AND json_type("schedules"."acknowledged") = 'array' AND ("schedules"."actor_meta" IS NULL OR json_valid("schedules"."actor_meta")))
53
+ );
54
+ --> statement-breakpoint
55
+ CREATE INDEX `schedules_due` ON `schedules` (`scheduled_at`);--> statement-breakpoint
56
+ CREATE UNIQUE INDEX `schedules_id_site` ON `schedules` (`id`,`site_id`);--> statement-breakpoint
57
+ CREATE UNIQUE INDEX `schedules_entry` ON `schedules` (`site_id`,`entry_id`);
@@ -0,0 +1,90 @@
1
+ CREATE TABLE `auth_challenges` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `site_id` text NOT NULL,
4
+ `challenge` text NOT NULL,
5
+ `purpose` text NOT NULL,
6
+ `invitation_id` text,
7
+ `user_id` text,
8
+ `expires_at` text NOT NULL,
9
+ `created_at` text NOT NULL,
10
+ `updated_at` text NOT NULL,
11
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
12
+ CONSTRAINT "auth_challenges_purpose" CHECK("auth_challenges"."purpose" IN ('register', 'authenticate'))
13
+ );
14
+ --> statement-breakpoint
15
+ CREATE UNIQUE INDEX `auth_challenges_id_site` ON `auth_challenges` (`id`,`site_id`);--> statement-breakpoint
16
+ CREATE TABLE `invitations` (
17
+ `id` text PRIMARY KEY NOT NULL,
18
+ `site_id` text NOT NULL,
19
+ `hash` text NOT NULL,
20
+ `role` text NOT NULL,
21
+ `user_id` text,
22
+ `expires_at` text NOT NULL,
23
+ `used_at` text,
24
+ `created_at` text NOT NULL,
25
+ `updated_at` text NOT NULL,
26
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
27
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
28
+ CONSTRAINT "invitations_role" CHECK("invitations"."role" IN ('owner', 'editor', 'author'))
29
+ );
30
+ --> statement-breakpoint
31
+ CREATE UNIQUE INDEX `invitations_id_site` ON `invitations` (`id`,`site_id`);--> statement-breakpoint
32
+ CREATE UNIQUE INDEX `invitations_hash` ON `invitations` (`hash`);--> statement-breakpoint
33
+ CREATE TABLE `members` (
34
+ `id` text PRIMARY KEY NOT NULL,
35
+ `site_id` text NOT NULL,
36
+ `user_id` text NOT NULL,
37
+ `role` text NOT NULL,
38
+ `created_at` text NOT NULL,
39
+ `updated_at` text NOT NULL,
40
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
41
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
42
+ CONSTRAINT "members_role" CHECK("members"."role" IN ('owner', 'editor', 'author'))
43
+ );
44
+ --> statement-breakpoint
45
+ CREATE UNIQUE INDEX `members_id_site` ON `members` (`id`,`site_id`);--> statement-breakpoint
46
+ CREATE UNIQUE INDEX `members_person` ON `members` (`site_id`,`user_id`);--> statement-breakpoint
47
+ CREATE TABLE `passkeys` (
48
+ `id` text PRIMARY KEY NOT NULL,
49
+ `site_id` text NOT NULL,
50
+ `user_id` text NOT NULL,
51
+ `credential_id` text NOT NULL,
52
+ `public_key` text NOT NULL,
53
+ `counter` integer NOT NULL,
54
+ `transports` text NOT NULL,
55
+ `label` text NOT NULL,
56
+ `last_used_at` text,
57
+ `created_at` text NOT NULL,
58
+ `updated_at` text NOT NULL,
59
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
60
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
61
+ CONSTRAINT "passkeys_counter" CHECK("passkeys"."counter" >= 0),
62
+ CONSTRAINT "passkeys_json" CHECK(json_valid("passkeys"."transports") AND json_type("passkeys"."transports") = 'array')
63
+ );
64
+ --> statement-breakpoint
65
+ CREATE INDEX `passkeys_user` ON `passkeys` (`user_id`);--> statement-breakpoint
66
+ CREATE UNIQUE INDEX `passkeys_id_site` ON `passkeys` (`id`,`site_id`);--> statement-breakpoint
67
+ CREATE UNIQUE INDEX `passkeys_credential` ON `passkeys` (`credential_id`);--> statement-breakpoint
68
+ CREATE TABLE `sessions` (
69
+ `id` text PRIMARY KEY NOT NULL,
70
+ `site_id` text NOT NULL,
71
+ `user_id` text NOT NULL,
72
+ `hash` text NOT NULL,
73
+ `expires_at` text NOT NULL,
74
+ `created_at` text NOT NULL,
75
+ `updated_at` text NOT NULL,
76
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
77
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
78
+ );
79
+ --> statement-breakpoint
80
+ CREATE UNIQUE INDEX `sessions_id_site` ON `sessions` (`id`,`site_id`);--> statement-breakpoint
81
+ CREATE UNIQUE INDEX `sessions_hash` ON `sessions` (`hash`);--> statement-breakpoint
82
+ -- Edited by hand (ADR-023): every person who has a token in a site becomes a member of it, with the
83
+ -- role they had, so a deployment of v0.2 keeps who may do what. A reviewer of then is an author
84
+ -- now. The id is the prefix and 26 hex digits, which are characters of a ULID.
85
+ INSERT INTO `members` (`id`, `site_id`, `user_id`, `role`, `created_at`, `updated_at`)
86
+ SELECT 'mbr_' || upper(hex(randomblob(13))), `pairs`.`site_id`, `users`.`id`,
87
+ CASE `users`.`role` WHEN 'reviewer' THEN 'author' ELSE `users`.`role` END,
88
+ `users`.`created_at`, `users`.`updated_at`
89
+ FROM (SELECT DISTINCT `site_id`, `user_id` FROM `tokens`) AS `pairs`
90
+ JOIN `users` ON `users`.`id` = `pairs`.`user_id`;
@@ -0,0 +1,27 @@
1
+ CREATE TABLE `reviews` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `site_id` text NOT NULL,
4
+ `entry_id` text NOT NULL,
5
+ `revision_id` text NOT NULL,
6
+ `status` text NOT NULL,
7
+ `acknowledged` text NOT NULL,
8
+ `requested_by` text NOT NULL,
9
+ `requested_meta` text,
10
+ `decided_by` text,
11
+ `decided_at` text,
12
+ `note` text,
13
+ `created_at` text NOT NULL,
14
+ `updated_at` text NOT NULL,
15
+ FOREIGN KEY (`site_id`) REFERENCES `sites`(`id`) ON UPDATE no action ON DELETE no action,
16
+ FOREIGN KEY (`entry_id`,`site_id`) REFERENCES `entries`(`id`,`site_id`) ON UPDATE no action ON DELETE no action,
17
+ FOREIGN KEY (`revision_id`,`site_id`) REFERENCES `revisions`(`id`,`site_id`) ON UPDATE no action ON DELETE no action,
18
+ FOREIGN KEY (`requested_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
19
+ FOREIGN KEY (`decided_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
20
+ CONSTRAINT "reviews_status" CHECK("reviews"."status" IN ('pending', 'approved', 'changes_requested', 'cancelled')),
21
+ CONSTRAINT "reviews_decided" CHECK(("reviews"."status" IN ('pending', 'cancelled')) OR ("reviews"."decided_by" IS NOT NULL AND "reviews"."decided_at" IS NOT NULL)),
22
+ CONSTRAINT "reviews_json" CHECK(json_valid("reviews"."acknowledged") AND json_type("reviews"."acknowledged") = 'array' AND ("reviews"."requested_meta" IS NULL OR json_valid("reviews"."requested_meta")))
23
+ );
24
+ --> statement-breakpoint
25
+ CREATE UNIQUE INDEX `reviews_pending` ON `reviews` (`site_id`,`entry_id`) WHERE "reviews"."status" = 'pending';--> statement-breakpoint
26
+ CREATE INDEX `reviews_queue` ON `reviews` (`site_id`,`status`,`created_at`);--> statement-breakpoint
27
+ CREATE UNIQUE INDEX `reviews_id_site` ON `reviews` (`id`,`site_id`);