@drfed/models 0.0.0-stage → 0.1.0-dev.554

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 (132) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +230 -2
  3. package/dist/activity-delivery.d.mts +111 -0
  4. package/dist/activity-delivery.d.mts.map +1 -0
  5. package/dist/activity-delivery.mjs +240 -0
  6. package/dist/activity-delivery.mjs.map +1 -0
  7. package/dist/db-DtcLuISw.d.mts +3098 -0
  8. package/dist/db-DtcLuISw.d.mts.map +1 -0
  9. package/dist/db.d.mts +2 -0
  10. package/dist/db.mjs +3 -0
  11. package/dist/email.d.mts +39 -0
  12. package/dist/email.d.mts.map +1 -0
  13. package/dist/email.mjs +12 -0
  14. package/dist/email.mjs.map +1 -0
  15. package/dist/index.d.mts +14 -0
  16. package/dist/index.mjs +18 -0
  17. package/dist/instance.d.mts +11 -0
  18. package/dist/instance.d.mts.map +1 -0
  19. package/dist/instance.mjs +21 -0
  20. package/dist/instance.mjs.map +1 -0
  21. package/dist/key.d.mts +2 -0
  22. package/dist/key.mjs +86 -0
  23. package/dist/key.mjs.map +1 -0
  24. package/dist/login.d.mts +49 -0
  25. package/dist/login.d.mts.map +1 -0
  26. package/dist/login.mjs +71 -0
  27. package/dist/login.mjs.map +1 -0
  28. package/dist/migrate.d.mts +46 -0
  29. package/dist/migrate.d.mts.map +1 -0
  30. package/dist/migrate.mjs +58 -0
  31. package/dist/migrate.mjs.map +1 -0
  32. package/dist/migration-manifest.d.mts +39 -0
  33. package/dist/migration-manifest.d.mts.map +1 -0
  34. package/dist/migration-manifest.mjs +77 -0
  35. package/dist/migration-manifest.mjs.map +1 -0
  36. package/dist/migration-session-B4xHeU_a.d.mts +56 -0
  37. package/dist/migration-session-B4xHeU_a.d.mts.map +1 -0
  38. package/dist/migration-session.d.mts +2 -0
  39. package/dist/migration-session.mjs +204 -0
  40. package/dist/migration-session.mjs.map +1 -0
  41. package/dist/migration-snapshot-OM5jQN1-.mjs +69 -0
  42. package/dist/migration-snapshot-OM5jQN1-.mjs.map +1 -0
  43. package/dist/migration-state.d.mts +41 -0
  44. package/dist/migration-state.d.mts.map +1 -0
  45. package/dist/migration-state.mjs +155 -0
  46. package/dist/migration-state.mjs.map +1 -0
  47. package/dist/migrations-manifest.json +109 -0
  48. package/dist/pglite-preparation.d.mts +23 -0
  49. package/dist/pglite-preparation.d.mts.map +1 -0
  50. package/dist/pglite-preparation.mjs +77 -0
  51. package/dist/pglite-preparation.mjs.map +1 -0
  52. package/dist/pglite-store.d.mts +29 -0
  53. package/dist/pglite-store.d.mts.map +1 -0
  54. package/dist/pglite-store.mjs +117 -0
  55. package/dist/pglite-store.mjs.map +1 -0
  56. package/dist/relations.d.mts +2 -0
  57. package/dist/relations.mjs +307 -0
  58. package/dist/relations.mjs.map +1 -0
  59. package/dist/resource.d.mts +50 -0
  60. package/dist/resource.d.mts.map +1 -0
  61. package/dist/resource.mjs +123 -0
  62. package/dist/resource.mjs.map +1 -0
  63. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  64. package/dist/schema.d.mts +2 -0
  65. package/dist/schema.mjs +495 -0
  66. package/dist/schema.mjs.map +1 -0
  67. package/dist/slug.d.mts +28 -0
  68. package/dist/slug.d.mts.map +1 -0
  69. package/dist/slug.mjs +55 -0
  70. package/dist/slug.mjs.map +1 -0
  71. package/dist/text.d.mts +10 -0
  72. package/dist/text.d.mts.map +1 -0
  73. package/dist/text.mjs +11 -0
  74. package/dist/text.mjs.map +1 -0
  75. package/dist/uuid-CKMzlIND.d.mts +26 -0
  76. package/dist/uuid-CKMzlIND.d.mts.map +1 -0
  77. package/dist/uuid.d.mts +2 -0
  78. package/dist/uuid.mjs +28 -0
  79. package/dist/uuid.mjs.map +1 -0
  80. package/drizzle/20260622021748_init/migration.sql +25 -0
  81. package/drizzle/20260622021748_init/snapshot.json +246 -0
  82. package/drizzle/20260623162238_dear_felicia_hardy/migration.sql +5 -0
  83. package/drizzle/20260623162238_dear_felicia_hardy/snapshot.json +321 -0
  84. package/drizzle/20260624094817_lethal_sinister_six/migration.sql +2 -0
  85. package/drizzle/20260624094817_lethal_sinister_six/snapshot.json +347 -0
  86. package/drizzle/20260716000333_email_auth/migration.sql +20 -0
  87. package/drizzle/20260716000333_email_auth/snapshot.json +575 -0
  88. package/drizzle/20260723065002_chief_colleen_wing/migration.sql +2 -0
  89. package/drizzle/20260723065002_chief_colleen_wing/snapshot.json +595 -0
  90. package/drizzle/20260802205417_separate-instance-local-remote/migration.sql +26 -0
  91. package/drizzle/20260802205417_separate-instance-local-remote/snapshot.json +768 -0
  92. package/drizzle/20260804061119_instances-local-remote-constraint/migration.sql +7 -0
  93. package/drizzle/20260804061119_instances-local-remote-constraint/snapshot.json +843 -0
  94. package/drizzle/20260818080259_dark_night_thrasher/migration.sql +15 -0
  95. package/drizzle/20260818080259_dark_night_thrasher/snapshot.json +722 -0
  96. package/drizzle/20260821072150_merge_remote_actors/migration.sql +54 -0
  97. package/drizzle/20260821072150_merge_remote_actors/snapshot.json +1312 -0
  98. package/drizzle/20260906052949_rename_followees_to_following/migration.sql +2 -0
  99. package/drizzle/20260906052949_rename_followees_to_following/snapshot.json +1315 -0
  100. package/drizzle/20260908062446_rename_login_tokens_to_login_challenges/migration.sql +1 -0
  101. package/drizzle/20260908062446_rename_login_tokens_to_login_challenges/snapshot.json +1312 -0
  102. package/drizzle/20260908065945_simplify_login_challenges/migration.sql +7 -0
  103. package/drizzle/20260908065945_simplify_login_challenges/snapshot.json +1290 -0
  104. package/drizzle/20260915061356_tighten_slug_constraint/migration.sql +12 -0
  105. package/drizzle/20260915061356_tighten_slug_constraint/snapshot.json +1290 -0
  106. package/drizzle/20260915063339_widen_instance_host/migration.sql +1 -0
  107. package/drizzle/20260915063339_widen_instance_host/snapshot.json +1290 -0
  108. package/drizzle/20260916085902_add_objects_activities_and_resources/migration.sql +110 -0
  109. package/drizzle/20260916085902_add_objects_activities_and_resources/snapshot.json +2263 -0
  110. package/drizzle/20260917163517_order_local_outbox_items/migration.sql +22 -0
  111. package/drizzle/20260917163517_order_local_outbox_items/snapshot.json +2263 -0
  112. package/drizzle/20260918071839_add_activity_object_index/migration.sql +1 -0
  113. package/drizzle/20260918071839_add_activity_object_index/snapshot.json +2298 -0
  114. package/drizzle/20261006061745_add_activity_deliveries_and_keys/migration.sql +106 -0
  115. package/drizzle/20261006061745_add_activity_deliveries_and_keys/snapshot.json +3538 -0
  116. package/drizzle/20261006085045_snake_case_columns/migration.sql +42 -0
  117. package/drizzle/20261006085045_snake_case_columns/snapshot.json +3570 -0
  118. package/drizzle/20261006122653_local_actor_keys/migration.sql +11 -0
  119. package/drizzle/20261006122653_local_actor_keys/snapshot.json +3627 -0
  120. package/drizzle/20261010044954_link_activity_deliveries_to_activities/migration.sql +8 -0
  121. package/drizzle/20261010044954_link_activity_deliveries_to_activities/snapshot.json +3714 -0
  122. package/drizzle/20261010073134_check_inbound_activity_link/migration.sql +1 -0
  123. package/drizzle/20261010073134_check_inbound_activity_link/snapshot.json +3721 -0
  124. package/drizzle/20261010104304_record_object_activity/migration.sql +3 -0
  125. package/drizzle/20261010104304_record_object_activity/snapshot.json +3756 -0
  126. package/drizzle/20261010111648_record_delivery_snapshot/migration.sql +29 -0
  127. package/drizzle/20261010111648_record_delivery_snapshot/snapshot.json +3769 -0
  128. package/drizzle/20261011144453_record_object_snapshot/migration.sql +10 -0
  129. package/drizzle/20261011144453_record_object_snapshot/snapshot.json +3808 -0
  130. package/drizzle/20261011192718_record_actor_followers/migration.sql +1 -0
  131. package/drizzle/20261011192718_record_actor_followers/snapshot.json +3821 -0
  132. package/package.json +193 -3
