@hollware/server 0.2.0 → 0.4.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,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`);
@@ -0,0 +1,54 @@
1
+ -- Edited by hand (ADR-023): a person is one across the sites of a deployment (v0.4), so passkeys,
2
+ -- sessions and sign-in challenges lose site_id. Each table is rebuilt, which D1 allows here since
3
+ -- no other table points at them; the PRAGMA foreign_keys lines drizzle-kit writes are gone, as D1
4
+ -- ignores them, and the CHECKs name their columns without the temporary table's name.
5
+ CREATE TABLE `__new_auth_challenges` (
6
+ `id` text PRIMARY KEY NOT NULL,
7
+ `challenge` text NOT NULL,
8
+ `purpose` text NOT NULL,
9
+ `invitation_id` text,
10
+ `user_id` text,
11
+ `expires_at` text NOT NULL,
12
+ `created_at` text NOT NULL,
13
+ `updated_at` text NOT NULL,
14
+ CONSTRAINT "auth_challenges_purpose" CHECK("purpose" IN ('register', 'authenticate'))
15
+ );
16
+ --> statement-breakpoint
17
+ INSERT INTO `__new_auth_challenges`("id", "challenge", "purpose", "invitation_id", "user_id", "expires_at", "created_at", "updated_at") SELECT "id", "challenge", "purpose", "invitation_id", "user_id", "expires_at", "created_at", "updated_at" FROM `auth_challenges`;--> statement-breakpoint
18
+ DROP TABLE `auth_challenges`;--> statement-breakpoint
19
+ ALTER TABLE `__new_auth_challenges` RENAME TO `auth_challenges`;--> statement-breakpoint
20
+ CREATE TABLE `__new_passkeys` (
21
+ `id` text PRIMARY KEY NOT NULL,
22
+ `user_id` text NOT NULL,
23
+ `credential_id` text NOT NULL,
24
+ `public_key` text NOT NULL,
25
+ `counter` integer NOT NULL,
26
+ `transports` text NOT NULL,
27
+ `label` text NOT NULL,
28
+ `last_used_at` text,
29
+ `created_at` text NOT NULL,
30
+ `updated_at` text NOT NULL,
31
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
32
+ CONSTRAINT "passkeys_counter" CHECK("counter" >= 0),
33
+ CONSTRAINT "passkeys_json" CHECK(json_valid("transports") AND json_type("transports") = 'array')
34
+ );
35
+ --> statement-breakpoint
36
+ INSERT INTO `__new_passkeys`("id", "user_id", "credential_id", "public_key", "counter", "transports", "label", "last_used_at", "created_at", "updated_at") SELECT "id", "user_id", "credential_id", "public_key", "counter", "transports", "label", "last_used_at", "created_at", "updated_at" FROM `passkeys`;--> statement-breakpoint
37
+ DROP TABLE `passkeys`;--> statement-breakpoint
38
+ ALTER TABLE `__new_passkeys` RENAME TO `passkeys`;--> statement-breakpoint
39
+ CREATE INDEX `passkeys_user` ON `passkeys` (`user_id`);--> statement-breakpoint
40
+ CREATE UNIQUE INDEX `passkeys_credential` ON `passkeys` (`credential_id`);--> statement-breakpoint
41
+ CREATE TABLE `__new_sessions` (
42
+ `id` text PRIMARY KEY NOT NULL,
43
+ `user_id` text NOT NULL,
44
+ `hash` text NOT NULL,
45
+ `expires_at` text NOT NULL,
46
+ `created_at` text NOT NULL,
47
+ `updated_at` text NOT NULL,
48
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
49
+ );
50
+ --> statement-breakpoint
51
+ INSERT INTO `__new_sessions`("id", "user_id", "hash", "expires_at", "created_at", "updated_at") SELECT "id", "user_id", "hash", "expires_at", "created_at", "updated_at" FROM `sessions`;--> statement-breakpoint
52
+ DROP TABLE `sessions`;--> statement-breakpoint
53
+ ALTER TABLE `__new_sessions` RENAME TO `sessions`;--> statement-breakpoint
54
+ CREATE UNIQUE INDEX `sessions_hash` ON `sessions` (`hash`);
@@ -0,0 +1,4 @@
1
+ -- Edited by hand (ADR-023). Read tokens (v0.4): a token is personal (hw_pat_) or a read token (hw_read_), which reads the
2
+ -- published content of its site over the read API and nothing else. Every token so far is
3
+ -- personal. The CHECK is the column's own, so the table is not rebuilt.
4
+ ALTER TABLE `tokens` ADD `kind` text DEFAULT 'personal' NOT NULL CHECK (`kind` IN ('personal', 'read'));