kopje 0.0.0 → 0.1.0-rc.1

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +13 -0
  3. package/README.md +35 -4
  4. package/cli/kopje-admin.js +13 -0
  5. package/cli/legacy-migrations/0000_initial.sql +184 -0
  6. package/cli/legacy-migrations/0001_add-unique-following.sql +3 -0
  7. package/cli/legacy-migrations/0002_add-target-outbox_objects.sql +4 -0
  8. package/cli/legacy-migrations/0003_add_peers.sql +5 -0
  9. package/cli/legacy-migrations/0004_add_outbox_objects_indices.sql +4 -0
  10. package/cli/legacy-migrations/0005_add_idempotency_keys.sql +9 -0
  11. package/cli/legacy-migrations/0006_add_note_hashtags.sql +9 -0
  12. package/cli/legacy-migrations/0007_change_subscriptions_id.sql +29 -0
  13. package/cli/legacy-migrations/0008_add_server-settings.sql +11 -0
  14. package/cli/legacy-migrations/0009_add_admin.sql +10 -0
  15. package/cli/legacy-migrations/0010_add_ui_client.sql +4 -0
  16. package/cli/legacy-migrations/0011_add_actor_preference.sql +13 -0
  17. package/cli/legacy-migrations/0012_add_mastodon_id.sql +1 -0
  18. package/cli/legacy-migrations/0013_add_id_sequences.sql +4 -0
  19. package/cli/legacy-migrations/0014_add_client_credentials.sql +9 -0
  20. package/cli/legacy-migrations/0015_add_actor_activities.sql +9 -0
  21. package/cli/legacy-migrations/0016_change_outbox_objects.sql +22 -0
  22. package/cli/legacy-migrations/0017_change_actor_reblogs.sql +42 -0
  23. package/cli/legacy-migrations/0018_swap_actor_reblogs.sql +2 -0
  24. package/cli/legacy-migrations/0019_add_users.sql +26 -0
  25. package/cli/legacy-migrations/0020_change_actors.sql +53 -0
  26. package/cli/legacy-migrations/0021_update_objects.sql +179 -0
  27. package/cli/legacy-migrations/0022_index_objects.sql +5 -0
  28. package/cli/legacy-migrations/0023_add_object_revisions.sql +11 -0
  29. package/cli/legacy-migrations/0024_add_actor_columns.sql +23 -0
  30. package/cli/legacy-migrations/0025_add_object_columns.sql +22 -0
  31. package/cli/legacy-migrations/0026_extend_following_users_notifications.sql +21 -0
  32. package/cli/legacy-migrations/0027_add_retention_columns.sql +14 -0
  33. package/cli/legacy-migrations/0028_backfill_retention_columns.sql +24 -0
  34. package/cli/legacy-migrations/0029_backfill_interaction_count.sql +32 -0
  35. package/cli/legacy-migrations/0030_create_account_relationship_tables.sql +66 -0
  36. package/cli/legacy-migrations/0031_create_interaction_media_tables.sql +46 -0
  37. package/cli/legacy-migrations/0032_create_tag_mention_list_tables.sql +79 -0
  38. package/cli/legacy-migrations/0033_create_remaining_tables.sql +162 -0
  39. package/cli/legacy-migrations/0034_add_unique_actor_favourites.sql +8 -0
  40. package/cli/legacy-migrations/0035_add_missing_indexes.sql +7 -0
  41. package/cli/legacy-migrations/0036_backfill_in_reply_to_id.sql +67 -0
  42. package/cli/legacy-migrations/0037_backfill_reblogs_count_and_add_in_reply_to_id_index.sql +4 -0
  43. package/cli/legacy-migrations/0038_add_actor_replies_unique_index.sql +37 -0
  44. package/cli/legacy-migrations/0039_add_relationship_visibility_indexes.sql +2 -0
  45. package/cli/lib/client.js +156 -0
  46. package/cli/lib/commands.js +524 -0
  47. package/cli/lib/cutover/convert.js +1465 -0
  48. package/cli/lib/cutover/dump-parse.js +219 -0
  49. package/cli/lib/cutover/fingerprint.js +284 -0
  50. package/cli/lib/cutover/kek.js +79 -0
  51. package/cli/lib/cutover/kopje-db.js +338 -0
  52. package/cli/lib/cutover/kopje-runtime.js +21 -0
  53. package/cli/lib/cutover/legacy-load.js +522 -0
  54. package/cli/lib/cutover/maintenance.js +284 -0
  55. package/cli/lib/cutover/preflight.js +252 -0
  56. package/cli/lib/cutover/run.js +333 -0
  57. package/cli/lib/cutover/sql-script.js +524 -0
  58. package/cli/lib/cutover/verify-actual.js +333 -0
  59. package/cli/lib/cutover/verify-expect.js +538 -0
  60. package/cli/lib/cutover/worker-file.js +39 -0
  61. package/cli/lib/format.js +167 -0
  62. package/cli/lib/main.js +821 -0
  63. package/cli/lib/node-io.js +98 -0
  64. package/cli/lib/write-all.js +16 -0
  65. package/dist/THIRD_PARTY_NOTICES.md +2605 -0
  66. package/dist/aeea693fcbc4419422cc1481c0f58bb51966b3fb-0000_initial.sql +562 -0
  67. package/dist/maintenance-render.js +749 -0
  68. package/dist/maintenance-worker.js +1 -0
  69. package/dist/worker.js +927 -0
  70. package/dist/worker.js.map +8 -0
  71. package/docs/backup.md +313 -0
  72. package/docs/cutover-runbook.md +579 -0
  73. package/docs/cutover.md +216 -0
  74. package/docs/dump-format.md +278 -0
  75. package/docs/setup.md +138 -0
  76. package/docs/upgrade.md +114 -0
  77. package/migrations/0000_initial.sql +562 -0
  78. package/package.json +88 -6
  79. package/public/_headers +3 -0
  80. package/public/assets/avatar.png +0 -0
  81. package/public/assets/header.png +0 -0
  82. package/public/assets/kopje.css +328 -0
  83. package/types/index.d.ts +17 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `kopje` package. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
