@drfed/models 0.2.0-dev.717 → 0.2.0-dev.718
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.
- package/dist/activity-delivery.d.mts +1 -1
- package/dist/{db-CcbUSnp2.d.mts → db-Al_MT-L_.d.mts} +132 -3
- package/dist/{db-CcbUSnp2.d.mts.map → db-Al_MT-L_.d.mts.map} +1 -1
- package/dist/db.d.mts +1 -1
- package/dist/document.mjs +1 -1
- package/dist/expansion-p4BoMDVd.d.mts +90 -0
- package/dist/expansion-p4BoMDVd.d.mts.map +1 -0
- package/dist/expansion.d.mts +2 -0
- package/dist/expansion.mjs +131 -0
- package/dist/expansion.mjs.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/instance.d.mts +1 -1
- package/dist/key.d.mts +1 -1
- package/dist/login.d.mts +1 -1
- package/dist/migrations-manifest.json +4 -0
- package/dist/relations.d.mts +1 -1
- package/dist/{resource-revision-rDmHhNCj.d.mts → resource-revision-BbXciRsu.d.mts} +117 -4
- package/dist/resource-revision-BbXciRsu.d.mts.map +1 -0
- package/dist/{resource-revision-bTQyJ7aw.mjs → resource-revision-DGsz8fnS.mjs} +338 -42
- package/dist/resource-revision-DGsz8fnS.mjs.map +1 -0
- package/dist/resource-revision.d.mts +2 -2
- package/dist/resource-revision.mjs +1 -1
- package/dist/resource.d.mts +1 -1
- package/dist/schema.d.mts +2 -2
- package/dist/schema.mjs +55 -1
- package/dist/schema.mjs.map +1 -1
- package/drizzle/20261125051505_revision_expansions/migration.sql +31 -0
- package/drizzle/20261125051505_revision_expansions/snapshot.json +4806 -0
- package/package.json +12 -7
- package/dist/resource-revision-bTQyJ7aw.mjs.map +0 -1
- package/dist/resource-revision-rDmHhNCj.d.mts.map +0 -1
package/dist/schema.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport type { webcrypto } from \"node:crypto\";\n\nimport { desc, sql } from \"drizzle-orm\";\nimport {\n type AnyPgColumn,\n boolean,\n bytea,\n char,\n check,\n customType,\n foreignKey,\n index,\n integer,\n json,\n jsonb,\n pgEnum,\n pgTable,\n primaryKey,\n text,\n unique,\n uniqueIndex,\n uuid,\n varchar,\n} from \"drizzle-orm/pg-core\";\n\nimport type { PublicJwk } from \"./key.ts\";\nimport type { Uuid } from \"./uuid.ts\";\n\n/** A timestamptz column preserving PostgreSQL's microsecond precision. */\nconst instant = customType<{ data: Temporal.Instant; driverData: string }>({\n dataType: () => \"timestamp with time zone\",\n fromDriver: (value) => Temporal.Instant.from(value),\n toDriver(value: Temporal.Instant | string) {\n // Pothos composite cursors decode timestamps as strings.\n if (typeof value === \"string\") return value;\n if (value instanceof Temporal.Instant) return value.toString();\n throw new TypeError(\n \"Expected a Temporal.Instant or a cursor timestamp string.\",\n );\n },\n});\n\nconst currentTimestamp = sql`CURRENT_TIMESTAMP`;\n\n/**\n * The database table to represent accounts.\n */\nexport const accounts = pgTable(\n \"accounts\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n email: varchar({ length: 255 }).notNull().unique(),\n name: varchar({ length: 100 }).notNull(),\n maxInstances: integer(\"max_instances\").notNull().default(10),\n admin: boolean().notNull().default(false),\n created: instant().notNull().default(currentTimestamp),\n },\n (table) => [\n check(\n \"accounts_email_check\",\n sql`${table.email} ~ '^[^@]+@[^@]+\\\\.[^@]+$'`,\n ),\n check(\"accounts_max_instances_check\", sql`${table.maxInstances} >= 0`),\n check(\"accounts_name_check\", sql`trim(both from ${table.name}) <> ''`),\n ],\n);\n\nexport type Account = typeof accounts.$inferSelect;\nexport type NewAccount = typeof accounts.$inferInsert;\n\n/**\n * The database table to represent instances.\n */\nexport const instances = pgTable(\"instances\", {\n id: uuid().$type<Uuid>().primaryKey(),\n localId: uuid(\"local_id\")\n .$type<Uuid>()\n .references(() => localInstances.id, {\n onDelete: \"cascade\",\n }),\n created: instant().notNull().default(currentTimestamp),\n // The authority an instance is federated under, which is what Fedify's\n // `Context.host` reports and therefore what dispatchers look instances up\n // by. That is a DNS name, at most 253 octets, plus a `:port` suffix of up\n // to 6 more characters when the deployment is not on the scheme's default\n // port. Both locally composed `<slug>.<root domain>` names and remote\n // hosts discovered from the fediverse live here.\n host: varchar({ length: 259 }).notNull().unique(),\n nodeInfoUrl: text(\"node_info_url\"),\n software: text(),\n softwareVersion: text(\"software_version\"),\n});\n\nexport type Instance = typeof instances.$inferSelect;\nexport type NewInstance = typeof instances.$inferInsert;\n\nexport const localInstances = pgTable(\n \"local_instances\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n slug: varchar({ length: 63 }).notNull().unique(),\n expires: instant().notNull(),\n maxActors: integer(\"max_actors\").notNull().default(10),\n },\n (table) => [\n // Keep this in agreement with `isValidSlug()` in ./slug.ts. A slug\n // becomes the leftmost label of the instance's host name, so it has to be\n // a valid DNS label: no leading or trailing hyphen, and none of RFC 5891's\n // reserved LDH labels except the `xn--` prefix of an A-label, which stays\n // allowed so that instances can carry internationalized domain names.\n check(\n \"local_instances_slug_check\",\n sql`${table.slug} ~ '^[a-z0-9][a-z0-9-]{2,61}[a-z0-9]$'\n AND (${table.slug} !~ '^..--' OR ${table.slug} ~ '^xn--')`,\n ),\n check(\"instances_max_actors_check\", sql`${table.maxActors} > 0`),\n ],\n);\n\nexport type LocalInstance = typeof localInstances.$inferSelect;\nexport type NewLocalInstance = typeof localInstances.$inferInsert;\n\n/**\n * The association table between instances and its member accounts.\n * Note that it also contains the just invited members, which are not yet\n * accepted. The `accepted` field is `NULL` for those members.\n */\nexport const instanceMembers = pgTable(\n \"instance_members\",\n {\n accountId: uuid(\"account_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => accounts.id),\n instanceId: uuid(\"instance_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => instances.id),\n admin: boolean().notNull().default(false),\n accepted: instant(),\n created: instant().notNull().default(currentTimestamp),\n },\n (table) => [\n primaryKey({ columns: [table.instanceId, table.accountId] }),\n index()\n .on(table.accountId)\n .where(sql`${table.accepted} IS NOT NULL`),\n index()\n .on(table.instanceId)\n .where(sql`${table.accepted} IS NOT NULL`),\n ],\n);\n\nexport type InstanceMember = typeof instanceMembers.$inferSelect;\nexport type NewInstanceMember = typeof instanceMembers.$inferInsert;\n\n/** The length of an email login verification code. */\nexport const LOGIN_CHALLENGE_CODE_LENGTH = 6;\n\n/**\n * Email login challenges identified by a public UUID and verified by a\n * plaintext code. Each challenge expires after 15 minutes and is single-use.\n */\nexport const loginChallenges = pgTable(\"login_challenges\", {\n id: uuid().$type<Uuid>().primaryKey(),\n accountId: uuid(\"account_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => accounts.id, { onDelete: \"cascade\" }),\n code: char({ length: LOGIN_CHALLENGE_CODE_LENGTH }).notNull(),\n created: instant().notNull().default(currentTimestamp),\n expires: instant()\n .notNull()\n .default(sql`CURRENT_TIMESTAMP + INTERVAL '15 minutes'`),\n consumed: instant(),\n});\n\nexport type LoginChallenge = typeof loginChallenges.$inferSelect;\nexport type NewLoginChallenge = typeof loginChallenges.$inferInsert;\n\n/**\n * Authenticated sessions. The `id` field is used to revoke a session, and\n * the `tokenHash` is the hash of the bearer access token.\n */\nexport const sessions = pgTable(\"sessions\", {\n id: uuid().$type<Uuid>().primaryKey(),\n accountId: uuid(\"account_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => accounts.id, { onDelete: \"cascade\" }),\n tokenHash: varchar(\"token_hash\", { length: 64 }).notNull().unique(),\n created: instant().notNull().default(currentTimestamp),\n expires: instant()\n .notNull()\n .default(sql`CURRENT_TIMESTAMP + INTERVAL '1 month'`),\n});\n\nexport type Session = typeof sessions.$inferSelect;\nexport type NewSession = typeof sessions.$inferInsert;\n\nexport const actorTypeEnum = pgEnum(\"actor_type\", [\n \"Application\",\n \"Group\",\n \"Organization\",\n \"Person\",\n \"Service\",\n]);\n\nexport type ActorType = (typeof actorTypeEnum.enumValues)[number];\n\nexport const resourceKindEnum = pgEnum(\"resource_kind\", [\n \"actor\",\n \"object\",\n \"activity\",\n \"collection\",\n \"unknown\",\n]);\n\n/**\n * Canonical IRI registry. Retained revisions keep their resource identity\n * even after a current typed row is deleted. Other references may also\n * intentionally restrict physical removal of the resource.\n */\nexport const resources = pgTable(\"resources\", {\n id: uuid().$type<Uuid>().primaryKey(),\n iri: text().notNull().unique(),\n kind: resourceKindEnum().notNull(),\n created: instant().notNull().default(currentTimestamp),\n});\nexport type Resource = typeof resources.$inferSelect;\n\nexport const actors = pgTable(\n \"actors\",\n {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n localId: uuid(\"local_id\")\n .$type<Uuid>()\n .unique()\n .references(() => localActors.id, { onDelete: \"cascade\" }),\n type: actorTypeEnum().notNull(),\n /**\n * A local actor's handle username; a remote actor's `preferredUsername`\n * as received, which ActivityPub neither requires nor makes unique.\n */\n username: text(),\n instanceId: uuid(\"instance_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => instances.id, { onDelete: \"cascade\" }),\n document: json(),\n inboxUrl: text(\"inbox_url\").notNull(),\n /**\n * The IRI of the followers collection a remote actor declares, as\n * received. It is never fetched, so it is no `collections` row: what the\n * collection is and holds is unknown.\n */\n followersUrl: text(\"followers_url\"),\n profileUrl: text(\"profile_url\"),\n avatarUrl: text(\"avatar_url\"),\n headerUrl: text(\"header_url\"),\n name: text(),\n bioHtml: text(\"bio_html\"),\n automaticallyApprovesFollowers: boolean(\"automatically_approves_followers\")\n .notNull()\n .default(false),\n fieldHtmls: jsonb(\"field_htmls\")\n .$type<Record<string, string>>()\n .notNull()\n .default({}),\n emojis: jsonb().$type<Record<string, string>>().notNull().default({}),\n tags: jsonb().$type<Record<string, string>>().notNull().default({}),\n sensitive: boolean().notNull().default(false),\n // Moderation sanction state, denormalized from flag_action records\n // (which remain the audit source of truth):\n // - Not sanctioned: suspended IS NULL\n // - Temporary suspension: suspended = start, suspendedUntil = end\n // - Permanent suspension (ban) for local actors, or permanent federation\n // block for remote actors: suspended set, suspendedUntil IS NULL\n // Whether a sanction is *currently* active is always determined by\n // comparing against the current time (lazy expiry; no cron):\n // Temporal.Instant.compare(suspended, now) <= 0 AND (suspendedUntil IS NULL OR Temporal.Instant.compare(suspendedUntil, now) > 0).\n suspended: instant(),\n suspendedUntil: instant(\"suspended_until\"),\n successorId: uuid(\"successor_id\")\n .$type<Uuid>()\n .references((): AnyPgColumn => actors.id, {\n onDelete: \"set null\",\n }),\n aliases: text()\n .array()\n .notNull()\n .default(sql`(ARRAY[]::text[])`),\n followingCount: integer(\"following_count\").notNull().default(0),\n followersCount: integer(\"followers_count\").notNull().default(0),\n updated: instant()\n .notNull()\n .default(currentTimestamp)\n .$onUpdate(() => currentTimestamp),\n published: instant(),\n created: instant().notNull().default(currentTimestamp),\n // When implementing actor deletion, add activities.deleted and set it\n // together with objects.deleted in the same transaction.\n // FIXME: https://github.com/fedify-dev/drfed/issues/89\n deleted: instant(),\n },\n (t) => [\n uniqueIndex(\"username_key\")\n .on(t.username, t.instanceId)\n .where(sql`${t.localId} IS NOT NULL`),\n check(\n \"actors_username_check\",\n sql`${t.localId} IS NULL OR ${t.username} NOT LIKE '%@%'`,\n ),\n check(\n \"actors_local_username_check\",\n sql`${t.localId} IS NULL OR ${t.username} IS NOT NULL`,\n ),\n check(\n \"actors_suspended_check\",\n sql`\n ${t.suspendedUntil} IS NULL OR (\n ${t.suspended} IS NOT NULL AND\n ${t.suspendedUntil} > ${t.suspended}\n )\n `,\n ),\n index(\"actor_instance_index\").on(t.instanceId),\n ],\n);\n\nexport type Actor = typeof actors.$inferSelect;\nexport type NewActor = typeof actors.$inferInsert;\n\nexport const localActors = pgTable(\"local_actors\", {\n id: uuid().$type<Uuid>().primaryKey(),\n avatar: text(),\n header: text(),\n});\n\nexport type LocalActor = typeof localActors.$inferSelect;\nexport type NewLocalActor = typeof localActors.$inferInsert;\n\n/** Signing algorithms available to local actors. */\nexport const localActorKeyTypeEnum = pgEnum(\"local_actor_key_type\", [\n \"RSASSA-PKCS1-v1_5\",\n \"Ed25519\",\n]);\nexport type LocalActorKeyType =\n (typeof localActorKeyTypeEnum.enumValues)[number];\n/** Private signing material; never expose this table through GraphQL. */\nexport const localActorKeys = pgTable(\n \"local_actor_keys\",\n {\n localActorId: uuid(\"local_actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => localActors.id, { onDelete: \"cascade\" }),\n type: localActorKeyTypeEnum().notNull(),\n publicKey: jsonb(\"public_key\").$type<PublicJwk>().notNull(),\n privateKey: jsonb(\"private_key\").$type<webcrypto.JsonWebKey>().notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.localActorId, table.type] }),\n check(\n \"local_actor_keys_public_key_check\",\n sql`jsonb_typeof(${table.publicKey}) = 'object' AND NOT (${table.publicKey} ?| array['d','p','q','dp','dq','qi','oth','k'])`,\n ),\n ],\n);\nexport type LocalActorKey = typeof localActorKeys.$inferSelect;\nexport type NewLocalActorKey = typeof localActorKeys.$inferInsert;\n\nexport const objectTypeEnum = pgEnum(\"object_type\", [\"Article\", \"Note\"]);\nexport type ObjectType = (typeof objectTypeEnum.enumValues)[number];\n/** ActivityPub objects authored by actors. */\nexport const objects = pgTable(\n \"objects\",\n {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n /**\n * The activity that carried the stored snapshot. Who may read a remote\n * object follows it, not the activities that refer to the object later\n * with another version of it.\n */\n activityId: uuid(\"activity_id\")\n .$type<Uuid>()\n .references(() => resources.id, { onDelete: \"set null\" }),\n /**\n * Whether `document` was fetched from the object's IRI rather than taken\n * from the activity that carried it, which then proves nothing of it.\n */\n fetched: boolean().notNull().default(false),\n type: objectTypeEnum().notNull(),\n document: json(),\n url: text(),\n name: text(),\n summary: text(),\n contentHtml: text(\"content_html\").notNull(),\n language: varchar({ length: 35 }),\n sensitive: boolean().notNull().default(false),\n published: instant().notNull().default(currentTimestamp),\n updated: instant()\n .notNull()\n .default(currentTimestamp)\n .$onUpdate(() => currentTimestamp),\n created: instant().notNull().default(currentTimestamp),\n deleted: instant(),\n },\n (t) => [\n check(\n \"objects_content_html_check\",\n sql`trim(both from ${t.contentHtml}) <> ''`,\n ),\n unique(\"objects_activity_id_key\").on(t.activityId),\n index(\"object_actor_published_index\").on(\n t.actorId,\n desc(t.published),\n desc(t.id),\n ),\n ],\n);\nexport type ActivityPubObject = typeof objects.$inferSelect;\nexport type NewActivityPubObject = typeof objects.$inferInsert;\n\nexport const collectionTypeEnum = pgEnum(\"collection_type\", [\n \"Collection\",\n \"OrderedCollection\",\n]);\nexport const collectionRoleEnum = pgEnum(\"collection_role\", [\n \"followers\",\n \"following\",\n \"featured\",\n \"outbox\",\n]);\nexport type CollectionRole = (typeof collectionRoleEnum.enumValues)[number];\nexport const collections = pgTable(\"collections\", {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n type: collectionTypeEnum().notNull(),\n /**\n * Lifecycle owner of a locally managed collection. Physical deletion of\n * the owner cascades to the collection and all references. Soft deletion\n * hides the collection and every actor's reference to it from GraphQL.\n */\n ownerActorId: uuid(\"owner_actor_id\")\n .$type<Uuid>()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n totalItems: integer(\"total_items\"),\n document: json(),\n updated: instant()\n .notNull()\n .default(currentTimestamp)\n .$onUpdate(() => currentTimestamp),\n});\nexport type Collection = typeof collections.$inferSelect;\n\n/** Actor-declared collection roles; a collection may be shared across roles or actors. */\nexport const actorCollectionReferences = pgTable(\n \"actor_collection_references\",\n {\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n role: collectionRoleEnum().notNull(),\n collectionId: uuid(\"collection_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => collections.id, { onDelete: \"cascade\" }),\n },\n (t) => [\n primaryKey({ columns: [t.actorId, t.role] }),\n index(\"actor_collection_reference_collection_index\").on(t.collectionId),\n ],\n);\n\nexport const collectionItems = pgTable(\n \"collection_items\",\n {\n collectionId: uuid(\"collection_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => collections.id, { onDelete: \"cascade\" }),\n itemId: uuid(\"item_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n position: integer(),\n observed: instant().notNull().default(currentTimestamp),\n },\n (t) => [\n primaryKey({ columns: [t.collectionId, t.itemId] }),\n index(\"collection_item_position_index\").on(t.collectionId, t.position),\n ],\n);\n\nexport const activityTypeEnum = pgEnum(\"activity_type\", [\"Create\"]);\nexport const activities = pgTable(\n \"activities\",\n {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n type: activityTypeEnum().notNull(),\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n objectId: uuid(\"object_id\")\n .$type<Uuid>()\n .references(() => resources.id, { onDelete: \"set null\" }),\n published: instant().notNull(),\n document: json(),\n created: instant().notNull().default(currentTimestamp),\n },\n (t) => [\n index(\"activity_actor_published_index\").on(\n t.actorId,\n desc(t.published),\n desc(t.id),\n ),\n index(\"activity_object_published_index\").on(t.objectId, t.published, t.id),\n ],\n);\nexport type StoredActivity = typeof activities.$inferSelect;\n\nexport const addressingPropertyEnum = pgEnum(\"addressing_property\", [\n \"to\",\n \"cc\",\n \"bto\",\n \"bcc\",\n \"audience\",\n]);\nexport type AddressingProperty =\n (typeof addressingPropertyEnum.enumValues)[number];\nexport const addressing = pgTable(\n \"addressing\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n sourceId: uuid(\"source_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n property: addressingPropertyEnum().notNull(),\n position: integer().notNull(),\n targetId: uuid(\"target_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"restrict\" }),\n },\n (t) => [\n unique(\"addressing_source_property_position_key\").on(\n t.sourceId,\n t.property,\n t.position,\n ),\n index(\"addressing_target_property_index\").on(t.targetId, t.property),\n ],\n);\nexport type Addressing = typeof addressing.$inferSelect;\n\n/** Direction of an observed delivery. */\nexport const activityDeliveryDirectionEnum = pgEnum(\n \"activity_delivery_direction\",\n [\"inbound\", \"outbound\"],\n);\n\n/**\n * Inbound: `received` (2xx, listener ran), `acknowledged` (2xx, listener did\n * not run), `unverified`, `rejected` (refused although verified); a request\n * whose handling threw is one of the last two, without a status code. Outbound:\n * `queued` (no attempt ended yet), `sent`, `failed` (the latest attempt\n * failed; a queued delivery may be retried), `permanently_failed`,\n * `abandoned` (the retry policy ran out).\n */\nexport const activityDeliveryStatusEnum = pgEnum(\"activity_delivery_status\", [\n \"received\",\n \"acknowledged\",\n \"unverified\",\n \"rejected\",\n \"queued\",\n \"sent\",\n \"failed\",\n \"permanently_failed\",\n \"abandoned\",\n]);\n\n/** The mechanism that authenticated an inbound activity. */\nexport const activityDeliveryVerificationMechanismEnum = pgEnum(\n \"activity_delivery_verification_mechanism\",\n [\"http_signature\", \"ld_signature\", \"object_integrity_proof\"],\n);\n\n/**\n * What Fedify reported of an inbound verification; `unattempted` when it\n * answered before verifying, and `unobserved` when recording failed.\n */\nexport const activityDeliveryVerificationResultEnum = pgEnum(\n \"activity_delivery_verification_result\",\n [\n \"verified\",\n \"invalid_signature\",\n \"key_fetch_error\",\n \"no_signature\",\n \"unattempted\",\n \"unobserved\",\n ],\n);\n\n/** Logical public keys, identified by their exact IRI. */\nexport const keys = pgTable(\"keys\", {\n id: uuid().$type<Uuid>().primaryKey(),\n iri: text().notNull().unique(),\n created: instant().notNull().default(currentTimestamp),\n});\n\n/** Immutable key material, independently retained from Fedify's KV cache. */\nexport const keyVersions = pgTable(\n \"key_versions\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n keyId: uuid(\"key_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => keys.id, { onDelete: \"restrict\" }),\n publicKey: jsonb(\"public_key\").$type<PublicJwk>().notNull(),\n fingerprint: text().notNull(),\n /** DrFed observation time, not remote rotation time or evidence of continuous use. */\n firstSeen: instant(\"first_seen\").notNull(),\n /** DrFed observation time, not remote rotation time or evidence of continuous use. */\n lastSeen: instant(\"last_seen\").notNull(),\n },\n (table) => [\n unique(\"key_versions_key_id_fingerprint_unique\").on(\n table.keyId,\n table.fingerprint,\n ),\n check(\n \"key_versions_seen_check\",\n sql`${table.lastSeen} >= ${table.firstSeen}`,\n ),\n check(\n \"key_versions_public_key_check\",\n sql`NOT (${table.publicKey} ?| array['d','p','q','dp','dq','qi','oth','k'])`,\n ),\n index(\"key_version_key_first_seen_index\").on(\n table.keyId,\n table.firstSeen,\n table.id,\n ),\n ],\n);\n\n/** Delivery observations; payloads may contain unverified, private remote input. */\nexport const activityDeliveries = pgTable(\n \"activity_deliveries\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n instanceId: uuid(\"instance_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => instances.id, { onDelete: \"cascade\" }),\n /** The owner of the inbox the request arrived at, or the sending actor. */\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .references(() => actors.id, { onDelete: \"set null\" }),\n direction: activityDeliveryDirectionEnum().notNull(),\n status: activityDeliveryStatusEnum().notNull(),\n verificationMechanism: activityDeliveryVerificationMechanismEnum(\n \"verification_mechanism\",\n ),\n verificationResult: activityDeliveryVerificationResultEnum(\n \"verification_result\",\n ),\n type: text(),\n types: text()\n .array()\n .notNull()\n .default(sql`'{}'`),\n activityIri: text(\"activity_iri\"),\n /**\n * The stored activity `activityIri` names: for an inbound delivery, only\n * one Fedify verified and accepted. The database enforces the latter;\n * `linkInboundActivity()` matches the IRI.\n */\n activityId: uuid(\"activity_id\")\n .$type<Uuid>()\n .references(() => activities.id, { onDelete: \"set null\" }),\n /**\n * Whether an inbound delivery carried the stored activity as it is, not\n * only its IRI. `linkInboundActivity()` decides it, and only such a\n * delivery opens the activity to its instance.\n */\n carriedSnapshot: boolean(\"carried_snapshot\").notNull().default(false),\n /**\n * The object an inbound delivery's inbox listener fetched from its IRI,\n * when it had to.\n */\n fetchedObject: jsonb(\"fetched_object\").$type<unknown>(),\n /**\n * Whether an inbound delivery carried the object stored with its activity\n * as it is: the activity carried it, or the delivery fetched it as stored.\n * `linkInboundActivity()` decides it, and only such a delivery opens the\n * object to its instance.\n */\n carriedObjectSnapshot: boolean(\"carried_object_snapshot\")\n .notNull()\n .default(false),\n objectType: text(\"object_type\"),\n objectIri: text(\"object_iri\"),\n signedKeyIri: text(\"signed_key_iri\"),\n /** A referenced version does not imply successful verification. */\n verificationKeyId: uuid(\"verification_key_id\")\n .$type<Uuid>()\n .references(() => keyVersions.id, { onDelete: \"restrict\" }),\n /** Inbound, only the first `actor`; the rest are in `payload`. */\n remoteActorIri: text(\"remote_actor_iri\"),\n remoteHost: text(\"remote_host\"),\n inboxUrl: text(\"inbox_url\").notNull(),\n requestUrl: text(\"request_url\"),\n /** Names are lowercase; original order and case are not kept. */\n headers: jsonb().$type<readonly (readonly [string, string])[]>(),\n body: bytea(),\n statusCode: integer(\"status_code\"),\n responseBody: text(\"response_body\"),\n error: text(),\n payload: jsonb().$type<unknown>(),\n recipientIris: text(\"recipient_iris\")\n .array()\n .notNull()\n .default(sql`'{}'`),\n /** Inbound, when the request arrived; outbound, when delivery started. */\n created: instant().notNull().default(currentTimestamp),\n /** Inbound, when DrFed answered; outbound, the latest status change. */\n completed: instant(),\n },\n (table) => [\n check(\n \"activity_deliveries_direction_status_check\",\n sql`(${table.direction} = 'inbound' AND ${table.status} IN ('received', 'acknowledged', 'unverified', 'rejected')) OR (${table.direction} = 'outbound' AND ${table.status} IN ('queued', 'sent', 'failed', 'permanently_failed', 'abandoned'))`,\n ),\n check(\n \"activity_deliveries_completed_check\",\n sql`(${table.completed} IS NULL) = (${table.status} = 'queued')`,\n ),\n check(\n \"activity_deliveries_status_code_check\",\n sql`${table.statusCode} IS NULL OR ${table.statusCode} BETWEEN 100 AND 599`,\n ),\n check(\n \"activity_deliveries_outbound_key_check\",\n sql`${table.direction} <> 'outbound' OR ${table.verificationKeyId} IS NULL`,\n ),\n check(\n \"activity_deliveries_verification_result_check\",\n sql`(${table.direction} = 'inbound') = (${table.verificationResult} IS NOT NULL)`,\n ),\n check(\n \"activity_deliveries_verification_mechanism_check\",\n sql`${table.verificationMechanism} IS NULL OR (${table.direction} = 'inbound' AND ${table.verificationResult} NOT IN ('unattempted', 'unobserved'))`,\n ),\n check(\n \"activity_deliveries_body_check\",\n sql`(${table.direction} = 'inbound') = (${table.body} IS NOT NULL)`,\n ),\n check(\n \"activity_deliveries_activity_check\",\n sql`${table.activityId} IS NULL OR ${table.direction} = 'outbound' OR (${table.verificationResult} = 'verified' AND ${table.status} IN ('received', 'acknowledged'))`,\n ),\n index(\"activity_delivery_instance_created_index\").on(\n table.instanceId,\n desc(table.created),\n desc(table.id),\n ),\n index(\"activity_delivery_actor_index\").on(table.actorId),\n index(\"activity_delivery_activity_created_index\").on(\n table.activityId,\n desc(table.created),\n desc(table.id),\n ),\n index(\"activity_delivery_verification_key_index\").on(\n table.verificationKeyId,\n ),\n index(\"activity_delivery_outbound_index\")\n .on(table.activityIri, table.inboxUrl)\n .where(sql`${table.direction} = 'outbound'`),\n ],\n);\n\n/** Each ended attempt of an outbound delivery. */\nexport const activityDeliveryAttempts = pgTable(\n \"activity_delivery_attempts\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n deliveryId: uuid(\"delivery_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => activityDeliveries.id, { onDelete: \"cascade\" }),\n succeeded: boolean().notNull(),\n statusCode: integer(\"status_code\"),\n responseBody: text(\"response_body\"),\n error: text(),\n /** When the attempt ended. */\n created: instant().notNull().default(currentTimestamp),\n },\n (table) => [\n check(\n \"activity_delivery_attempts_status_code_check\",\n sql`${table.statusCode} IS NULL OR ${table.statusCode} BETWEEN 100 AND 599`,\n ),\n check(\n \"activity_delivery_attempts_error_check\",\n sql`${table.succeeded} = (${table.error} IS NULL)`,\n ),\n index(\"activity_delivery_attempt_delivery_index\").on(\n table.deliveryId,\n table.created,\n table.id,\n ),\n ],\n);\n\n/**\n * The local actors a delivery concerns, one row per delivery and actor; each\n * must be a local actor of the delivery's instance, which the record functions\n * check.\n */\nexport const activityDeliveryActors = pgTable(\n \"activity_delivery_actors\",\n {\n deliveryId: uuid(\"delivery_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => activityDeliveries.id, { onDelete: \"cascade\" }),\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n inboxOwner: boolean(\"inbox_owner\").notNull().default(false),\n /** Addressed directly or through a collection. */\n addressed: boolean().notNull().default(false),\n /** Addressed by its own IRI; collections are in a row each. */\n addressedDirectly: boolean(\"addressed_directly\").notNull().default(false),\n sender: boolean().notNull().default(false),\n /** The delivery's `created`, which an actor's deliveries are ordered by. */\n created: instant().notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.deliveryId, table.actorId] }),\n check(\n \"activity_delivery_actors_role_check\",\n sql`${table.inboxOwner} OR ${table.addressed} OR ${table.sender}`,\n ),\n check(\n \"activity_delivery_actors_addressed_directly_check\",\n sql`NOT ${table.addressedDirectly} OR ${table.addressed}`,\n ),\n index(\"activity_delivery_actor_created_index\").on(\n table.actorId,\n desc(table.created),\n desc(table.deliveryId),\n ),\n ],\n);\n\n/** Each addressed collection a delivery reached a local actor through. */\nexport const activityDeliveryActorCollections = pgTable(\n \"activity_delivery_actor_collections\",\n {\n deliveryId: uuid(\"delivery_id\").$type<Uuid>().notNull(),\n actorId: uuid(\"actor_id\").$type<Uuid>().notNull(),\n collectionIri: text(\"collection_iri\").notNull(),\n },\n (table) => [\n primaryKey({\n columns: [table.deliveryId, table.actorId, table.collectionIri],\n }),\n foreignKey({\n name: \"activity_delivery_actor_collections_link_fkey\",\n columns: [table.deliveryId, table.actorId],\n foreignColumns: [\n activityDeliveryActors.deliveryId,\n activityDeliveryActors.actorId,\n ],\n }).onDelete(\"cascade\"),\n ],\n);\nexport type Key = typeof keys.$inferSelect;\nexport type KeyVersion = typeof keyVersions.$inferSelect;\nexport type ActivityDelivery = typeof activityDeliveries.$inferSelect;\nexport type NewActivityDelivery = typeof activityDeliveries.$inferInsert;\nexport type ActivityDeliveryAttempt =\n typeof activityDeliveryAttempts.$inferSelect;\nexport type ActivityDeliveryActor = typeof activityDeliveryActors.$inferSelect;\nexport type NewActivityDeliveryActor =\n typeof activityDeliveryActors.$inferInsert;\nexport type ActivityDeliveryActorCollection =\n typeof activityDeliveryActorCollections.$inferSelect;\nexport type ActivityDeliveryDirection =\n (typeof activityDeliveryDirectionEnum.enumValues)[number];\nexport type ActivityDeliveryStatus =\n (typeof activityDeliveryStatusEnum.enumValues)[number];\nexport type ActivityDeliveryVerificationMechanism =\n (typeof activityDeliveryVerificationMechanismEnum.enumValues)[number];\nexport type ActivityDeliveryVerificationResult =\n (typeof activityDeliveryVerificationResultEnum.enumValues)[number];\n\nexport const resourceRevisionKindEnum = pgEnum(\"resource_revision_kind\", [\n \"snapshot\",\n \"unavailable\",\n \"whiteout\",\n]);\nexport const resourceRevisionCaptureEnum = pgEnum(\"resource_revision_capture\", [\n \"local\",\n \"received\",\n \"embedded\",\n \"fetched\",\n]);\nexport const resourceRevisionProjectionEnum = pgEnum(\n \"resource_revision_projection\",\n [\"partial\", \"complete\"],\n);\n\n/** Immutable parsed documents, independently of current typed rows. */\nexport const resourceRevisions = pgTable(\n \"resource_revisions\",\n {\n id: uuid().$type<Uuid>().primaryKey().defaultRandom(),\n resourceId: uuid(\"resource_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"restrict\" }),\n sequence: integer().notNull(),\n kind: resourceRevisionKindEnum().notNull(),\n capture: resourceRevisionCaptureEnum().notNull(),\n backfilled: boolean().notNull().default(false),\n document: json(),\n formerTypes: text(\"former_types\").array(),\n deleted: instant(),\n projection: resourceRevisionProjectionEnum().notNull().default(\"partial\"),\n created: instant().notNull().default(currentTimestamp),\n },\n (t) => [\n unique(\"resource_revisions_resource_sequence_key\").on(\n t.resourceId,\n t.sequence,\n ),\n unique(\"resource_revisions_resource_id_key\").on(t.resourceId, t.id),\n check(\"resource_revisions_sequence_check\", sql`${t.sequence} > 0`),\n check(\n \"resource_revisions_document_check\",\n sql`(${t.kind} = 'snapshot' AND ${t.document} IS NOT NULL)\n OR (${t.kind} IN ('unavailable', 'whiteout') AND ${t.document} IS NULL)`,\n ),\n check(\n \"resource_revisions_deletion_check\",\n sql`(${t.kind} = 'whiteout' AND ${t.deleted} IS NOT NULL AND ${t.formerTypes} IS NOT NULL)\n OR (${t.kind} <> 'whiteout' AND ${t.deleted} IS NULL AND ${t.formerTypes} IS NULL)`,\n ),\n ],\n);\n\n/** The current revision of one canonical resource. */\nexport const resourceHeads = pgTable(\n \"resource_heads\",\n {\n resourceId: uuid(\"resource_id\")\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"restrict\" }),\n revisionId: uuid(\"revision_id\").$type<Uuid>().notNull(),\n },\n (t) => [\n foreignKey({\n name: \"resource_heads_resource_revision_fkey\",\n columns: [t.resourceId, t.revisionId],\n foreignColumns: [resourceRevisions.resourceId, resourceRevisions.id],\n }).onDelete(\"restrict\"),\n ],\n);\n\n/** Root addressing occurrences, including blind recipients and duplicates. */\nexport const revisionAddressing = pgTable(\n \"revision_addressing\",\n {\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n property: addressingPropertyEnum().notNull(),\n position: integer().notNull(),\n iri: text().notNull(),\n },\n (t) => [\n primaryKey({ columns: [t.revisionId, t.property, t.position] }),\n check(\"revision_addressing_position_check\", sql`${t.position} >= 0`),\n index(\"revision_addressing_iri_property_index\").on(t.iri, t.property),\n ],\n);\n\nexport const revisionRelationRepresentationEnum = pgEnum(\n \"revision_relation_representation\",\n [\"reference\", \"embedded\", \"link\"],\n);\n/** Caller-supplied relation occurrences; the saved JSON remains authoritative. */\nexport const revisionRelations = pgTable(\n \"revision_relations\",\n {\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n occurrence: integer().notNull(),\n property: text().notNull(),\n path: json().$type<readonly (string | number)[]>(),\n representation: revisionRelationRepresentationEnum().notNull(),\n targetIri: text(\"target_iri\"),\n },\n (t) => [\n primaryKey({ columns: [t.revisionId, t.occurrence] }),\n check(\"revision_relations_occurrence_check\", sql`${t.occurrence} >= 0`),\n check(\n \"revision_relations_path_check\",\n sql`${t.path} IS NULL OR json_typeof(${t.path}) = 'array'`,\n ),\n check(\n \"revision_relations_reference_check\",\n sql`${t.representation} <> 'reference' OR ${t.targetIri} IS NOT NULL`,\n ),\n index(\"revision_relations_property_target_index\").on(\n t.property,\n t.targetIri,\n t.revisionId,\n ),\n ],\n);\n\nexport const revisionEmbeddingRelationEnum = pgEnum(\n \"revision_embedding_relation\",\n [\"snapshot\", \"derived\"],\n);\n/**\n * Where an embedded document of a revision came from, recorded when the\n * revision was saved: the revision of another resource whose contents it\n * keeps, apart from the context it inherits, or from which it was derived.\n * An embedded document without a row has an unknown source. Rows are part\n * of the immutable history of their revision.\n */\nexport const revisionEmbeddings = pgTable(\n \"revision_embeddings\",\n {\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n path: jsonb().$type<readonly (string | number)[]>().notNull(),\n sourceRevisionId: uuid(\"source_revision_id\").$type<Uuid>().notNull(),\n relation: revisionEmbeddingRelationEnum().notNull(),\n },\n (t) => [\n primaryKey({ columns: [t.revisionId, t.path] }),\n foreignKey({\n name: \"revision_embeddings_source_revision_fkey\",\n columns: [t.sourceRevisionId],\n foreignColumns: [resourceRevisions.id],\n }).onDelete(\"restrict\"),\n check(\n \"revision_embeddings_path_check\",\n sql`jsonb_typeof(${t.path}) = 'array' AND jsonb_array_length(${t.path}) > 0`,\n ),\n check(\n \"revision_embeddings_source_check\",\n sql`${t.sourceRevisionId} <> ${t.revisionId}`,\n ),\n index(\"revision_embeddings_source_index\").on(t.sourceRevisionId),\n ],\n);\n\nexport const revisionReceiptRoleEnum = pgEnum(\"revision_receipt_role\", [\n \"activity\",\n \"object\",\n]);\n/** Mutable index of delivery evidence, not part of immutable document history. */\nexport const revisionReceipts = pgTable(\n \"revision_receipts\",\n {\n deliveryId: uuid(\"delivery_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => activityDeliveries.id, { onDelete: \"cascade\" }),\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n role: revisionReceiptRoleEnum().notNull(),\n },\n (t) => [\n primaryKey({ columns: [t.deliveryId, t.revisionId, t.role] }),\n index(\"revision_receipts_revision_index\").on(t.revisionId),\n ],\n);\n\nexport type ResourceRevision = typeof resourceRevisions.$inferSelect;\nexport type NewResourceRevision = typeof resourceRevisions.$inferInsert;\nexport type ResourceHead = typeof resourceHeads.$inferSelect;\nexport type RevisionAddressing = typeof revisionAddressing.$inferSelect;\nexport type RevisionRelation = typeof revisionRelations.$inferSelect;\nexport type RevisionReceipt = typeof revisionReceipts.$inferSelect;\nexport type RevisionEmbedding = typeof revisionEmbeddings.$inferSelect;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,UAAU,WAA2D;CACzE,gBAAgB;CAChB,aAAa,UAAU,SAAS,QAAQ,KAAK,KAAK;CAClD,SAAS,OAAkC;EAEzC,IAAI,OAAO,UAAU,UAAU,OAAO;EACtC,IAAI,iBAAiB,SAAS,SAAS,OAAO,MAAM,SAAS;EAC7D,MAAM,IAAI,UACR,2DACF;CACF;AACF,CAAC;AAED,MAAM,mBAAmB,GAAG;;;;AAK5B,MAAa,WAAW,QACtB,YACA;CACE,IAAI,KAAK,CAAC,CAAC,MAAY,CAAC,CAAC,WAAW;CACpC,OAAO,QAAQ,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO;CACjD,MAAM,QAAQ,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ;CACvC,cAAc,QAAQ,eAAe,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE;CAC3D,OAAO,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,KAAK;CACxC,SAAS,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,gBAAgB;AACvD,IACC,UAAU;CACT,MACE,wBACA,GAAG,GAAG,MAAM,MAAM,2BACpB;CACA,MAAM,gCAAgC,GAAG,GAAG,MAAM,aAAa,MAAM;CACrE,MAAM,uBAAuB,GAAG,kBAAkB,MAAM,KAAK,QAAQ;AACvE,CACF;;;;AAQA,MAAa,YAAY,QAAQ,aAAa;CAC5C,IAAI,KAAK,CAAC,CAAC,MAAY,CAAC,CAAC,WAAW;CACpC,SAAS,KAAK,UAAU,CAAC,CACtB,MAAY,CAAC,CACb,iBAAiB,eAAe,IAAI,EACnC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AAQ;CACnE,UAAU,8BAA8B,CAAC,CAAC,QAAQ;AACpD,IACC,MAAM;CACL,WAAW,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;CAC9C,WAAW;EACT,MAAM;EACN,SAAS,CAAC,EAAE,gBAAgB;EAC5B,gBAAgB,CAAC,kBAAkB,EAAE;CACvC,CAAC,CAAC,CAAC,SAAS,UAAU;CACtB,MACE,kCACA,GAAG,gBAAgB,EAAE,KAAK,qCAAqC,EAAE,KAAK,MACxE;CACA,MACE,oCACA,GAAG,GAAG,EAAE,iBAAiB,MAAM,EAAE,YACnC;CACA,MAAM,kCAAkC,CAAC,CAAC,GAAG,EAAE,gBAAgB;AACjE,CACF;AAEA,MAAa,0BAA0B,OAAO,yBAAyB,CACrE,YACA,QACF,CAAC;;AAED,MAAa,mBAAmB,QAC9B,qBACA;CACE,YAAY,KAAK,aAAa,CAAC,CAC5B,MAAY,CAAC,CACb,QAAQ,CAAC,CACT,iBAAiB,mBAAmB,IAAI,EAAE,UAAU,UAAU,CAAC;CAClE,YAAY,KAAK,aAAa,CAAC,CAC5B,MAAY,CAAC,CACb,QAAQ,CAAC,CACT,iBAAiB,kBAAkB,IAAI,EAAE,UAAU,WAAW,CAAC;CAClE,MAAM,wBAAwB,CAAC,CAAC,QAAQ;AAC1C,IACC,MAAM,CACL,WAAW,EAAE,SAAS;CAAC,EAAE;CAAY,EAAE;CAAY,EAAE;AAAI,EAAE,CAAC,GAC5D,MAAM,kCAAkC,CAAC,CAAC,GAAG,EAAE,UAAU,CAC3D,CACF"}
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport type { webcrypto } from \"node:crypto\";\n\nimport { desc, sql } from \"drizzle-orm\";\nimport {\n type AnyPgColumn,\n boolean,\n bytea,\n char,\n check,\n customType,\n foreignKey,\n index,\n integer,\n json,\n jsonb,\n pgEnum,\n pgTable,\n primaryKey,\n text,\n unique,\n uniqueIndex,\n uuid,\n varchar,\n} from \"drizzle-orm/pg-core\";\n\nimport type { PublicJwk } from \"./key.ts\";\nimport type { Uuid } from \"./uuid.ts\";\n\n/** A timestamptz column preserving PostgreSQL's microsecond precision. */\nconst instant = customType<{ data: Temporal.Instant; driverData: string }>({\n dataType: () => \"timestamp with time zone\",\n fromDriver: (value) => Temporal.Instant.from(value),\n toDriver(value: Temporal.Instant | string) {\n // Pothos composite cursors decode timestamps as strings.\n if (typeof value === \"string\") return value;\n if (value instanceof Temporal.Instant) return value.toString();\n throw new TypeError(\n \"Expected a Temporal.Instant or a cursor timestamp string.\",\n );\n },\n});\n\nconst currentTimestamp = sql`CURRENT_TIMESTAMP`;\n\n/**\n * The database table to represent accounts.\n */\nexport const accounts = pgTable(\n \"accounts\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n email: varchar({ length: 255 }).notNull().unique(),\n name: varchar({ length: 100 }).notNull(),\n maxInstances: integer(\"max_instances\").notNull().default(10),\n admin: boolean().notNull().default(false),\n created: instant().notNull().default(currentTimestamp),\n },\n (table) => [\n check(\n \"accounts_email_check\",\n sql`${table.email} ~ '^[^@]+@[^@]+\\\\.[^@]+$'`,\n ),\n check(\"accounts_max_instances_check\", sql`${table.maxInstances} >= 0`),\n check(\"accounts_name_check\", sql`trim(both from ${table.name}) <> ''`),\n ],\n);\n\nexport type Account = typeof accounts.$inferSelect;\nexport type NewAccount = typeof accounts.$inferInsert;\n\n/**\n * The database table to represent instances.\n */\nexport const instances = pgTable(\"instances\", {\n id: uuid().$type<Uuid>().primaryKey(),\n localId: uuid(\"local_id\")\n .$type<Uuid>()\n .references(() => localInstances.id, {\n onDelete: \"cascade\",\n }),\n created: instant().notNull().default(currentTimestamp),\n // The authority an instance is federated under, which is what Fedify's\n // `Context.host` reports and therefore what dispatchers look instances up\n // by. That is a DNS name, at most 253 octets, plus a `:port` suffix of up\n // to 6 more characters when the deployment is not on the scheme's default\n // port. Both locally composed `<slug>.<root domain>` names and remote\n // hosts discovered from the fediverse live here.\n host: varchar({ length: 259 }).notNull().unique(),\n nodeInfoUrl: text(\"node_info_url\"),\n software: text(),\n softwareVersion: text(\"software_version\"),\n});\n\nexport type Instance = typeof instances.$inferSelect;\nexport type NewInstance = typeof instances.$inferInsert;\n\nexport const localInstances = pgTable(\n \"local_instances\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n slug: varchar({ length: 63 }).notNull().unique(),\n expires: instant().notNull(),\n maxActors: integer(\"max_actors\").notNull().default(10),\n },\n (table) => [\n // Keep this in agreement with `isValidSlug()` in ./slug.ts. A slug\n // becomes the leftmost label of the instance's host name, so it has to be\n // a valid DNS label: no leading or trailing hyphen, and none of RFC 5891's\n // reserved LDH labels except the `xn--` prefix of an A-label, which stays\n // allowed so that instances can carry internationalized domain names.\n check(\n \"local_instances_slug_check\",\n sql`${table.slug} ~ '^[a-z0-9][a-z0-9-]{2,61}[a-z0-9]$'\n AND (${table.slug} !~ '^..--' OR ${table.slug} ~ '^xn--')`,\n ),\n check(\"instances_max_actors_check\", sql`${table.maxActors} > 0`),\n ],\n);\n\nexport type LocalInstance = typeof localInstances.$inferSelect;\nexport type NewLocalInstance = typeof localInstances.$inferInsert;\n\n/**\n * The association table between instances and its member accounts.\n * Note that it also contains the just invited members, which are not yet\n * accepted. The `accepted` field is `NULL` for those members.\n */\nexport const instanceMembers = pgTable(\n \"instance_members\",\n {\n accountId: uuid(\"account_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => accounts.id),\n instanceId: uuid(\"instance_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => instances.id),\n admin: boolean().notNull().default(false),\n accepted: instant(),\n created: instant().notNull().default(currentTimestamp),\n },\n (table) => [\n primaryKey({ columns: [table.instanceId, table.accountId] }),\n index()\n .on(table.accountId)\n .where(sql`${table.accepted} IS NOT NULL`),\n index()\n .on(table.instanceId)\n .where(sql`${table.accepted} IS NOT NULL`),\n ],\n);\n\nexport type InstanceMember = typeof instanceMembers.$inferSelect;\nexport type NewInstanceMember = typeof instanceMembers.$inferInsert;\n\n/** The length of an email login verification code. */\nexport const LOGIN_CHALLENGE_CODE_LENGTH = 6;\n\n/**\n * Email login challenges identified by a public UUID and verified by a\n * plaintext code. Each challenge expires after 15 minutes and is single-use.\n */\nexport const loginChallenges = pgTable(\"login_challenges\", {\n id: uuid().$type<Uuid>().primaryKey(),\n accountId: uuid(\"account_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => accounts.id, { onDelete: \"cascade\" }),\n code: char({ length: LOGIN_CHALLENGE_CODE_LENGTH }).notNull(),\n created: instant().notNull().default(currentTimestamp),\n expires: instant()\n .notNull()\n .default(sql`CURRENT_TIMESTAMP + INTERVAL '15 minutes'`),\n consumed: instant(),\n});\n\nexport type LoginChallenge = typeof loginChallenges.$inferSelect;\nexport type NewLoginChallenge = typeof loginChallenges.$inferInsert;\n\n/**\n * Authenticated sessions. The `id` field is used to revoke a session, and\n * the `tokenHash` is the hash of the bearer access token.\n */\nexport const sessions = pgTable(\"sessions\", {\n id: uuid().$type<Uuid>().primaryKey(),\n accountId: uuid(\"account_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => accounts.id, { onDelete: \"cascade\" }),\n tokenHash: varchar(\"token_hash\", { length: 64 }).notNull().unique(),\n created: instant().notNull().default(currentTimestamp),\n expires: instant()\n .notNull()\n .default(sql`CURRENT_TIMESTAMP + INTERVAL '1 month'`),\n});\n\nexport type Session = typeof sessions.$inferSelect;\nexport type NewSession = typeof sessions.$inferInsert;\n\nexport const actorTypeEnum = pgEnum(\"actor_type\", [\n \"Application\",\n \"Group\",\n \"Organization\",\n \"Person\",\n \"Service\",\n]);\n\nexport type ActorType = (typeof actorTypeEnum.enumValues)[number];\n\nexport const resourceKindEnum = pgEnum(\"resource_kind\", [\n \"actor\",\n \"object\",\n \"activity\",\n \"collection\",\n \"unknown\",\n]);\n\n/**\n * Canonical IRI registry. Retained revisions keep their resource identity\n * even after a current typed row is deleted. Other references may also\n * intentionally restrict physical removal of the resource.\n */\nexport const resources = pgTable(\"resources\", {\n id: uuid().$type<Uuid>().primaryKey(),\n iri: text().notNull().unique(),\n kind: resourceKindEnum().notNull(),\n created: instant().notNull().default(currentTimestamp),\n});\nexport type Resource = typeof resources.$inferSelect;\n\nexport const actors = pgTable(\n \"actors\",\n {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n localId: uuid(\"local_id\")\n .$type<Uuid>()\n .unique()\n .references(() => localActors.id, { onDelete: \"cascade\" }),\n type: actorTypeEnum().notNull(),\n /**\n * A local actor's handle username; a remote actor's `preferredUsername`\n * as received, which ActivityPub neither requires nor makes unique.\n */\n username: text(),\n instanceId: uuid(\"instance_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => instances.id, { onDelete: \"cascade\" }),\n document: json(),\n inboxUrl: text(\"inbox_url\").notNull(),\n /**\n * The IRI of the followers collection a remote actor declares, as\n * received. It is never fetched, so it is no `collections` row: what the\n * collection is and holds is unknown.\n */\n followersUrl: text(\"followers_url\"),\n profileUrl: text(\"profile_url\"),\n avatarUrl: text(\"avatar_url\"),\n headerUrl: text(\"header_url\"),\n name: text(),\n bioHtml: text(\"bio_html\"),\n automaticallyApprovesFollowers: boolean(\"automatically_approves_followers\")\n .notNull()\n .default(false),\n fieldHtmls: jsonb(\"field_htmls\")\n .$type<Record<string, string>>()\n .notNull()\n .default({}),\n emojis: jsonb().$type<Record<string, string>>().notNull().default({}),\n tags: jsonb().$type<Record<string, string>>().notNull().default({}),\n sensitive: boolean().notNull().default(false),\n // Moderation sanction state, denormalized from flag_action records\n // (which remain the audit source of truth):\n // - Not sanctioned: suspended IS NULL\n // - Temporary suspension: suspended = start, suspendedUntil = end\n // - Permanent suspension (ban) for local actors, or permanent federation\n // block for remote actors: suspended set, suspendedUntil IS NULL\n // Whether a sanction is *currently* active is always determined by\n // comparing against the current time (lazy expiry; no cron):\n // Temporal.Instant.compare(suspended, now) <= 0 AND (suspendedUntil IS NULL OR Temporal.Instant.compare(suspendedUntil, now) > 0).\n suspended: instant(),\n suspendedUntil: instant(\"suspended_until\"),\n successorId: uuid(\"successor_id\")\n .$type<Uuid>()\n .references((): AnyPgColumn => actors.id, {\n onDelete: \"set null\",\n }),\n aliases: text()\n .array()\n .notNull()\n .default(sql`(ARRAY[]::text[])`),\n followingCount: integer(\"following_count\").notNull().default(0),\n followersCount: integer(\"followers_count\").notNull().default(0),\n updated: instant()\n .notNull()\n .default(currentTimestamp)\n .$onUpdate(() => currentTimestamp),\n published: instant(),\n created: instant().notNull().default(currentTimestamp),\n // When implementing actor deletion, add activities.deleted and set it\n // together with objects.deleted in the same transaction.\n // FIXME: https://github.com/fedify-dev/drfed/issues/89\n deleted: instant(),\n },\n (t) => [\n uniqueIndex(\"username_key\")\n .on(t.username, t.instanceId)\n .where(sql`${t.localId} IS NOT NULL`),\n check(\n \"actors_username_check\",\n sql`${t.localId} IS NULL OR ${t.username} NOT LIKE '%@%'`,\n ),\n check(\n \"actors_local_username_check\",\n sql`${t.localId} IS NULL OR ${t.username} IS NOT NULL`,\n ),\n check(\n \"actors_suspended_check\",\n sql`\n ${t.suspendedUntil} IS NULL OR (\n ${t.suspended} IS NOT NULL AND\n ${t.suspendedUntil} > ${t.suspended}\n )\n `,\n ),\n index(\"actor_instance_index\").on(t.instanceId),\n ],\n);\n\nexport type Actor = typeof actors.$inferSelect;\nexport type NewActor = typeof actors.$inferInsert;\n\nexport const localActors = pgTable(\"local_actors\", {\n id: uuid().$type<Uuid>().primaryKey(),\n avatar: text(),\n header: text(),\n});\n\nexport type LocalActor = typeof localActors.$inferSelect;\nexport type NewLocalActor = typeof localActors.$inferInsert;\n\n/** Signing algorithms available to local actors. */\nexport const localActorKeyTypeEnum = pgEnum(\"local_actor_key_type\", [\n \"RSASSA-PKCS1-v1_5\",\n \"Ed25519\",\n]);\nexport type LocalActorKeyType =\n (typeof localActorKeyTypeEnum.enumValues)[number];\n/** Private signing material; never expose this table through GraphQL. */\nexport const localActorKeys = pgTable(\n \"local_actor_keys\",\n {\n localActorId: uuid(\"local_actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => localActors.id, { onDelete: \"cascade\" }),\n type: localActorKeyTypeEnum().notNull(),\n publicKey: jsonb(\"public_key\").$type<PublicJwk>().notNull(),\n privateKey: jsonb(\"private_key\").$type<webcrypto.JsonWebKey>().notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.localActorId, table.type] }),\n check(\n \"local_actor_keys_public_key_check\",\n sql`jsonb_typeof(${table.publicKey}) = 'object' AND NOT (${table.publicKey} ?| array['d','p','q','dp','dq','qi','oth','k'])`,\n ),\n ],\n);\nexport type LocalActorKey = typeof localActorKeys.$inferSelect;\nexport type NewLocalActorKey = typeof localActorKeys.$inferInsert;\n\nexport const objectTypeEnum = pgEnum(\"object_type\", [\"Article\", \"Note\"]);\nexport type ObjectType = (typeof objectTypeEnum.enumValues)[number];\n/** ActivityPub objects authored by actors. */\nexport const objects = pgTable(\n \"objects\",\n {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n /**\n * The activity that carried the stored snapshot. Who may read a remote\n * object follows it, not the activities that refer to the object later\n * with another version of it.\n */\n activityId: uuid(\"activity_id\")\n .$type<Uuid>()\n .references(() => resources.id, { onDelete: \"set null\" }),\n /**\n * Whether `document` was fetched from the object's IRI rather than taken\n * from the activity that carried it, which then proves nothing of it.\n */\n fetched: boolean().notNull().default(false),\n type: objectTypeEnum().notNull(),\n document: json(),\n url: text(),\n name: text(),\n summary: text(),\n contentHtml: text(\"content_html\").notNull(),\n language: varchar({ length: 35 }),\n sensitive: boolean().notNull().default(false),\n published: instant().notNull().default(currentTimestamp),\n updated: instant()\n .notNull()\n .default(currentTimestamp)\n .$onUpdate(() => currentTimestamp),\n created: instant().notNull().default(currentTimestamp),\n deleted: instant(),\n },\n (t) => [\n check(\n \"objects_content_html_check\",\n sql`trim(both from ${t.contentHtml}) <> ''`,\n ),\n unique(\"objects_activity_id_key\").on(t.activityId),\n index(\"object_actor_published_index\").on(\n t.actorId,\n desc(t.published),\n desc(t.id),\n ),\n ],\n);\nexport type ActivityPubObject = typeof objects.$inferSelect;\nexport type NewActivityPubObject = typeof objects.$inferInsert;\n\nexport const collectionTypeEnum = pgEnum(\"collection_type\", [\n \"Collection\",\n \"OrderedCollection\",\n]);\nexport const collectionRoleEnum = pgEnum(\"collection_role\", [\n \"followers\",\n \"following\",\n \"featured\",\n \"outbox\",\n]);\nexport type CollectionRole = (typeof collectionRoleEnum.enumValues)[number];\nexport const collections = pgTable(\"collections\", {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n type: collectionTypeEnum().notNull(),\n /**\n * Lifecycle owner of a locally managed collection. Physical deletion of\n * the owner cascades to the collection and all references. Soft deletion\n * hides the collection and every actor's reference to it from GraphQL.\n */\n ownerActorId: uuid(\"owner_actor_id\")\n .$type<Uuid>()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n totalItems: integer(\"total_items\"),\n document: json(),\n updated: instant()\n .notNull()\n .default(currentTimestamp)\n .$onUpdate(() => currentTimestamp),\n});\nexport type Collection = typeof collections.$inferSelect;\n\n/** Actor-declared collection roles; a collection may be shared across roles or actors. */\nexport const actorCollectionReferences = pgTable(\n \"actor_collection_references\",\n {\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n role: collectionRoleEnum().notNull(),\n collectionId: uuid(\"collection_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => collections.id, { onDelete: \"cascade\" }),\n },\n (t) => [\n primaryKey({ columns: [t.actorId, t.role] }),\n index(\"actor_collection_reference_collection_index\").on(t.collectionId),\n ],\n);\n\nexport const collectionItems = pgTable(\n \"collection_items\",\n {\n collectionId: uuid(\"collection_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => collections.id, { onDelete: \"cascade\" }),\n itemId: uuid(\"item_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n position: integer(),\n observed: instant().notNull().default(currentTimestamp),\n },\n (t) => [\n primaryKey({ columns: [t.collectionId, t.itemId] }),\n index(\"collection_item_position_index\").on(t.collectionId, t.position),\n ],\n);\n\nexport const activityTypeEnum = pgEnum(\"activity_type\", [\"Create\"]);\nexport const activities = pgTable(\n \"activities\",\n {\n id: uuid()\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n type: activityTypeEnum().notNull(),\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n objectId: uuid(\"object_id\")\n .$type<Uuid>()\n .references(() => resources.id, { onDelete: \"set null\" }),\n published: instant().notNull(),\n document: json(),\n created: instant().notNull().default(currentTimestamp),\n },\n (t) => [\n index(\"activity_actor_published_index\").on(\n t.actorId,\n desc(t.published),\n desc(t.id),\n ),\n index(\"activity_object_published_index\").on(t.objectId, t.published, t.id),\n ],\n);\nexport type StoredActivity = typeof activities.$inferSelect;\n\nexport const addressingPropertyEnum = pgEnum(\"addressing_property\", [\n \"to\",\n \"cc\",\n \"bto\",\n \"bcc\",\n \"audience\",\n]);\nexport type AddressingProperty =\n (typeof addressingPropertyEnum.enumValues)[number];\nexport const addressing = pgTable(\n \"addressing\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n sourceId: uuid(\"source_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"cascade\" }),\n property: addressingPropertyEnum().notNull(),\n position: integer().notNull(),\n targetId: uuid(\"target_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"restrict\" }),\n },\n (t) => [\n unique(\"addressing_source_property_position_key\").on(\n t.sourceId,\n t.property,\n t.position,\n ),\n index(\"addressing_target_property_index\").on(t.targetId, t.property),\n ],\n);\nexport type Addressing = typeof addressing.$inferSelect;\n\n/** Direction of an observed delivery. */\nexport const activityDeliveryDirectionEnum = pgEnum(\n \"activity_delivery_direction\",\n [\"inbound\", \"outbound\"],\n);\n\n/**\n * Inbound: `received` (2xx, listener ran), `acknowledged` (2xx, listener did\n * not run), `unverified`, `rejected` (refused although verified); a request\n * whose handling threw is one of the last two, without a status code. Outbound:\n * `queued` (no attempt ended yet), `sent`, `failed` (the latest attempt\n * failed; a queued delivery may be retried), `permanently_failed`,\n * `abandoned` (the retry policy ran out).\n */\nexport const activityDeliveryStatusEnum = pgEnum(\"activity_delivery_status\", [\n \"received\",\n \"acknowledged\",\n \"unverified\",\n \"rejected\",\n \"queued\",\n \"sent\",\n \"failed\",\n \"permanently_failed\",\n \"abandoned\",\n]);\n\n/** The mechanism that authenticated an inbound activity. */\nexport const activityDeliveryVerificationMechanismEnum = pgEnum(\n \"activity_delivery_verification_mechanism\",\n [\"http_signature\", \"ld_signature\", \"object_integrity_proof\"],\n);\n\n/**\n * What Fedify reported of an inbound verification; `unattempted` when it\n * answered before verifying, and `unobserved` when recording failed.\n */\nexport const activityDeliveryVerificationResultEnum = pgEnum(\n \"activity_delivery_verification_result\",\n [\n \"verified\",\n \"invalid_signature\",\n \"key_fetch_error\",\n \"no_signature\",\n \"unattempted\",\n \"unobserved\",\n ],\n);\n\n/** Logical public keys, identified by their exact IRI. */\nexport const keys = pgTable(\"keys\", {\n id: uuid().$type<Uuid>().primaryKey(),\n iri: text().notNull().unique(),\n created: instant().notNull().default(currentTimestamp),\n});\n\n/** Immutable key material, independently retained from Fedify's KV cache. */\nexport const keyVersions = pgTable(\n \"key_versions\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n keyId: uuid(\"key_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => keys.id, { onDelete: \"restrict\" }),\n publicKey: jsonb(\"public_key\").$type<PublicJwk>().notNull(),\n fingerprint: text().notNull(),\n /** DrFed observation time, not remote rotation time or evidence of continuous use. */\n firstSeen: instant(\"first_seen\").notNull(),\n /** DrFed observation time, not remote rotation time or evidence of continuous use. */\n lastSeen: instant(\"last_seen\").notNull(),\n },\n (table) => [\n unique(\"key_versions_key_id_fingerprint_unique\").on(\n table.keyId,\n table.fingerprint,\n ),\n check(\n \"key_versions_seen_check\",\n sql`${table.lastSeen} >= ${table.firstSeen}`,\n ),\n check(\n \"key_versions_public_key_check\",\n sql`NOT (${table.publicKey} ?| array['d','p','q','dp','dq','qi','oth','k'])`,\n ),\n index(\"key_version_key_first_seen_index\").on(\n table.keyId,\n table.firstSeen,\n table.id,\n ),\n ],\n);\n\n/** Delivery observations; payloads may contain unverified, private remote input. */\nexport const activityDeliveries = pgTable(\n \"activity_deliveries\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n instanceId: uuid(\"instance_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => instances.id, { onDelete: \"cascade\" }),\n /** The owner of the inbox the request arrived at, or the sending actor. */\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .references(() => actors.id, { onDelete: \"set null\" }),\n direction: activityDeliveryDirectionEnum().notNull(),\n status: activityDeliveryStatusEnum().notNull(),\n verificationMechanism: activityDeliveryVerificationMechanismEnum(\n \"verification_mechanism\",\n ),\n verificationResult: activityDeliveryVerificationResultEnum(\n \"verification_result\",\n ),\n type: text(),\n types: text()\n .array()\n .notNull()\n .default(sql`'{}'`),\n activityIri: text(\"activity_iri\"),\n /**\n * The stored activity `activityIri` names: for an inbound delivery, only\n * one Fedify verified and accepted. The database enforces the latter;\n * `linkInboundActivity()` matches the IRI.\n */\n activityId: uuid(\"activity_id\")\n .$type<Uuid>()\n .references(() => activities.id, { onDelete: \"set null\" }),\n /**\n * Whether an inbound delivery carried the stored activity as it is, not\n * only its IRI. `linkInboundActivity()` decides it, and only such a\n * delivery opens the activity to its instance.\n */\n carriedSnapshot: boolean(\"carried_snapshot\").notNull().default(false),\n /**\n * The object an inbound delivery's inbox listener fetched from its IRI,\n * when it had to.\n */\n fetchedObject: jsonb(\"fetched_object\").$type<unknown>(),\n /**\n * Whether an inbound delivery carried the object stored with its activity\n * as it is: the activity carried it, or the delivery fetched it as stored.\n * `linkInboundActivity()` decides it, and only such a delivery opens the\n * object to its instance.\n */\n carriedObjectSnapshot: boolean(\"carried_object_snapshot\")\n .notNull()\n .default(false),\n objectType: text(\"object_type\"),\n objectIri: text(\"object_iri\"),\n signedKeyIri: text(\"signed_key_iri\"),\n /** A referenced version does not imply successful verification. */\n verificationKeyId: uuid(\"verification_key_id\")\n .$type<Uuid>()\n .references(() => keyVersions.id, { onDelete: \"restrict\" }),\n /** Inbound, only the first `actor`; the rest are in `payload`. */\n remoteActorIri: text(\"remote_actor_iri\"),\n remoteHost: text(\"remote_host\"),\n inboxUrl: text(\"inbox_url\").notNull(),\n requestUrl: text(\"request_url\"),\n /** Names are lowercase; original order and case are not kept. */\n headers: jsonb().$type<readonly (readonly [string, string])[]>(),\n body: bytea(),\n statusCode: integer(\"status_code\"),\n responseBody: text(\"response_body\"),\n error: text(),\n payload: jsonb().$type<unknown>(),\n recipientIris: text(\"recipient_iris\")\n .array()\n .notNull()\n .default(sql`'{}'`),\n /** Inbound, when the request arrived; outbound, when delivery started. */\n created: instant().notNull().default(currentTimestamp),\n /** Inbound, when DrFed answered; outbound, the latest status change. */\n completed: instant(),\n },\n (table) => [\n check(\n \"activity_deliveries_direction_status_check\",\n sql`(${table.direction} = 'inbound' AND ${table.status} IN ('received', 'acknowledged', 'unverified', 'rejected')) OR (${table.direction} = 'outbound' AND ${table.status} IN ('queued', 'sent', 'failed', 'permanently_failed', 'abandoned'))`,\n ),\n check(\n \"activity_deliveries_completed_check\",\n sql`(${table.completed} IS NULL) = (${table.status} = 'queued')`,\n ),\n check(\n \"activity_deliveries_status_code_check\",\n sql`${table.statusCode} IS NULL OR ${table.statusCode} BETWEEN 100 AND 599`,\n ),\n check(\n \"activity_deliveries_outbound_key_check\",\n sql`${table.direction} <> 'outbound' OR ${table.verificationKeyId} IS NULL`,\n ),\n check(\n \"activity_deliveries_verification_result_check\",\n sql`(${table.direction} = 'inbound') = (${table.verificationResult} IS NOT NULL)`,\n ),\n check(\n \"activity_deliveries_verification_mechanism_check\",\n sql`${table.verificationMechanism} IS NULL OR (${table.direction} = 'inbound' AND ${table.verificationResult} NOT IN ('unattempted', 'unobserved'))`,\n ),\n check(\n \"activity_deliveries_body_check\",\n sql`(${table.direction} = 'inbound') = (${table.body} IS NOT NULL)`,\n ),\n check(\n \"activity_deliveries_activity_check\",\n sql`${table.activityId} IS NULL OR ${table.direction} = 'outbound' OR (${table.verificationResult} = 'verified' AND ${table.status} IN ('received', 'acknowledged'))`,\n ),\n index(\"activity_delivery_instance_created_index\").on(\n table.instanceId,\n desc(table.created),\n desc(table.id),\n ),\n index(\"activity_delivery_actor_index\").on(table.actorId),\n index(\"activity_delivery_activity_created_index\").on(\n table.activityId,\n desc(table.created),\n desc(table.id),\n ),\n index(\"activity_delivery_verification_key_index\").on(\n table.verificationKeyId,\n ),\n index(\"activity_delivery_outbound_index\")\n .on(table.activityIri, table.inboxUrl)\n .where(sql`${table.direction} = 'outbound'`),\n ],\n);\n\n/** Each ended attempt of an outbound delivery. */\nexport const activityDeliveryAttempts = pgTable(\n \"activity_delivery_attempts\",\n {\n id: uuid().$type<Uuid>().primaryKey(),\n deliveryId: uuid(\"delivery_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => activityDeliveries.id, { onDelete: \"cascade\" }),\n succeeded: boolean().notNull(),\n statusCode: integer(\"status_code\"),\n responseBody: text(\"response_body\"),\n error: text(),\n /** When the attempt ended. */\n created: instant().notNull().default(currentTimestamp),\n },\n (table) => [\n check(\n \"activity_delivery_attempts_status_code_check\",\n sql`${table.statusCode} IS NULL OR ${table.statusCode} BETWEEN 100 AND 599`,\n ),\n check(\n \"activity_delivery_attempts_error_check\",\n sql`${table.succeeded} = (${table.error} IS NULL)`,\n ),\n index(\"activity_delivery_attempt_delivery_index\").on(\n table.deliveryId,\n table.created,\n table.id,\n ),\n ],\n);\n\n/**\n * The local actors a delivery concerns, one row per delivery and actor; each\n * must be a local actor of the delivery's instance, which the record functions\n * check.\n */\nexport const activityDeliveryActors = pgTable(\n \"activity_delivery_actors\",\n {\n deliveryId: uuid(\"delivery_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => activityDeliveries.id, { onDelete: \"cascade\" }),\n actorId: uuid(\"actor_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => actors.id, { onDelete: \"cascade\" }),\n inboxOwner: boolean(\"inbox_owner\").notNull().default(false),\n /** Addressed directly or through a collection. */\n addressed: boolean().notNull().default(false),\n /** Addressed by its own IRI; collections are in a row each. */\n addressedDirectly: boolean(\"addressed_directly\").notNull().default(false),\n sender: boolean().notNull().default(false),\n /** The delivery's `created`, which an actor's deliveries are ordered by. */\n created: instant().notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.deliveryId, table.actorId] }),\n check(\n \"activity_delivery_actors_role_check\",\n sql`${table.inboxOwner} OR ${table.addressed} OR ${table.sender}`,\n ),\n check(\n \"activity_delivery_actors_addressed_directly_check\",\n sql`NOT ${table.addressedDirectly} OR ${table.addressed}`,\n ),\n index(\"activity_delivery_actor_created_index\").on(\n table.actorId,\n desc(table.created),\n desc(table.deliveryId),\n ),\n ],\n);\n\n/** Each addressed collection a delivery reached a local actor through. */\nexport const activityDeliveryActorCollections = pgTable(\n \"activity_delivery_actor_collections\",\n {\n deliveryId: uuid(\"delivery_id\").$type<Uuid>().notNull(),\n actorId: uuid(\"actor_id\").$type<Uuid>().notNull(),\n collectionIri: text(\"collection_iri\").notNull(),\n },\n (table) => [\n primaryKey({\n columns: [table.deliveryId, table.actorId, table.collectionIri],\n }),\n foreignKey({\n name: \"activity_delivery_actor_collections_link_fkey\",\n columns: [table.deliveryId, table.actorId],\n foreignColumns: [\n activityDeliveryActors.deliveryId,\n activityDeliveryActors.actorId,\n ],\n }).onDelete(\"cascade\"),\n ],\n);\nexport type Key = typeof keys.$inferSelect;\nexport type KeyVersion = typeof keyVersions.$inferSelect;\nexport type ActivityDelivery = typeof activityDeliveries.$inferSelect;\nexport type NewActivityDelivery = typeof activityDeliveries.$inferInsert;\nexport type ActivityDeliveryAttempt =\n typeof activityDeliveryAttempts.$inferSelect;\nexport type ActivityDeliveryActor = typeof activityDeliveryActors.$inferSelect;\nexport type NewActivityDeliveryActor =\n typeof activityDeliveryActors.$inferInsert;\nexport type ActivityDeliveryActorCollection =\n typeof activityDeliveryActorCollections.$inferSelect;\nexport type ActivityDeliveryDirection =\n (typeof activityDeliveryDirectionEnum.enumValues)[number];\nexport type ActivityDeliveryStatus =\n (typeof activityDeliveryStatusEnum.enumValues)[number];\nexport type ActivityDeliveryVerificationMechanism =\n (typeof activityDeliveryVerificationMechanismEnum.enumValues)[number];\nexport type ActivityDeliveryVerificationResult =\n (typeof activityDeliveryVerificationResultEnum.enumValues)[number];\n\nexport const resourceRevisionKindEnum = pgEnum(\"resource_revision_kind\", [\n \"snapshot\",\n \"unavailable\",\n \"whiteout\",\n]);\nexport const resourceRevisionCaptureEnum = pgEnum(\"resource_revision_capture\", [\n \"local\",\n \"received\",\n \"embedded\",\n \"fetched\",\n]);\nexport const resourceRevisionProjectionEnum = pgEnum(\n \"resource_revision_projection\",\n [\"partial\", \"complete\"],\n);\n\n/** Immutable parsed documents, independently of current typed rows. */\nexport const resourceRevisions = pgTable(\n \"resource_revisions\",\n {\n id: uuid().$type<Uuid>().primaryKey().defaultRandom(),\n resourceId: uuid(\"resource_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resources.id, { onDelete: \"restrict\" }),\n sequence: integer().notNull(),\n kind: resourceRevisionKindEnum().notNull(),\n capture: resourceRevisionCaptureEnum().notNull(),\n backfilled: boolean().notNull().default(false),\n document: json(),\n formerTypes: text(\"former_types\").array(),\n deleted: instant(),\n projection: resourceRevisionProjectionEnum().notNull().default(\"partial\"),\n created: instant().notNull().default(currentTimestamp),\n },\n (t) => [\n unique(\"resource_revisions_resource_sequence_key\").on(\n t.resourceId,\n t.sequence,\n ),\n unique(\"resource_revisions_resource_id_key\").on(t.resourceId, t.id),\n check(\"resource_revisions_sequence_check\", sql`${t.sequence} > 0`),\n check(\n \"resource_revisions_document_check\",\n sql`(${t.kind} = 'snapshot' AND ${t.document} IS NOT NULL)\n OR (${t.kind} IN ('unavailable', 'whiteout') AND ${t.document} IS NULL)`,\n ),\n check(\n \"resource_revisions_deletion_check\",\n sql`(${t.kind} = 'whiteout' AND ${t.deleted} IS NOT NULL AND ${t.formerTypes} IS NOT NULL)\n OR (${t.kind} <> 'whiteout' AND ${t.deleted} IS NULL AND ${t.formerTypes} IS NULL)`,\n ),\n ],\n);\n\n/** The current revision of one canonical resource. */\nexport const resourceHeads = pgTable(\n \"resource_heads\",\n {\n resourceId: uuid(\"resource_id\")\n .$type<Uuid>()\n .primaryKey()\n .references(() => resources.id, { onDelete: \"restrict\" }),\n revisionId: uuid(\"revision_id\").$type<Uuid>().notNull(),\n },\n (t) => [\n foreignKey({\n name: \"resource_heads_resource_revision_fkey\",\n columns: [t.resourceId, t.revisionId],\n foreignColumns: [resourceRevisions.resourceId, resourceRevisions.id],\n }).onDelete(\"restrict\"),\n ],\n);\n\n/** Root addressing occurrences, including blind recipients and duplicates. */\nexport const revisionAddressing = pgTable(\n \"revision_addressing\",\n {\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n property: addressingPropertyEnum().notNull(),\n position: integer().notNull(),\n iri: text().notNull(),\n },\n (t) => [\n primaryKey({ columns: [t.revisionId, t.property, t.position] }),\n check(\"revision_addressing_position_check\", sql`${t.position} >= 0`),\n index(\"revision_addressing_iri_property_index\").on(t.iri, t.property),\n ],\n);\n\nexport const revisionRelationRepresentationEnum = pgEnum(\n \"revision_relation_representation\",\n [\"reference\", \"embedded\", \"link\"],\n);\n/** Caller-supplied relation occurrences; the saved JSON remains authoritative. */\nexport const revisionRelations = pgTable(\n \"revision_relations\",\n {\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n occurrence: integer().notNull(),\n property: text().notNull(),\n path: json().$type<readonly (string | number)[]>(),\n representation: revisionRelationRepresentationEnum().notNull(),\n targetIri: text(\"target_iri\"),\n },\n (t) => [\n primaryKey({ columns: [t.revisionId, t.occurrence] }),\n check(\"revision_relations_occurrence_check\", sql`${t.occurrence} >= 0`),\n check(\n \"revision_relations_path_check\",\n sql`${t.path} IS NULL OR json_typeof(${t.path}) = 'array'`,\n ),\n check(\n \"revision_relations_reference_check\",\n sql`${t.representation} <> 'reference' OR ${t.targetIri} IS NOT NULL`,\n ),\n index(\"revision_relations_property_target_index\").on(\n t.property,\n t.targetIri,\n t.revisionId,\n ),\n ],\n);\n\nexport const revisionEmbeddingRelationEnum = pgEnum(\n \"revision_embedding_relation\",\n [\"snapshot\", \"derived\"],\n);\n/**\n * Where an embedded document of a revision came from, recorded when the\n * revision was saved: the revision of another resource whose contents it\n * keeps, apart from the context it inherits, or from which it was derived.\n * An embedded document without a row has an unknown source. Rows are part\n * of the immutable history of their revision.\n */\nexport const revisionEmbeddings = pgTable(\n \"revision_embeddings\",\n {\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n path: jsonb().$type<readonly (string | number)[]>().notNull(),\n sourceRevisionId: uuid(\"source_revision_id\").$type<Uuid>().notNull(),\n relation: revisionEmbeddingRelationEnum().notNull(),\n },\n (t) => [\n primaryKey({ columns: [t.revisionId, t.path] }),\n foreignKey({\n name: \"revision_embeddings_source_revision_fkey\",\n columns: [t.sourceRevisionId],\n foreignColumns: [resourceRevisions.id],\n }).onDelete(\"restrict\"),\n check(\n \"revision_embeddings_path_check\",\n sql`jsonb_typeof(${t.path}) = 'array' AND jsonb_array_length(${t.path}) > 0`,\n ),\n check(\n \"revision_embeddings_source_check\",\n sql`${t.sourceRevisionId} <> ${t.revisionId}`,\n ),\n index(\"revision_embeddings_source_index\").on(t.sourceRevisionId),\n ],\n);\n\nexport const revisionExpansionOutcomeEnum = pgEnum(\n \"revision_expansion_outcome\",\n [\"expanded\", \"failed\", \"no_document\"],\n);\n/**\n * The JSON-LD expanded form of a revision's document, written with the\n * revision. Unlike the other revision projections, rows are derived data: an\n * incorrect expansion is a bug, fixed by recomputing the rows of the affected\n * revisions, so the table has no immutability guard. A revision without a row\n * has not been expanded yet. An object embedded in a received activity is\n * expanded from that activity's document, recorded as `sourceRevisionId`.\n *\n * Unlike revision documents, expanded documents are `jsonb` so that they can\n * be indexed and queried with containment. Being derived, they are stored\n * normalized: U+0000 and unpaired surrogates in strings and keys become\n * U+FFFD, and negative zero becomes zero. The stored document holds the exact\n * values.\n */\nexport const revisionExpansions = pgTable(\n \"revision_expansions\",\n {\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .primaryKey()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n outcome: revisionExpansionOutcomeEnum().notNull(),\n document: jsonb().$type<readonly unknown[]>(),\n droppedTerms: text(\"dropped_terms\").array(),\n undefinedTerms: text(\"undefined_terms\").array(),\n failure: text(),\n sourceRevisionId: uuid(\"source_revision_id\").$type<Uuid>(),\n },\n (t) => [\n foreignKey({\n name: \"revision_expansions_source_revision_fkey\",\n columns: [t.sourceRevisionId],\n foreignColumns: [resourceRevisions.id],\n }).onDelete(\"restrict\"),\n check(\n \"revision_expansions_outcome_check\",\n sql`(${t.outcome} = 'expanded'\n AND ${t.document} IS NOT NULL\n AND ${t.droppedTerms} IS NOT NULL\n AND ${t.undefinedTerms} IS NOT NULL\n AND ${t.failure} IS NULL)\n OR (${t.outcome} = 'failed'\n AND ${t.document} IS NULL\n AND ${t.droppedTerms} IS NULL\n AND ${t.undefinedTerms} IS NULL\n AND ${t.failure} IS NOT NULL)\n OR (${t.outcome} = 'no_document'\n AND ${t.document} IS NULL\n AND ${t.droppedTerms} IS NULL\n AND ${t.undefinedTerms} IS NULL\n AND ${t.failure} IS NULL\n AND ${t.sourceRevisionId} IS NULL)`,\n ),\n check(\n \"revision_expansions_source_check\",\n sql`${t.sourceRevisionId} <> ${t.revisionId}`,\n ),\n index(\"revision_expansions_source_index\").on(t.sourceRevisionId),\n ],\n);\n\nexport const revisionReceiptRoleEnum = pgEnum(\"revision_receipt_role\", [\n \"activity\",\n \"object\",\n]);\n/** Mutable index of delivery evidence, not part of immutable document history. */\nexport const revisionReceipts = pgTable(\n \"revision_receipts\",\n {\n deliveryId: uuid(\"delivery_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => activityDeliveries.id, { onDelete: \"cascade\" }),\n revisionId: uuid(\"revision_id\")\n .$type<Uuid>()\n .notNull()\n .references(() => resourceRevisions.id, { onDelete: \"restrict\" }),\n role: revisionReceiptRoleEnum().notNull(),\n },\n (t) => [\n primaryKey({ columns: [t.deliveryId, t.revisionId, t.role] }),\n index(\"revision_receipts_revision_index\").on(t.revisionId),\n ],\n);\n\nexport type ResourceRevision = typeof resourceRevisions.$inferSelect;\nexport type NewResourceRevision = typeof resourceRevisions.$inferInsert;\nexport type ResourceHead = typeof resourceHeads.$inferSelect;\nexport type RevisionAddressing = typeof revisionAddressing.$inferSelect;\nexport type RevisionRelation = typeof revisionRelations.$inferSelect;\nexport type RevisionReceipt = typeof revisionReceipts.$inferSelect;\nexport type RevisionEmbedding = typeof revisionEmbeddings.$inferSelect;\nexport type RevisionExpansion = typeof revisionExpansions.$inferSelect;\nexport type NewRevisionExpansion = typeof revisionExpansions.$inferInsert;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,UAAU,WAA2D;CACzE,gBAAgB;CAChB,aAAa,UAAU,SAAS,QAAQ,KAAK,KAAK;CAClD,SAAS,OAAkC;EAEzC,IAAI,OAAO,UAAU,UAAU,OAAO;EACtC,IAAI,iBAAiB,SAAS,SAAS,OAAO,MAAM,SAAS;EAC7D,MAAM,IAAI,UACR,2DACF;CACF;AACF,CAAC;AAED,MAAM,mBAAmB,GAAG;;;;AAK5B,MAAa,WAAW,QACtB,YACA;CACE,IAAI,KAAK,CAAC,CAAC,MAAY,CAAC,CAAC,WAAW;CACpC,OAAO,QAAQ,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO;CACjD,MAAM,QAAQ,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ;CACvC,cAAc,QAAQ,eAAe,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE;CAC3D,OAAO,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,KAAK;CACxC,SAAS,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,gBAAgB;AACvD,IACC,UAAU;CACT,MACE,wBACA,GAAG,GAAG,MAAM,MAAM,2BACpB;CACA,MAAM,gCAAgC,GAAG,GAAG,MAAM,aAAa,MAAM;CACrE,MAAM,uBAAuB,GAAG,kBAAkB,MAAM,KAAK,QAAQ;AACvE,CACF;;;;AAQA,MAAa,YAAY,QAAQ,aAAa;CAC5C,IAAI,KAAK,CAAC,CAAC,MAAY,CAAC,CAAC,WAAW;CACpC,SAAS,KAAK,UAAU,CAAC,CACtB,MAAY,CAAC,CACb,iBAAiB,eAAe,I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AAa;gBACf,EAAE,eAAe;gBACjB,EAAE,QAAQ;cACZ,EAAE,QAAQ;gBACR,EAAE,SAAS;gBACX,EAAE,aAAa;gBACf,EAAE,eAAe;gBACjB,EAAE,QAAQ;gBACV,EAAE,iBAAiB,UAC/B;CACA,MACE,oCACA,GAAG,GAAG,EAAE,iBAAiB,MAAM,EAAE,YACnC;CACA,MAAM,kCAAkC,CAAC,CAAC,GAAG,EAAE,gBAAgB;AACjE,CACF;AAEA,MAAa,0BAA0B,OAAO,yBAAyB,CACrE,YACA,QACF,CAAC;;AAED,MAAa,mBAAmB,QAC9B,qBACA;CACE,YAAY,KAAK,aAAa,CAAC,CAC5B,MAAY,CAAC,CACb,QAAQ,CAAC,CACT,iBAAiB,mBAAmB,IAAI,EAAE,UAAU,UAAU,CAAC;CAClE,YAAY,KAAK,aAAa,CAAC,CAC5B,MAAY,CAAC,CACb,QAAQ,CAAC,CACT,iBAAiB,kBAAkB,IAAI,EAAE,UAAU,WAAW,CAAC;CAClE,MAAM,wBAAwB,CAAC,CAAC,QAAQ;AAC1C,IACC,MAAM,CACL,WAAW,EAAE,SAAS;CAAC,EAAE;CAAY,EAAE;CAAY,EAAE;AAAI,EAAE,CAAC,GAC5D,MAAM,kCAAkC,CAAC,CAAC,GAAG,EAAE,UAAU,CAC3D,CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
CREATE TYPE "revision_expansion_outcome" AS ENUM('expanded', 'failed', 'no_document');--> statement-breakpoint
|
|
2
|
+
CREATE TABLE "revision_expansions" (
|
|
3
|
+
"revision_id" uuid PRIMARY KEY,
|
|
4
|
+
"outcome" "revision_expansion_outcome" NOT NULL,
|
|
5
|
+
"document" jsonb,
|
|
6
|
+
"dropped_terms" text[],
|
|
7
|
+
"undefined_terms" text[],
|
|
8
|
+
"failure" text,
|
|
9
|
+
"source_revision_id" uuid,
|
|
10
|
+
CONSTRAINT "revision_expansions_outcome_check" CHECK (("outcome" = 'expanded'
|
|
11
|
+
AND "document" IS NOT NULL
|
|
12
|
+
AND "dropped_terms" IS NOT NULL
|
|
13
|
+
AND "undefined_terms" IS NOT NULL
|
|
14
|
+
AND "failure" IS NULL)
|
|
15
|
+
OR ("outcome" = 'failed'
|
|
16
|
+
AND "document" IS NULL
|
|
17
|
+
AND "dropped_terms" IS NULL
|
|
18
|
+
AND "undefined_terms" IS NULL
|
|
19
|
+
AND "failure" IS NOT NULL)
|
|
20
|
+
OR ("outcome" = 'no_document'
|
|
21
|
+
AND "document" IS NULL
|
|
22
|
+
AND "dropped_terms" IS NULL
|
|
23
|
+
AND "undefined_terms" IS NULL
|
|
24
|
+
AND "failure" IS NULL
|
|
25
|
+
AND "source_revision_id" IS NULL)),
|
|
26
|
+
CONSTRAINT "revision_expansions_source_check" CHECK ("source_revision_id" <> "revision_id")
|
|
27
|
+
);
|
|
28
|
+
--> statement-breakpoint
|
|
29
|
+
CREATE INDEX "revision_expansions_source_index" ON "revision_expansions" ("source_revision_id");--> statement-breakpoint
|
|
30
|
+
ALTER TABLE "revision_expansions" ADD CONSTRAINT "revision_expansions_revision_id_resource_revisions_id_fkey" FOREIGN KEY ("revision_id") REFERENCES "resource_revisions"("id") ON DELETE RESTRICT;--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "revision_expansions" ADD CONSTRAINT "revision_expansions_source_revision_fkey" FOREIGN KEY ("source_revision_id") REFERENCES "resource_revisions"("id") ON DELETE RESTRICT;
|