package/dist/slug.mjs ADDED
@@ -0,0 +1,55 @@
1
+ //#region src/slug.ts
2
+ /**
3
+ * The shape of a syntactically valid slug: 4 to 63 characters drawn from
4
+ * lowercase letters, digits and hyphens, and starting and ending with a letter
5
+ * or a digit.
6
+ *
7
+ * The bounds on the inner group encode the overall 4–63 length: two anchoring
8
+ * characters plus 2–61 in between. The upper bound is the maximum length of
9
+ * a DNS label, and the lower bound keeps very short slugs — which are the ones
10
+ * most likely to collide with an operational host name such as `www` or
11
+ * `api` — out of circulation.
12
+ */
13
+ const SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{2,61}[a-z0-9]$/u;
14
+ /**
15
+ * Labels whose third and fourth characters are both hyphens. RFC 5891 § 4.2.3.1
16
+ * reserves the whole class and gives a meaning to exactly one member of it,
17
+ * the `xn--` prefix that introduces a Punycode-encoded A-label.
18
+ */
19
+ const RESERVED_LDH_PATTERN = /^..--/u;
20
+ /**
21
+ * The prefix of an A-label, i.e. the ASCII-compatible encoding of an
22
+ * internationalized domain name label.
23
+ */
24
+ const A_LABEL_PREFIX = "xn--";
25
+ /**
26
+ * Checks whether a slug can be used as the leftmost label of an instance's
27
+ * host name.
28
+ *
29
+ * A slug has to be a valid DNS label, because it becomes one: an instance with
30
+ * the slug `foo-bar` is served at `foo-bar.<root domain>`. That rules out
31
+ * leading and trailing hyphens, which no resolver accepts, and the reserved
32
+ * LDH labels of RFC 5891 — except for `xn--`, which is deliberately allowed so
33
+ * that instances can carry internationalized domain names. DrFed is a tool for
34
+ * debugging federation, and IDN host names are one of the things that break it.
35
+ *
36
+ * Whether such a label is decodable Punycode is deliberately not checked here.
37
+ * Node answers that out of its bundled ICU, so the answer moves with the
38
+ * runtime, and a rule that accepts a slug on one deployment while rejecting it
39
+ * on another is worse than no rule at all. `createInstance` instead refuses a
40
+ * slug whose composed host the local runtime cannot parse, which is the thing
41
+ * that actually matters.
42
+ *
43
+ * This duplicates the `local_instances_slug_check` constraint in
44
+ * {@link file://./schema.ts}; the two must be kept in agreement.
45
+ * @param slug The slug to check.
46
+ * @returns `true` if the slug is usable, `false` otherwise.
47
+ */
48
+ function isValidSlug(slug) {
49
+ if (!SLUG_PATTERN.test(slug)) return false;
50
+ return !RESERVED_LDH_PATTERN.test(slug) || slug.startsWith(A_LABEL_PREFIX);
51
+ }
52
+ //#endregion
53
+ export { isValidSlug };
54
+
55
+ //# sourceMappingURL=slug.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug.mjs","names":[],"sources":["../src/slug.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\n/**\n * The shape of a syntactically valid slug: 4 to 63 characters drawn from\n * lowercase letters, digits and hyphens, and starting and ending with a letter\n * or a digit.\n *\n * The bounds on the inner group encode the overall 4–63 length: two anchoring\n * characters plus 2–61 in between. The upper bound is the maximum length of\n * a DNS label, and the lower bound keeps very short slugs — which are the ones\n * most likely to collide with an operational host name such as `www` or\n * `api` — out of circulation.\n */\nconst SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{2,61}[a-z0-9]$/u;\n\n/**\n * Labels whose third and fourth characters are both hyphens. RFC 5891 § 4.2.3.1\n * reserves the whole class and gives a meaning to exactly one member of it,\n * the `xn--` prefix that introduces a Punycode-encoded A-label.\n */\nconst RESERVED_LDH_PATTERN = /^..--/u;\n\n/**\n * The prefix of an A-label, i.e. the ASCII-compatible encoding of an\n * internationalized domain name label.\n */\nconst A_LABEL_PREFIX = \"xn--\";\n\n/**\n * Checks whether a slug can be used as the leftmost label of an instance's\n * host name.\n *\n * A slug has to be a valid DNS label, because it becomes one: an instance with\n * the slug `foo-bar` is served at `foo-bar.<root domain>`. That rules out\n * leading and trailing hyphens, which no resolver accepts, and the reserved\n * LDH labels of RFC 5891 — except for `xn--`, which is deliberately allowed so\n * that instances can carry internationalized domain names. DrFed is a tool for\n * debugging federation, and IDN host names are one of the things that break it.\n *\n * Whether such a label is decodable Punycode is deliberately not checked here.\n * Node answers that out of its bundled ICU, so the answer moves with the\n * runtime, and a rule that accepts a slug on one deployment while rejecting it\n * on another is worse than no rule at all. `createInstance` instead refuses a\n * slug whose composed host the local runtime cannot parse, which is the thing\n * that actually matters.\n *\n * This duplicates the `local_instances_slug_check` constraint in\n * {@link file://./schema.ts}; the two must be kept in agreement.\n * @param slug The slug to check.\n * @returns `true` if the slug is usable, `false` otherwise.\n */\nexport function isValidSlug(slug: string): boolean {\n if (!SLUG_PATTERN.test(slug)) return false;\n return !RESERVED_LDH_PATTERN.test(slug) || slug.startsWith(A_LABEL_PREFIX);\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,MAAM,eAAe;;;;;;AAOrB,MAAM,uBAAuB;;;;;AAM7B,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;AAyBvB,SAAgB,YAAY,MAAuB;CACjD,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,OAAO;CACrC,OAAO,CAAC,qBAAqB,KAAK,IAAI,KAAK,KAAK,WAAW,cAAc;AAC3E"}
@@ -0,0 +1,10 @@
1
+ //#region src/text.d.ts
2
+ /**
3
+ * PostgreSQL's text and jsonb hold no U+0000, and the driver replaces an
4
+ * unpaired surrogate with U+FFFD on its way into the database's UTF-8.
5
+ * @returns Whether the string is stored as it is.
6
+ */
7
+ declare const storableText: (value: string) => boolean;
8
+ //#endregion
9
+ export { storableText };
10
+ //# sourceMappingURL=text.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.mts","names":[],"sources":["../src/text.ts"],"mappings":";;;;;;cAqBa,eAAY"}
package/dist/text.mjs ADDED
@@ -0,0 +1,11 @@
1
+ //#region src/text.ts
2
+ /**
3
+ * PostgreSQL's text and jsonb hold no U+0000, and the driver replaces an
4
+ * unpaired surrogate with U+FFFD on its way into the database's UTF-8.
5
+ * @returns Whether the string is stored as it is.
6
+ */
7
+ const storableText = (value) => !value.includes("\0") && value.isWellFormed();
8
+ //#endregion
9
+ export { storableText };
10
+
11
+ //# sourceMappingURL=text.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.mjs","names":[],"sources":["../src/text.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\n/**\n * PostgreSQL's text and jsonb hold no U+0000, and the driver replaces an\n * unpaired surrogate with U+FFFD on its way into the database's UTF-8.\n * @returns Whether the string is stored as it is.\n */\nexport const storableText = (value: string): boolean =>\n !value.includes(\"\\0\") && value.isWellFormed();\n"],"mappings":";;;;;;AAqBA,MAAa,gBAAgB,UAC3B,CAAC,MAAM,SAAS,IAAI,KAAK,MAAM,aAAa"}
@@ -0,0 +1,26 @@
1
+ //#region src/uuid.d.ts
2
+ /**
3
+ * A UUID string. It does not guarantee that the string is a normalized UUID.
4
+ */
5
+ type Uuid = ReturnType<typeof crypto.randomUUID>;
6
+ /**
7
+ * Compares two UUIDs for equality, ignoring case.
8
+ * @param left A UUID string to compare.
9
+ * @param right Another UUID string to compare.
10
+ * @returns `true` if the UUIDs are equal (ignoring case), `false` otherwise.
11
+ */
12
+ declare function areUuidsEqual(left: Uuid, right: Uuid): boolean;
13
+ /**
14
+ * Generates a new UUIDv7 string.
15
+ * @returns A new UUIDv7 string.
16
+ */
17
+ declare function uuidV7(): Uuid;
18
+ /**
19
+ * Validate UUID.
20
+ * @param value A Value to validate.
21
+ * @returns `true` if the input is `Uuid`.
22
+ */
23
+ declare const validateUuid: (value: unknown) => value is Uuid;
24
+ //#endregion
25
+ export { validateUuid as i, areUuidsEqual as n, uuidV7 as r, Uuid as t };
26
+ //# sourceMappingURL=uuid-CKMzlIND.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid-CKMzlIND.d.mts","names":[],"sources":["../src/uuid.ts"],"mappings":";;;;KAoBY,OAAO,kBAAkB,OAAO;;;;;;;iBAQ5B,cAAc,MAAM,MAAM,OAAO;;;;;iBAQjC,UAAU;;;;;;cASb,eAAY,mBAAqB,SAAS"}
@@ -0,0 +1,2 @@
1
+ import { i as validateUuid, n as areUuidsEqual, r as uuidV7, t as Uuid } from "./uuid-CKMzlIND.mjs";
2
+ export { Uuid, areUuidsEqual, uuidV7, validateUuid };
package/dist/uuid.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { v7, validate } from "uuid";
2
+ //#region src/uuid.ts
3
+ /**
4
+ * Compares two UUIDs for equality, ignoring case.
5
+ * @param left A UUID string to compare.
6
+ * @param right Another UUID string to compare.
7
+ * @returns `true` if the UUIDs are equal (ignoring case), `false` otherwise.
8
+ */
9
+ function areUuidsEqual(left, right) {
10
+ return left.toLowerCase() === right.toLowerCase();
11
+ }
12
+ /**
13
+ * Generates a new UUIDv7 string.
14
+ * @returns A new UUIDv7 string.
15
+ */
16
+ function uuidV7() {
17
+ return v7();
18
+ }
19
+ /**
20
+ * Validate UUID.
21
+ * @param value A Value to validate.
22
+ * @returns `true` if the input is `Uuid`.
23
+ */
24
+ const validateUuid = (value) => validate(value);
25
+ //#endregion
26
+ export { areUuidsEqual, uuidV7, validateUuid };
27
+
28
+ //# sourceMappingURL=uuid.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.mjs","names":[],"sources":["../src/uuid.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/>.\nimport { v7, validate } from \"uuid\";\n\n/**\n * A UUID string. It does not guarantee that the string is a normalized UUID.\n */\nexport type Uuid = ReturnType<typeof crypto.randomUUID>;\n\n/**\n * Compares two UUIDs for equality, ignoring case.\n * @param left A UUID string to compare.\n * @param right Another UUID string to compare.\n * @returns `true` if the UUIDs are equal (ignoring case), `false` otherwise.\n */\nexport function areUuidsEqual(left: Uuid, right: Uuid): boolean {\n return left.toLowerCase() === right.toLowerCase();\n}\n\n/**\n * Generates a new UUIDv7 string.\n * @returns A new UUIDv7 string.\n */\nexport function uuidV7(): Uuid {\n return v7() as Uuid;\n}\n\n/**\n * Validate UUID.\n * @param value A Value to validate.\n * @returns `true` if the input is `Uuid`.\n */\nexport const validateUuid = (value: unknown): value is Uuid => validate(value);\n"],"mappings":";;;;;;;;AA4BA,SAAgB,cAAc,MAAY,OAAsB;CAC9D,OAAO,KAAK,YAAY,MAAM,MAAM,YAAY;AAClD;;;;;AAMA,SAAgB,SAAe;CAC7B,OAAO,GAAG;AACZ;;;;;;AAOA,MAAa,gBAAgB,UAAkC,SAAS,KAAK"}
@@ -0,0 +1,25 @@
1
+ CREATE TABLE "accounts" (
2
+ "id" uuid PRIMARY KEY,
3
+ "email" varchar(255) NOT NULL UNIQUE,
4
+ "created" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
5
+ CONSTRAINT "accounts_email_check" CHECK ("email" ~ '^[^@]+@[^@]+\.[^@]+$')
6
+ );
7
+ --> statement-breakpoint
8
+ CREATE TABLE "instance_members" (
9
+ "instanceId" uuid,
10
+ "accountId" uuid,
11
+ "created" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
12
+ CONSTRAINT "instance_members_pkey" PRIMARY KEY("instanceId","accountId")
13
+ );
14
+ --> statement-breakpoint
15
+ CREATE TABLE "instances" (
16
+ "id" uuid PRIMARY KEY,
17
+ "slug" varchar(100) NOT NULL UNIQUE,
18
+ "expires" timestamp with time zone NOT NULL,
19
+ "created" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
20
+ CONSTRAINT "instances_slug_check" CHECK ("slug" ~ '^[a-z0-9-]{4,100}$'),
21
+ CONSTRAINT "instances_expires_check" CHECK ("expires" < ("created" + INTERVAL '1 year'))
22
+ );
23
+ --> statement-breakpoint
24
+ ALTER TABLE "instance_members" ADD CONSTRAINT "instance_members_instanceId_instances_id_fkey" FOREIGN KEY ("instanceId") REFERENCES "instances"("id");--> statement-breakpoint
25
+ ALTER TABLE "instance_members" ADD CONSTRAINT "instance_members_accountId_accounts_id_fkey" FOREIGN KEY ("accountId") REFERENCES "accounts"("id");
@@ -0,0 +1,246 @@
1
+ {
2
+ "version": "8",
3
+ "dialect": "postgres",
4
+ "id": "2cffbe98-208b-4301-ad32-8c2e3e74928f",
5
+ "prevIds": ["00000000-0000-0000-0000-000000000000"],
6
+ "ddl": [
7
+ {
8
+ "isRlsEnabled": false,
9
+ "name": "accounts",
10
+ "entityType": "tables",
11
+ "schema": "public"
12
+ },
13
+ {
14
+ "isRlsEnabled": false,
15
+ "name": "instance_members",
16
+ "entityType": "tables",
17
+ "schema": "public"
18
+ },
19
+ {
20
+ "isRlsEnabled": false,
21
+ "name": "instances",
22
+ "entityType": "tables",
23
+ "schema": "public"
24
+ },
25
+ {
26
+ "type": "uuid",
27
+ "typeSchema": null,
28
+ "notNull": true,
29
+ "dimensions": 0,
30
+ "default": null,
31
+ "generated": null,
32
+ "identity": null,
33
+ "name": "id",
34
+ "entityType": "columns",
35
+ "schema": "public",
36
+ "table": "accounts"
37
+ },
38
+ {
39
+ "type": "varchar(255)",
40
+ "typeSchema": null,
41
+ "notNull": true,
42
+ "dimensions": 0,
43
+ "default": null,
44
+ "generated": null,
45
+ "identity": null,
46
+ "name": "email",
47
+ "entityType": "columns",
48
+ "schema": "public",
49
+ "table": "accounts"
50
+ },
51
+ {
52
+ "type": "timestamp with time zone",
53
+ "typeSchema": null,
54
+ "notNull": true,
55
+ "dimensions": 0,
56
+ "default": "CURRENT_TIMESTAMP",
57
+ "generated": null,
58
+ "identity": null,
59
+ "name": "created",
60
+ "entityType": "columns",
61
+ "schema": "public",
62
+ "table": "accounts"
63
+ },
64
+ {
65
+ "type": "uuid",
66
+ "typeSchema": null,
67
+ "notNull": true,
68
+ "dimensions": 0,
69
+ "default": null,
70
+ "generated": null,
71
+ "identity": null,
72
+ "name": "instanceId",
73
+ "entityType": "columns",
74
+ "schema": "public",
75
+ "table": "instance_members"
76
+ },
77
+ {
78
+ "type": "uuid",
79
+ "typeSchema": null,
80
+ "notNull": true,
81
+ "dimensions": 0,
82
+ "default": null,
83
+ "generated": null,
84
+ "identity": null,
85
+ "name": "accountId",
86
+ "entityType": "columns",
87
+ "schema": "public",
88
+ "table": "instance_members"
89
+ },
90
+ {
91
+ "type": "timestamp with time zone",
92
+ "typeSchema": null,
93
+ "notNull": true,
94
+ "dimensions": 0,
95
+ "default": "CURRENT_TIMESTAMP",
96
+ "generated": null,
97
+ "identity": null,
98
+ "name": "created",
99
+ "entityType": "columns",
100
+ "schema": "public",
101
+ "table": "instance_members"
102
+ },
103
+ {
104
+ "type": "uuid",
105
+ "typeSchema": null,
106
+ "notNull": true,
107
+ "dimensions": 0,
108
+ "default": null,
109
+ "generated": null,
110
+ "identity": null,
111
+ "name": "id",
112
+ "entityType": "columns",
113
+ "schema": "public",
114
+ "table": "instances"
115
+ },
116
+ {
117
+ "type": "varchar(100)",
118
+ "typeSchema": null,
119
+ "notNull": true,
120
+ "dimensions": 0,
121
+ "default": null,
122
+ "generated": null,
123
+ "identity": null,
124
+ "name": "slug",
125
+ "entityType": "columns",
126
+ "schema": "public",
127
+ "table": "instances"
128
+ },
129
+ {
130
+ "type": "timestamp with time zone",
131
+ "typeSchema": null,
132
+ "notNull": true,
133
+ "dimensions": 0,
134
+ "default": null,
135
+ "generated": null,
136
+ "identity": null,
137
+ "name": "expires",
138
+ "entityType": "columns",
139
+ "schema": "public",
140
+ "table": "instances"
141
+ },
142
+ {
143
+ "type": "timestamp with time zone",
144
+ "typeSchema": null,
145
+ "notNull": true,
146
+ "dimensions": 0,
147
+ "default": "CURRENT_TIMESTAMP",
148
+ "generated": null,
149
+ "identity": null,
150
+ "name": "created",
151
+ "entityType": "columns",
152
+ "schema": "public",
153
+ "table": "instances"
154
+ },
155
+ {
156
+ "nameExplicit": false,
157
+ "columns": ["instanceId"],
158
+ "schemaTo": "public",
159
+ "tableTo": "instances",
160
+ "columnsTo": ["id"],
161
+ "onUpdate": "NO ACTION",
162
+ "onDelete": "NO ACTION",
163
+ "name": "instance_members_instanceId_instances_id_fkey",
164
+ "entityType": "fks",
165
+ "schema": "public",
166
+ "table": "instance_members"
167
+ },
168
+ {
169
+ "nameExplicit": false,
170
+ "columns": ["accountId"],
171
+ "schemaTo": "public",
172
+ "tableTo": "accounts",
173
+ "columnsTo": ["id"],
174
+ "onUpdate": "NO ACTION",
175
+ "onDelete": "NO ACTION",
176
+ "name": "instance_members_accountId_accounts_id_fkey",
177
+ "entityType": "fks",
178
+ "schema": "public",
179
+ "table": "instance_members"
180
+ },
181
+ {
182
+ "columns": ["instanceId", "accountId"],
183
+ "nameExplicit": false,
184
+ "name": "instance_members_pkey",
185
+ "entityType": "pks",
186
+ "schema": "public",
187
+ "table": "instance_members"
188
+ },
189
+ {
190
+ "columns": ["id"],
191
+ "nameExplicit": false,
192
+ "name": "accounts_pkey",
193
+ "schema": "public",
194
+ "table": "accounts",
195
+ "entityType": "pks"
196
+ },
197
+ {
198
+ "columns": ["id"],
199
+ "nameExplicit": false,
200
+ "name": "instances_pkey",
201
+ "schema": "public",
202
+ "table": "instances",
203
+ "entityType": "pks"
204
+ },
205
+ {
206
+ "nameExplicit": false,
207
+ "columns": ["email"],
208
+ "nullsNotDistinct": false,
209
+ "name": "accounts_email_key",
210
+ "schema": "public",
211
+ "table": "accounts",
212
+ "entityType": "uniques"
213
+ },
214
+ {
215
+ "nameExplicit": false,
216
+ "columns": ["slug"],
217
+ "nullsNotDistinct": false,
218
+ "name": "instances_slug_key",
219
+ "schema": "public",
220
+ "table": "instances",
221
+ "entityType": "uniques"
222
+ },
223
+ {
224
+ "value": "\"email\" ~ '^[^@]+@[^@]+\\.[^@]+$'",
225
+ "name": "accounts_email_check",
226
+ "entityType": "checks",
227
+ "schema": "public",
228
+ "table": "accounts"
229
+ },
230
+ {
231
+ "value": "\"slug\" ~ '^[a-z0-9-]{4,100}$'",
232
+ "name": "instances_slug_check",
233
+ "entityType": "checks",
234
+ "schema": "public",
235
+ "table": "instances"
236
+ },
237
+ {
238
+ "value": "\"expires\" < (\"created\" + INTERVAL '1 year')",
239
+ "name": "instances_expires_check",
240
+ "entityType": "checks",
241
+ "schema": "public",
242
+ "table": "instances"
243
+ }
244
+ ],
245
+ "renames": []
246
+ }
@@ -0,0 +1,5 @@
1
+ ALTER TABLE "accounts" ADD COLUMN "name" varchar(100) NOT NULL;--> statement-breakpoint
2
+ ALTER TABLE "instance_members" ADD COLUMN "accepted" timestamp with time zone;--> statement-breakpoint
3
+ CREATE INDEX "instance_members_accountId_index" ON "instance_members" ("accountId") WHERE "accepted" IS NOT NULL;--> statement-breakpoint
4
+ CREATE INDEX "instance_members_instanceId_index" ON "instance_members" ("instanceId") WHERE "accepted" IS NOT NULL;--> statement-breakpoint
5
+ ALTER TABLE "accounts" ADD CONSTRAINT "accounts_name_check" CHECK (trim(both from "name") <> '');