4
+ and versions follow [semver](https://semver.org). Before 1.0, a minor version may make breaking changes.
5
+
6
+ Each version says whether it changes the Store's schema (adds migrations) and whether an instance must change its
7
+ `wrangler.jsonc` (a binding, a compatibility date or flag). See [docs/upgrade.md](docs/upgrade.md).
8
+
9
+ ## [Unreleased]
10
+
11
+ ## [0.1.0-rc.1] - 2026-10-13
12
+
13
+ A release candidate of the first release, published under the npm dist-tag `next`.
14
+
15
+ ### Added
16
+
17
+ - The first release: the Mastodon API, ActivityPub federation, media, search, the `/setup` wizard, the daily
18
+ encrypted backup and the `kopje-admin` CLI.
19
+ - The instance template (`deploy/` in the repository), with the Deploy to Cloudflare button.
20
+ - The cutover from a legacy Wildebeest instance: `convert`, `verify-conversion`, `cutover-preflight`, `fingerprint`,
21
+ `maintenance-worker`, `maintenance-worker-check` and `cutover` in `kopje-admin`, and
22
+ [docs/cutover-runbook.md](docs/cutover-runbook.md).
23
+
24
+ ### Instance changes
25
+
26
+ - Store schema: `0000_initial`.
27
+ - `wrangler.jsonc`: as in the template, compatibility date `2026-10-11`. Tested with wrangler 4.149.0. The Queue
28
+ consumer has a dead-letter queue (`dead_letter_queue`), which must exist before the deploy.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2023 Cloudflare, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md CHANGED
@@ -1,7 +1,38 @@
1
- # kopje
1
+ # Kopje
2
2
 
3
- Kopje lets an individual or a small group (up to about 10 people) keep a Fediverse identity (`acct:user@your.domain`) on their own Cloudflare account and their own domain, using existing Mastodon clients.
3
+ A Mastodon-compatible ActivityPub server for one person or a small group (up to about ten local accounts), running as
4
+ one Cloudflare Worker and one SQLite-backed Durable Object on your own Cloudflare account. It is a spiritual successor
5
+ of cloudflare/wildebeest and is not affiliated with Cloudflare.
4
6
 
5
- It is a spiritual successor of [cloudflare/wildebeest](https://github.com/cloudflare/wildebeest) and is **not affiliated with or endorsed by Cloudflare**.
7
+ ## Running an instance
6
8
 
7
- This version (0.0.0) contains no code. Kopje is under development at https://github.com/shuymn/wildebeest.
9
+ Do not install this package by hand: start from the instance template, which has the Deploy to Cloudflare button, the
10
+ `wrangler.jsonc` every instance uses, and the update setup. See
11
+ [deploy/README.md](https://github.com/shuymn/wildebeest/tree/main/deploy).
12
+
13
+ - [docs/setup.md](docs/setup.md): the `/setup` wizard
14
+ - [docs/upgrade.md](docs/upgrade.md): updates and rollback
15
+ - [docs/backup.md](docs/backup.md): the daily encrypted backup
16
+ - [docs/cutover-runbook.md](docs/cutover-runbook.md): moving a legacy Wildebeest instance to Kopje
17
+ ([docs/cutover.md](docs/cutover.md): the conversion)
18
+ - [CHANGELOG.md](CHANGELOG.md): release notes
19
+
20
+ ## What the package contains
21
+
22
+ | Path or export | What |
23
+ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
24
+ | `kopje` (`dist/worker.js`) | The Worker, bundled and minified: the default export has `fetch`, `queue` and `scheduled`, and `Store` is the Durable Object class. It has no runtime dependencies |
25
+ | `dist/*.sql` | The Store's schema migrations, imported by the bundle as text modules (the `**/*.sql` Text rule in `wrangler.jsonc`) |
26
+ | `kopje/public/*` | The static assets the Worker serves through the `ASSETS` binding |
27
+ | `kopje/migrations/*` | The same migrations as SQL files, for reference |
28
+ | `kopje-admin` | The operations CLI (Node.js 22 or later). See [docs/setup.md](docs/setup.md#running-the-admin-cli) |
29
+ | `dist/maintenance-*.js` | The cutover's maintenance worker and the code `kopje-admin` renders its snapshot and converts with ([docs/cutover-runbook.md](docs/cutover-runbook.md)) |
30
+ | `dist/THIRD_PARTY_NOTICES.md` | The licenses of the packages bundled into `dist/worker.js` (the maintenance bundles hold a subset of them) |
31
+
32
+ The bundle is built with wrangler from the source in the
33
+ [repository](https://github.com/shuymn/wildebeest/tree/main/packages/kopje); an instance's `wrangler deploy` bundles it
34
+ once more with its own entry module.
35
+
36
+ ## License
37
+
38
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /* global process */
3
+ // kopje-admin: operations CLI for a Kopje instance (calls /admin/* through Cloudflare Access).
4
+ import { run } from './lib/main.js'
5
+ import { nodeIO } from './lib/node-io.js'
6
+
7
+ process.exitCode = await run({
8
+ argv: process.argv.slice(2),
9
+ env: process.env,
10
+ io: nodeIO,
11
+ stdout: process.stdout,
12
+ stderr: process.stderr,
13
+ })
@@ -0,0 +1,184 @@
1
+ -- Migration number: 0000 2022-12-05T20:27:34.391Z
2
+
3
+ CREATE TABLE "actors" (
4
+ "id" TEXT PRIMARY KEY,
5
+ "type" TEXT NOT NULL,
6
+ "email" TEXT,
7
+ "privkey" BLOB,
8
+ "privkey_salt" BLOB,
9
+ "pubkey" TEXT,
10
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
11
+ "properties" TEXT NOT NULL DEFAULT (json_object())
12
+ );
13
+
14
+ CREATE INDEX "actors_email" ON "actors" ("email");
15
+
16
+ CREATE TABLE "actor_following" (
17
+ "id" TEXT PRIMARY KEY,
18
+ "actor_id" TEXT NOT NULL,
19
+ "target_actor_id" TEXT NOT NULL,
20
+ "target_actor_acct" TEXT NOT NULL,
21
+ "state" TEXT NOT NULL DEFAULT 'pending',
22
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
23
+
24
+ CONSTRAINT "actor_following_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
25
+ CONSTRAINT "actor_following_target_actor_id_fkey" FOREIGN KEY ("target_actor_id") REFERENCES "actors" ("id")
26
+ );
27
+
28
+ CREATE INDEX "actor_following_actor_id" ON "actor_following" ("actor_id");
29
+ CREATE INDEX "actor_following_target_actor_id" ON "actor_following" ("target_actor_id");
30
+
31
+ CREATE TABLE "objects" (
32
+ "id" TEXT PRIMARY KEY,
33
+ "mastodon_id" TEXT UNIQUE NOT NULL,
34
+ "type" TEXT NOT NULL,
35
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
36
+ "original_actor_id" TEXT,
37
+ "original_object_id" TEXT UNIQUE,
38
+ "reply_to_object_id" TEXT,
39
+ "properties" TEXT NOT NULL DEFAULT (json_object()),
40
+ "local" INTEGER NOT NULL
41
+ );
42
+
43
+ CREATE TABLE "inbox_objects" (
44
+ "id" TEXT PRIMARY KEY,
45
+ "actor_id" TEXT NOT NULL,
46
+ "object_id" TEXT NOT NULL,
47
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
48
+
49
+ CONSTRAINT "inbox_objects_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
50
+ CONSTRAINT "inbox_objects_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id")
51
+ );
52
+
53
+ CREATE TABLE "outbox_objects" (
54
+ "id" TEXT PRIMARY KEY,
55
+ "actor_id" TEXT NOT NULL,
56
+ "object_id" TEXT NOT NULL,
57
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
58
+ "published_date" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
59
+
60
+ CONSTRAINT "outbox_objects_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
61
+ CONSTRAINT "outbox_objects_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id")
62
+ );
63
+
64
+ CREATE TABLE "actor_notifications" (
65
+ "id" INTEGER PRIMARY KEY AUTOINCREMENT,
66
+ "type" TEXT NOT NULL,
67
+ "actor_id" TEXT NOT NULL,
68
+ "from_actor_id" TEXT NOT NULL,
69
+ "object_id" TEXT,
70
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
71
+
72
+ CONSTRAINT "actor_notifications_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
73
+ CONSTRAINT "actor_notifications_from_actor_id_fkey" FOREIGN KEY ("from_actor_id") REFERENCES "actors" ("id"),
74
+ CONSTRAINT "actor_notifications_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id")
75
+ );
76
+
77
+ CREATE INDEX "actor_notifications_actor_id" ON "actor_notifications" ("actor_id");
78
+
79
+ CREATE TABLE "actor_favourites" (
80
+ "id" TEXT PRIMARY KEY,
81
+ "actor_id" TEXT NOT NULL,
82
+ "object_id" TEXT NOT NULL,
83
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
84
+
85
+ CONSTRAINT "actor_favourites_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
86
+ CONSTRAINT "actor_favourites_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id")
87
+ );
88
+
89
+ CREATE INDEX "actor_favourites_actor_id" ON "actor_favourites" ("actor_id");
90
+ CREATE INDEX "actor_favourites_object_id" ON "actor_favourites" ("object_id");
91
+
92
+ CREATE TABLE "actor_reblogs" (
93
+ "id" TEXT PRIMARY KEY,
94
+ "actor_id" TEXT NOT NULL,
95
+ "object_id" TEXT NOT NULL,
96
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
97
+
98
+ CONSTRAINT "actor_reblogs_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
99
+ CONSTRAINT "actor_reblogs_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id")
100
+ );
101
+
102
+ CREATE INDEX "actor_reblogs_actor_id" ON "actor_reblogs" ("actor_id");
103
+ CREATE INDEX "actor_reblogs_object_id" ON "actor_reblogs" ("object_id");
104
+
105
+ CREATE TABLE "clients" (
106
+ "id" TEXT PRIMARY KEY,
107
+ "secret" TEXT NOT NULL,
108
+ "name" TEXT NOT NULL,
109
+ "redirect_uris" TEXT NOT NULL,
110
+ "website" TEXT,
111
+ "scopes" TEXT,
112
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW'))
113
+ );
114
+
115
+ CREATE TABLE "subscriptions" (
116
+ "id" TEXT PRIMARY KEY,
117
+ "actor_id" TEXT NOT NULL,
118
+ "client_id" TEXT NOT NULL,
119
+ "endpoint" TEXT NULL,
120
+ "key_p256dh" TEXT NOT NULL,
121
+ "key_auth" TEXT NOT NULL,
122
+ "alert_mention" INTEGER NOT NULL,
123
+ "alert_status" INTEGER NOT NULL,
124
+ "alert_reblog" INTEGER NOT NULL,
125
+ "alert_follow" INTEGER NOT NULL,
126
+ "alert_follow_request" INTEGER NOT NULL,
127
+ "alert_favourite" INTEGER NOT NULL,
128
+ "alert_poll" INTEGER NOT NULL,
129
+ "alert_update" INTEGER NOT NULL,
130
+ "alert_admin_sign_up" INTEGER NOT NULL,
131
+ "alert_admin_report" INTEGER NOT NULL,
132
+ "policy" TEXT,
133
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
134
+
135
+ CONSTRAINT "subscriptions_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
136
+ CONSTRAINT "subscriptions_client_id_fkey" FOREIGN KEY ("client_id") REFERENCES "clients" ("id")
137
+ );
138
+
139
+ CREATE UNIQUE INDEX "unique_subscriptions" ON "subscriptions" ("actor_id", "client_id");
140
+
141
+ CREATE VIRTUAL TABLE "search_fts" USING "fts5" (
142
+ "type",
143
+ "name",
144
+ "preferredUsername",
145
+ "status"
146
+ );
147
+
148
+ CREATE TRIGGER "actors_search_fts_insert" AFTER INSERT ON "actors"
149
+ BEGIN
150
+ INSERT INTO "search_fts" ("rowid", "type", "name", "preferredUsername")
151
+ VALUES ("new"."rowid",
152
+ "new"."type",
153
+ json_extract("new"."properties", '$.name'),
154
+ json_extract("new"."properties", '$.preferredUsername'));
155
+ END;
156
+
157
+ CREATE TRIGGER "actors_search_fts_delete" AFTER DELETE ON "actors"
158
+ BEGIN
159
+ DELETE FROM "search_fts" WHERE "rowid"="old"."rowid";
160
+ END;
161
+
162
+ CREATE TRIGGER "actors_search_fts_update" AFTER UPDATE ON "actors"
163
+ BEGIN
164
+ DELETE FROM "search_fts" WHERE "rowid"="old"."rowid";
165
+ INSERT INTO "search_fts" ("rowid", "type", "name", "preferredUsername")
166
+ VALUES ("new"."rowid",
167
+ "new"."type",
168
+ json_extract("new"."properties", '$.name'),
169
+ json_extract("new"."properties", '$.preferredUsername'));
170
+ END;
171
+
172
+ CREATE TABLE "actor_replies" (
173
+ "id" TEXT PRIMARY KEY,
174
+ "actor_id" TEXT NOT NULL,
175
+ "object_id" TEXT NOT NULL,
176
+ "in_reply_to_object_id" TEXT NOT NULL,
177
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
178
+
179
+ CONSTRAINT "actor_replies_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id"),
180
+ CONSTRAINT "actor_replies_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id"),
181
+ CONSTRAINT "actor_replies_in_reply_to_object_id_fkey" FOREIGN KEY ("in_reply_to_object_id") REFERENCES "objects" ("id")
182
+ );
183
+
184
+ CREATE INDEX "actor_replies_in_reply_to_object_id" ON "actor_replies" ("in_reply_to_object_id");
@@ -0,0 +1,3 @@
1
+ -- Migration number: 0001 2023-01-16T13:09:04.033Z
2
+
3
+ CREATE UNIQUE INDEX "unique_actor_following" ON "actor_following" ("actor_id", "target_actor_id");
@@ -0,0 +1,4 @@
1
+ -- Migration number: 0002 2023-01-16T13:46:54.975Z
2
+
3
+ ALTER TABLE "outbox_objects"
4
+ ADD "target" TEXT NOT NULL DEFAULT 'https://www.w3.org/ns/activitystreams#Public';
@@ -0,0 +1,5 @@
1
+ -- Migration number: 0003 2023-02-02T15:03:27.478Z
2
+
3
+ CREATE TABLE "peers" (
4
+ "domain" TEXT UNIQUE NOT NULL
5
+ );
@@ -0,0 +1,4 @@
1
+ -- Migration number: 0004 2023-02-03T17:17:19.099Z
2
+
3
+ CREATE INDEX "outbox_objects_actor_id" ON "outbox_objects" ("actor_id");
4
+ CREATE INDEX "outbox_objects_target" ON "outbox_objects" ("target");
@@ -0,0 +1,9 @@
1
+ -- Migration number: 0005 2023-02-07T10:57:21.848Z
2
+
3
+ CREATE TABLE "idempotency_keys" (
4
+ "key" TEXT PRIMARY KEY,
5
+ "object_id" TEXT NOT NULL,
6
+ "expires_at" DATETIME NOT NULL,
7
+
8
+ CONSTRAINT "idempotency_keys_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id")
9
+ );
@@ -0,0 +1,9 @@
1
+ -- Migration number: 0006 2023-02-13T11:18:03.485Z
2
+
3
+ CREATE TABLE "note_hashtags" (
4
+ "value" TEXT NOT NULL,
5
+ "object_id" TEXT NOT NULL,
6
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
7
+
8
+ CONSTRAINT "note_hashtags_object_id_fkey" FOREIGN KEY("object_id") REFERENCES "objects" ("id")
9
+ );
@@ -0,0 +1,29 @@
1
+ -- Migration number: 0007 2023-02-15T11:01:46.585Z
2
+
3
+ DROP table "subscriptions";
4
+
5
+ CREATE TABLE "subscriptions" (
6
+ "id" INTEGER PRIMARY KEY AUTOINCREMENT,
7
+ "actor_id" TEXT NOT NULL,
8
+ "client_id" TEXT NOT NULL,
9
+ "endpoint" TEXT NULL NOT NULL,
10
+ "key_p256dh" TEXT NOT NULL,
11
+ "key_auth" TEXT NOT NULL,
12
+ "alert_mention" INTEGER NOT NULL,
13
+ "alert_status" INTEGER NOT NULL,
14
+ "alert_reblog" INTEGER NOT NULL,
15
+ "alert_follow" INTEGER NOT NULL,
16
+ "alert_follow_request" INTEGER NOT NULL,
17
+ "alert_favourite" INTEGER NOT NULL,
18
+ "alert_poll" INTEGER NOT NULL,
19
+ "alert_update" INTEGER NOT NULL,
20
+ "alert_admin_sign_up" INTEGER NOT NULL,
21
+ "alert_admin_report" INTEGER NOT NULL,
22
+ "policy" TEXT NOT NULL,
23
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
24
+
25
+ CONSTRAINT "subscriptions_actor_id_fkey" FOREIGN KEY("actor_id") REFERENCES "actors" ("id"),
26
+ CONSTRAINT "subscriptions_client_id_fkey" FOREIGN KEY("client_id") REFERENCES "clients" ("id")
27
+ );
28
+
29
+ CREATE UNIQUE INDEX "unique_subscriptions" ON "subscriptions" ("actor_id", "client_id");
@@ -0,0 +1,11 @@
1
+ -- Migration number: 0003 2023-02-24T15:03:27.478Z
2
+
3
+ CREATE TABLE "server_settings" (
4
+ "setting_name" TEXT UNIQUE NOT NULL,
5
+ "setting_value" TEXT NOT NULL
6
+ );
7
+
8
+ CREATE TABLE "server_rules" (
9
+ "id" INTEGER PRIMARY KEY AUTOINCREMENT,
10
+ "text" TEXT NOT NULL
11
+ );
@@ -0,0 +1,10 @@
1
+ -- Migration number: 0009 2023-02-28T13:58:08.319Z
2
+
3
+ ALTER TABLE "actors"
4
+ ADD "is_admin" INTEGER;
5
+
6
+ UPDATE "actors" SET "is_admin" = 1
7
+ WHERE "id" =
8
+ (SELECT "id"
9
+ FROM "actors"
10
+ ORDER BY "cdate" ASC LIMIT 1);
@@ -0,0 +1,4 @@
1
+ -- Migration number: 0010 2023-03-08T09:40:30.734Z
2
+
3
+ INSERT INTO "clients" ("id", "secret", "name", "redirect_uris", "scopes")
4
+ VALUES ('924801be-d211-495d-8cac-e73503413af8', hex(randomblob(42)), 'Wildebeest User Interface', '/', 'all');
@@ -0,0 +1,13 @@
1
+ CREATE TABLE "actor_preferences" (
2
+ "id" TEXT PRIMARY KEY,
3
+ "posting_default_visibility" TEXT NOT NULL DEFAULT 'public',
4
+ "posting_default_sensitive" INTEGER NOT NULL DEFAULT 0,
5
+ "posting_default_language" TEXT,
6
+ "reading_expand_media" TEXT NOT NULL DEFAULT 'default',
7
+ "reading_expand_spoilers" INTEGER NOT NULL DEFAULT 0,
8
+
9
+ CONSTRAINT "actor_preferences_id_fkey" FOREIGN KEY ("id") REFERENCES "actors"("id") ON DELETE CASCADE
10
+ );
11
+
12
+ INSERT INTO "actor_preferences" SELECT id, 'public', 0, null, 'default', 0 FROM "actors"
13
+ WHERE "id" = (SELECT "id" FROM "actors" ORDER BY "cdate" ASC LIMIT 1);
@@ -0,0 +1 @@
1
+ ALTER TABLE "actors" ADD "mastodon_id" TEXT;
@@ -0,0 +1,4 @@
1
+ CREATE TABLE "id_sequences" (
2
+ "key" TEXT PRIMARY KEY,
3
+ "value" INTEGER NOT NULL DEFAULT 0
4
+ );
@@ -0,0 +1,9 @@
1
+ CREATE TABLE "client_credentials" (
2
+ "id" TEXT PRIMARY KEY,
3
+ "client_id" TEXT NOT NULL,
4
+ "access_token" TEXT NOT NULL,
5
+ "scopes" TEXT NOT NULL,
6
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
7
+
8
+ CONSTRAINT "client_credentials_client_id_fkey" FOREIGN KEY ("client_id") REFERENCES "clients" ("id") ON DELETE CASCADE
9
+ );
@@ -0,0 +1,9 @@
1
+ CREATE TABLE "actor_activities" (
2
+ "id" TEXT NOT NULL PRIMARY KEY,
3
+ "actor_id" TEXT NOT NULL,
4
+ "type" TEXT NOT NULL GENERATED ALWAYS AS (json_extract(activity, '$.type')) STORED,
5
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
6
+ "activity" TEXT NOT NULL,
7
+
8
+ CONSTRAINT "actor_activities_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id") ON DELETE CASCADE
9
+ );
@@ -0,0 +1,22 @@
1
+ CREATE TABLE "new_outbox_objects" (
2
+ "id" TEXT NOT NULL PRIMARY KEY,
3
+ "actor_id" TEXT NOT NULL,
4
+ "object_id" TEXT NOT NULL,
5
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
6
+ "published_date" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
7
+ "to" TEXT NOT NULL DEFAULT (json_array()),
8
+ "cc" TEXT NOT NULL DEFAULT (json_array()),
9
+
10
+ CONSTRAINT "outbox_objects_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id") ON DELETE CASCADE,
11
+ CONSTRAINT "outbox_objects_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id") ON DELETE CASCADE
12
+ );
13
+
14
+ INSERT INTO new_outbox_objects (id, actor_id, object_id, cdate, published_date, `to`)
15
+ SELECT id, actor_id, object_id, cdate, published_date, json_array(target) FROM outbox_objects;
16
+
17
+ DROP TABLE outbox_objects;
18
+ ALTER TABLE new_outbox_objects RENAME TO outbox_objects;
19
+
20
+ CREATE INDEX "outbox_objects_actor_id" ON "outbox_objects" ("actor_id");
21
+ CREATE INDEX "outbox_objects_to" ON "outbox_objects" ("to");
22
+ CREATE INDEX "outbox_objects_cc" ON "outbox_objects" ("cc");
@@ -0,0 +1,42 @@
1
+ CREATE TABLE "new_actor_reblogs" (
2
+ "id" TEXT NOT NULL PRIMARY KEY,
3
+ "mastodon_id" TEXT UNIQUE NOT NULL,
4
+ "actor_id" TEXT NOT NULL,
5
+ "object_id" TEXT NOT NULL,
6
+ "outbox_object_id" TEXT UNIQUE NOT NULL,
7
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
8
+
9
+ CONSTRAINT "actor_reblogs_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id") ON DELETE CASCADE,
10
+ CONSTRAINT "actor_reblogs_object_id_fkey" FOREIGN KEY ("object_id") REFERENCES "objects" ("id") ON DELETE CASCADE,
11
+ CONSTRAINT "actor_reblogs_outbox_object_id_fkey" FOREIGN KEY ("outbox_object_id") REFERENCES "outbox_objects" ("id") ON DELETE CASCADE
12
+ );
13
+
14
+ CREATE UNIQUE INDEX "unique_actor_reblogs" ON "new_actor_reblogs" ("actor_id", "object_id");
15
+
16
+ -- D1 does not support transactions, so between the execution of the migration and
17
+ -- the deployment of the Workers, it will not be possible to receive or post reblogs.
18
+
19
+ -- Ideally, the id of the received or created announce activity should be inserted,
20
+ -- but since it was not retained, the URL is made to look appropriate even though it cannot be accessed.
21
+ -- And this query probably won't work in PostgreSQL.
22
+ INSERT INTO new_actor_reblogs (id, mastodon_id, actor_id, object_id, outbox_object_id, cdate)
23
+ SELECT
24
+ 'https://' || substr(
25
+ tmp.object_id,
26
+ instr(tmp.object_id, '//') + 2,
27
+ instr(substr(tmp.object_id, instr(tmp.object_id, '//') + 2), '/') - 1
28
+ ) || '/ap/a/' || actor_reblogs.id AS id,
29
+ actor_reblogs.id AS mastodon_id,
30
+ actor_reblogs.actor_id,
31
+ actor_reblogs.object_id,
32
+ tmp.id AS outbox_object_id,
33
+ actor_reblogs.cdate
34
+ FROM actor_reblogs
35
+ INNER JOIN (
36
+ SELECT *, ROW_NUMBER() OVER (PARTITION BY actor_id, object_id ORDER BY cdate DESC) AS rn
37
+ FROM outbox_objects
38
+ ) tmp ON tmp.actor_id = actor_reblogs.actor_id AND tmp.object_id = actor_reblogs.object_id
39
+ WHERE tmp.rn = 1;
40
+
41
+ DROP TABLE actor_reblogs;
42
+ ALTER TABLE new_actor_reblogs RENAME TO actor_reblogs;
@@ -0,0 +1,2 @@
1
+ CREATE INDEX "actor_reblogs_actor_id" ON "actor_reblogs" ("actor_id");
2
+ CREATE INDEX "actor_reblogs_object_id" ON "actor_reblogs" ("object_id");
@@ -0,0 +1,26 @@
1
+ CREATE TABLE "users" (
2
+ "id" TEXT NOT NULL PRIMARY KEY,
3
+ "actor_id" TEXT UNIQUE NOT NULL,
4
+ "email" TEXT UNIQUE NOT NULL,
5
+ "privkey" BLOB UNIQUE NOT NULL,
6
+ "privkey_salt" BLOB UNIQUE NOT NULL,
7
+ "pubkey" TEXT NOT NULL,
8
+ "is_admin" INTEGER NOT NULL DEFAULT 0,
9
+ "cdate" DATETIME NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
10
+
11
+ CONSTRAINT "users_actor_id_fkey" FOREIGN KEY ("actor_id") REFERENCES "actors" ("id") ON DELETE RESTRICT
12
+ );
13
+ CREATE INDEX "users_email" ON "users" ("email");
14
+
15
+ INSERT INTO users(id, actor_id, email, privkey, privkey_salt, pubkey, cdate, is_admin)
16
+ SELECT
17
+ printf('%s-%s-%s-%s-%s', lower(hex(randomblob(4))), lower(hex(randomblob(2))), lower(hex(randomblob(2))), lower(hex(randomblob(2))), lower(hex(randomblob(6)))) as id,
18
+ id as actor_id,
19
+ email,
20
+ privkey,
21
+ privkey_salt,
22
+ pubkey,
23
+ cdate,
24
+ ifnull(is_admin = 1, 0) as is_admin
25
+ FROM actors
26
+ WHERE email IS NOT NULL;
@@ -0,0 +1,53 @@
1
+ ALTER TABLE `actors` ADD COLUMN `username` text;
2
+ ALTER TABLE `actors` ADD COLUMN `domain` text;
3
+
4
+ CREATE INDEX "actors_mastodon_id" ON "actors" ("mastodon_id");
5
+ CREATE INDEX "actors_username" ON "actors" ("username");
6
+ CREATE INDEX "actors_domain" ON "actors" ("domain");
7
+
8
+ UPDATE actors SET domain = substr(substr(id, instr(id, '//') + 2), 0, instr(substr(id, instr(id, '//') + 2), '/'));
9
+ UPDATE actors SET username = lower(json_extract(properties, '$.preferredUsername'));
10
+
11
+ UPDATE actors SET mastodon_id = printf('%s-%s-%s-%s-%s', lower(hex(randomblob(4))), lower(hex(randomblob(2))), lower(hex(randomblob(2))), lower(hex(randomblob(2))), lower(hex(randomblob(6)))) WHERE mastodon_id IS NULL;
12
+ UPDATE actors SET `type` = json_extract(properties, '$.type');
13
+
14
+ UPDATE actors SET properties = json_set(properties, '$.type', type) WHERE json_extract(properties, '$.type') IS NULL;
15
+ UPDATE actors SET properties = json_set(properties, '$.id', id) WHERE json_extract(properties, '$.id') IS NULL;
16
+
17
+ UPDATE actors SET properties = json_set(properties, '$.featured', id || '/featured')
18
+ WHERE json_extract(properties, '$.featured') IS NULL AND email IS NOT NULL;
19
+
20
+ UPDATE actors SET properties = json_set(properties, '$.publicKey', json_patch(json_object('id', id || '#main-key'), json_object('publicKeyPem', pubkey)))
21
+ WHERE json_extract(properties, '$.publicKey') IS NULL AND email IS NOT NULL;
22
+
23
+ UPDATE actors SET properties = json_set(properties, '$.url', 'https://' || domain || '/@' || username)
24
+ WHERE json_extract(properties, '$.url') IS NULL AND email IS NOT NULL;
25
+
26
+ DROP INDEX `actors_email`;
27
+ ALTER TABLE `actors` DROP COLUMN `email`;
28
+ ALTER TABLE `actors` DROP COLUMN `pubkey`;
29
+ ALTER TABLE `actors` DROP COLUMN `privkey`;
30
+ ALTER TABLE `actors` DROP COLUMN `privkey_salt`;
31
+ ALTER TABLE `actors` DROP COLUMN `is_admin`;
32
+
33
+ DROP TRIGGER `actors_search_fts_insert`;
34
+ DROP TRIGGER `actors_search_fts_update`;
35
+
36
+ CREATE TRIGGER "actors_search_fts_insert" AFTER INSERT ON "actors"
37
+ BEGIN
38
+ INSERT INTO "search_fts" ("rowid", "type", "name", "preferredUsername")
39
+ VALUES ("new"."rowid",
40
+ "new"."type",
41
+ json_extract("new"."properties", '$.name'),
42
+ "new"."username");
43
+ END;
44
+
45
+ CREATE TRIGGER "actors_search_fts_update" AFTER UPDATE ON "actors"
46
+ BEGIN
47
+ DELETE FROM "search_fts" WHERE "rowid"="old"."rowid";
48
+ INSERT INTO "search_fts" ("rowid", "type", "name", "preferredUsername")
49
+ VALUES ("new"."rowid",
50
+ "new"."type",
51
+ json_extract("new"."properties", '$.name'),
52
+ "new"."username");
53
+ END;