@headless-lms/adapter-db 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/repositories/assets.js +1 -0
- package/dist/repositories/assets.js.map +1 -1
- package/dist/repositories/content.js +3 -0
- package/dist/repositories/content.js.map +1 -1
- package/dist/repositories/organizations.d.ts +2 -1
- package/dist/repositories/organizations.js +5 -0
- package/dist/repositories/organizations.js.map +1 -1
- package/dist/schema/automations.d.ts +1 -1
- package/dist/schema/content.d.ts +51 -0
- package/dist/schema/content.js +19 -1
- package/dist/schema/content.js.map +1 -1
- package/dist/schema/discussion.d.ts +1 -1
- package/dist/schema/organizations.d.ts +19 -0
- package/dist/schema/organizations.js +2 -1
- package/dist/schema/organizations.js.map +1 -1
- package/drizzle/0020_space_images.sql +9 -0
- package/drizzle/0021_org_metadata.sql +1 -0
- package/drizzle/meta/0020_snapshot.json +10045 -0
- package/drizzle/meta/0021_snapshot.json +10052 -0
- package/drizzle/meta/_journal.json +14 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizations.js","names":[],"sources":["../../src/repositories/organizations.ts"],"sourcesContent":["// organizations — Drizzle repository (implements the core outbound port).\nimport { and, asc, eq, inArray, sql } from \"drizzle-orm\";\nimport type { NodePgDatabase } from \"drizzle-orm/node-postgres\";\nimport type {\n CreateOrgUserInput,\n Invite,\n NewInviteRow,\n NewOrganizationRow,\n Organization,\n OrganizationsRepository,\n OrgUser,\n UpdateOrganizationInput,\n UpdateOrgUserInput,\n} from \"@headless-lms/core/organizations\";\nimport { invites, organizations, orgUsers } from \"../schema/organizations.js\";\nimport type { Logger } from \"@headless-lms/core/shared/ports\";\nimport { noopLogger } from \"@headless-lms/core/shared/logger\";\nimport { ConflictError } from \"@headless-lms/core/shared/errors\";\nimport { isUniqueViolation, pgErrorFields, translateDbErrors } from \"./pg-errors.js\";\n\nconst INVITE_STATUSES = [\"pending\", \"accepted\", \"rejected\", \"canceled\"] as const;\ntype InviteStatus = (typeof INVITE_STATUSES)[number];\nconst toStatus = (s: string): InviteStatus =>\n (INVITE_STATUSES as readonly string[]).includes(s) ? (s as InviteStatus) : \"pending\";\n\nfunction toInvite(row: typeof invites.$inferSelect): Invite {\n return {\n id: row.id,\n orgId: row.orgId,\n email: row.email,\n roleKey: row.roleKey,\n status: row.status,\n invitedBy: row.invitedBy,\n tokenHash: row.tokenHash,\n expiresAt: row.expiresAt,\n createdAt: row.createdAt,\n updatedAt: row.updatedAt,\n };\n}\n\nexport class DrizzleOrganizationsRepository implements OrganizationsRepository {\n constructor(\n private readonly db: NodePgDatabase,\n private readonly logger: Logger = noopLogger,\n ) {}\n\n async create(input: NewOrganizationRow): Promise<Organization> {\n const [row] = await this.db\n .insert(organizations)\n .values({\n externalId: input.externalId,\n name: input.name,\n slug: input.slug,\n ownerId: input.ownerId,\n id: input.id,\n })\n .returning();\n if (!row) {\n throw new Error(\"failed to insert organization\");\n }\n return row!;\n }\n\n async update(id: string, input: UpdateOrganizationInput): Promise<Organization | null> {\n const [row] = await this.db\n .update(organizations)\n .set({ name: input.name, slug: input.slug })\n .where(eq(organizations.id, id))\n .returning();\n return row ?? null;\n }\n\n async delete(id: string): Promise<Organization> {\n const [row] = await this.db.delete(organizations).where(eq(organizations.id, id)).returning();\n\n if (!row) {\n throw new Error(\"failed to delete organization\");\n }\n return row;\n }\n\n async findById(id: string): Promise<Organization | null> {\n const [row] = await this.db.select().from(organizations).where(eq(organizations.id, id));\n return row ?? null;\n }\n\n async listIds(): Promise<string[]> {\n const rows = await this.db\n .select({ id: organizations.id })\n .from(organizations)\n .orderBy(asc(organizations.id));\n return rows.map((row) => row.id);\n }\n\n async findByExternalId(externalId: string): Promise<Organization | null> {\n const [row] = await this.db\n .select()\n .from(organizations)\n .where(eq(organizations.externalId, externalId))\n .limit(1);\n return row ?? null;\n }\n\n async findBySlug(slug: string): Promise<Organization | null> {\n const [row] = await this.db\n .select()\n .from(organizations)\n .where(eq(organizations.slug, slug))\n .limit(1);\n return row ?? null;\n }\n\n async upsertPendingInvite(orgId: string, input: NewInviteRow): Promise<Invite> {\n const [row] = await this.db\n .insert(invites)\n .values({\n orgId,\n email: input.email,\n roleKey: input.roleKey,\n status: \"pending\",\n invitedBy: input.invitedBy,\n tokenHash: input.tokenHash,\n expiresAt: input.expiresAt,\n })\n .onConflictDoUpdate({\n target: [invites.orgId, invites.email],\n targetWhere: sql`${invites.status} = 'pending'`,\n set: {\n roleKey: input.roleKey,\n invitedBy: input.invitedBy,\n tokenHash: input.tokenHash,\n expiresAt: input.expiresAt,\n },\n })\n .returning();\n if (!row) {\n throw new Error(\"failed to upsert invite\");\n }\n return toInvite(row);\n }\n\n async setInviteStatus(orgId: string, id: string, status: string): Promise<Invite | null> {\n const [row] = await this.db\n .update(invites)\n .set({ status: toStatus(status) })\n .where(and(eq(invites.orgId, orgId), eq(invites.id, id)))\n .returning();\n return row ? toInvite(row) : null;\n }\n\n async setInviteRole(\n orgId: string,\n id: string,\n roleKey: string,\n invitedBy: string,\n ): Promise<Invite | null> {\n const [row] = await this.db\n .update(invites)\n .set({ roleKey, invitedBy })\n .where(and(eq(invites.orgId, orgId), eq(invites.id, id), eq(invites.status, \"pending\")))\n .returning();\n return row ? toInvite(row) : null;\n }\n\n async findInviteByTokenHash(tokenHash: string): Promise<Invite | null> {\n const [row] = await this.db\n .select()\n .from(invites)\n .where(eq(invites.tokenHash, tokenHash))\n .limit(1);\n return row ? toInvite(row) : null;\n }\n\n async findPendingInvite(orgId: string, email: string): Promise<Invite | null> {\n const [row] = await this.db\n .select()\n .from(invites)\n .where(\n and(\n eq(invites.orgId, orgId),\n sql`lower(${invites.email}) = lower(${email})`,\n eq(invites.status, \"pending\"),\n ),\n )\n .limit(1);\n return row ? toInvite(row) : null;\n }\n\n async setInviteToken(\n orgId: string,\n id: string,\n tokenHash: string,\n expiresAt: Date,\n invitedBy: string,\n ): Promise<Invite | null> {\n const [row] = await this.db\n .update(invites)\n .set({ tokenHash, expiresAt, invitedBy })\n .where(and(eq(invites.orgId, orgId), eq(invites.id, id), eq(invites.status, \"pending\")))\n .returning();\n return row ? toInvite(row) : null;\n }\n\n async findOrgUser(orgId: string, userId: string): Promise<OrgUser | null> {\n const [row] = await this.db\n .select()\n .from(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.userId, userId)))\n .limit(1);\n return row ?? null;\n }\n\n async findOrgUsersByUser(userId: string): Promise<OrgUser[]> {\n const rows = await this.db\n .select()\n .from(orgUsers)\n .where(eq(orgUsers.userId, userId))\n .orderBy(orgUsers.createdAt);\n return rows;\n }\n\n async findOrgUserById(orgId: string, id: string): Promise<OrgUser | null> {\n const [row] = await this.db\n .select()\n .from(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.id, id)))\n .limit(1);\n return row ?? null;\n }\n\n async findOrgUsersByIds(orgId: string, ids: string[]): Promise<OrgUser[]> {\n if (ids.length === 0) {\n return [];\n }\n const rows = await this.db\n .select()\n .from(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), inArray(orgUsers.id, ids)));\n return rows;\n }\n\n async createOrgUser(input: CreateOrgUserInput): Promise<OrgUser> {\n try {\n const [row] = await this.db\n .insert(orgUsers)\n .values({\n orgId: input.orgId,\n userId: input.userId,\n status: input.status ?? \"active\",\n })\n .returning();\n if (!row) {\n throw new Error(\"failed to insert org user\");\n }\n return row;\n } catch (err) {\n if (isUniqueViolation(err)) {\n throw new ConflictError(\"That account already belongs to this organization\");\n }\n throw err;\n }\n }\n\n async updateOrgUser(\n orgId: string,\n id: string,\n patch: UpdateOrgUserInput,\n ): Promise<OrgUser | null> {\n const [row] = await this.db\n .update(orgUsers)\n .set({\n ...(patch.status !== undefined && { status: patch.status }),\n })\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.id, id)))\n .returning();\n return row ?? null;\n }\n\n async deleteOrgUser(orgId: string, id: string): Promise<OrgUser | null> {\n try {\n const [row] = await this.db\n .delete(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.id, id)))\n .returning();\n return row ?? null;\n } catch (err) {\n if (pgErrorFields(err)?.code === \"23503\") {\n throw Object.assign(\n new ConflictError(\n \"This person has written posts, comments or messages and cannot be deleted\",\n ),\n { cause: err },\n );\n }\n throw err;\n }\n }\n}\ntranslateDbErrors(DrizzleOrganizationsRepository);\n"],"mappings":";;;;;;AAoBA,MAAM,kBAAkB;CAAC;CAAW;CAAY;CAAY;AAAU;AAEtE,MAAM,YAAY,MACf,gBAAsC,SAAS,CAAC,IAAK,IAAqB;AAE7E,SAAS,SAAS,KAA0C;CAC1D,OAAO;EACL,IAAI,IAAI;EACR,OAAO,IAAI;EACX,OAAO,IAAI;EACX,SAAS,IAAI;EACb,QAAQ,IAAI;EACZ,WAAW,IAAI;EACf,WAAW,IAAI;EACf,WAAW,IAAI;EACf,WAAW,IAAI;EACf,WAAW,IAAI;CACjB;AACF;AAEA,IAAa,iCAAb,MAA+E;CAE1D;CACA;CAFnB,YACE,IACA,SAAkC,YAClC;EAFiB,KAAA,KAAA;EACA,KAAA,SAAA;CAChB;CAEH,MAAM,OAAO,OAAkD;EAC7D,MAAM,CAAC,OAAO,MAAM,KAAK,GACtB,OAAO,aAAa,CAAC,CACrB,OAAO;GACN,YAAY,MAAM;GAClB,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,SAAS,MAAM;GACf,IAAI,MAAM;EACZ,CAAC,CAAC,CACD,UAAU;EACb,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,+BAA+B;EAEjD,OAAO;CACT;CAEA,MAAM,OAAO,IAAY,OAA8D;EACrF,MAAM,CAAC,OAAO,MAAM,KAAK,GACtB,OAAO,aAAa,CAAC,CACrB,IAAI;GAAE,MAAM,MAAM;GAAM,MAAM,MAAM;EAAK,CAAC,CAAC,CAC3C,MAAM,GAAG,cAAc,IAAI,EAAE,CAAC,CAAC,CAC/B,UAAU;EACb,OAAO,OAA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"}
|
|
1
|
+
{"version":3,"file":"organizations.js","names":[],"sources":["../../src/repositories/organizations.ts"],"sourcesContent":["// organizations — Drizzle repository (implements the core outbound port).\nimport { and, asc, eq, inArray, sql } from \"drizzle-orm\";\nimport type { NodePgDatabase } from \"drizzle-orm/node-postgres\";\nimport type {\n CreateOrgUserInput,\n Invite,\n NewInviteRow,\n NewOrganizationRow,\n Organization,\n OrganizationMetadata,\n OrganizationsRepository,\n OrgUser,\n UpdateOrganizationInput,\n UpdateOrgUserInput,\n} from \"@headless-lms/core/organizations\";\nimport { invites, organizations, orgUsers } from \"../schema/organizations.js\";\nimport type { Logger } from \"@headless-lms/core/shared/ports\";\nimport { noopLogger } from \"@headless-lms/core/shared/logger\";\nimport { ConflictError } from \"@headless-lms/core/shared/errors\";\nimport { isUniqueViolation, pgErrorFields, translateDbErrors } from \"./pg-errors.js\";\n\nconst INVITE_STATUSES = [\"pending\", \"accepted\", \"rejected\", \"canceled\"] as const;\ntype InviteStatus = (typeof INVITE_STATUSES)[number];\nconst toStatus = (s: string): InviteStatus =>\n (INVITE_STATUSES as readonly string[]).includes(s) ? (s as InviteStatus) : \"pending\";\n\nfunction toInvite(row: typeof invites.$inferSelect): Invite {\n return {\n id: row.id,\n orgId: row.orgId,\n email: row.email,\n roleKey: row.roleKey,\n status: row.status,\n invitedBy: row.invitedBy,\n tokenHash: row.tokenHash,\n expiresAt: row.expiresAt,\n createdAt: row.createdAt,\n updatedAt: row.updatedAt,\n };\n}\n\nexport class DrizzleOrganizationsRepository implements OrganizationsRepository {\n constructor(\n private readonly db: NodePgDatabase,\n private readonly logger: Logger = noopLogger,\n ) {}\n\n async create(input: NewOrganizationRow): Promise<Organization> {\n const [row] = await this.db\n .insert(organizations)\n .values({\n externalId: input.externalId,\n name: input.name,\n slug: input.slug,\n ownerId: input.ownerId,\n id: input.id,\n })\n .returning();\n if (!row) {\n throw new Error(\"failed to insert organization\");\n }\n return row!;\n }\n\n async update(id: string, input: UpdateOrganizationInput): Promise<Organization | null> {\n const [row] = await this.db\n .update(organizations)\n .set({ name: input.name, slug: input.slug })\n .where(eq(organizations.id, id))\n .returning();\n return row ?? null;\n }\n\n async delete(id: string): Promise<Organization> {\n const [row] = await this.db.delete(organizations).where(eq(organizations.id, id)).returning();\n\n if (!row) {\n throw new Error(\"failed to delete organization\");\n }\n return row;\n }\n\n async findById(id: string): Promise<Organization | null> {\n const [row] = await this.db.select().from(organizations).where(eq(organizations.id, id));\n return row ?? null;\n }\n\n async listIds(): Promise<string[]> {\n const rows = await this.db\n .select({ id: organizations.id })\n .from(organizations)\n .orderBy(asc(organizations.id));\n return rows.map((row) => row.id);\n }\n\n async findByExternalId(externalId: string): Promise<Organization | null> {\n const [row] = await this.db\n .select()\n .from(organizations)\n .where(eq(organizations.externalId, externalId))\n .limit(1);\n return row ?? null;\n }\n\n async setMetadata(id: string, metadata: OrganizationMetadata): Promise<Organization> {\n const [row] = await this.db\n .update(organizations)\n .set({ metadata })\n .where(eq(organizations.id, id))\n .returning();\n if (!row) {\n throw new Error(\"failed to update organization\");\n }\n return row;\n }\n\n async findBySlug(slug: string): Promise<Organization | null> {\n const [row] = await this.db\n .select()\n .from(organizations)\n .where(eq(organizations.slug, slug))\n .limit(1);\n return row ?? null;\n }\n\n async upsertPendingInvite(orgId: string, input: NewInviteRow): Promise<Invite> {\n const [row] = await this.db\n .insert(invites)\n .values({\n orgId,\n email: input.email,\n roleKey: input.roleKey,\n status: \"pending\",\n invitedBy: input.invitedBy,\n tokenHash: input.tokenHash,\n expiresAt: input.expiresAt,\n })\n .onConflictDoUpdate({\n target: [invites.orgId, invites.email],\n targetWhere: sql`${invites.status} = 'pending'`,\n set: {\n roleKey: input.roleKey,\n invitedBy: input.invitedBy,\n tokenHash: input.tokenHash,\n expiresAt: input.expiresAt,\n },\n })\n .returning();\n if (!row) {\n throw new Error(\"failed to upsert invite\");\n }\n return toInvite(row);\n }\n\n async setInviteStatus(orgId: string, id: string, status: string): Promise<Invite | null> {\n const [row] = await this.db\n .update(invites)\n .set({ status: toStatus(status) })\n .where(and(eq(invites.orgId, orgId), eq(invites.id, id)))\n .returning();\n return row ? toInvite(row) : null;\n }\n\n async setInviteRole(\n orgId: string,\n id: string,\n roleKey: string,\n invitedBy: string,\n ): Promise<Invite | null> {\n const [row] = await this.db\n .update(invites)\n .set({ roleKey, invitedBy })\n .where(and(eq(invites.orgId, orgId), eq(invites.id, id), eq(invites.status, \"pending\")))\n .returning();\n return row ? toInvite(row) : null;\n }\n\n async findInviteByTokenHash(tokenHash: string): Promise<Invite | null> {\n const [row] = await this.db\n .select()\n .from(invites)\n .where(eq(invites.tokenHash, tokenHash))\n .limit(1);\n return row ? toInvite(row) : null;\n }\n\n async findPendingInvite(orgId: string, email: string): Promise<Invite | null> {\n const [row] = await this.db\n .select()\n .from(invites)\n .where(\n and(\n eq(invites.orgId, orgId),\n sql`lower(${invites.email}) = lower(${email})`,\n eq(invites.status, \"pending\"),\n ),\n )\n .limit(1);\n return row ? toInvite(row) : null;\n }\n\n async setInviteToken(\n orgId: string,\n id: string,\n tokenHash: string,\n expiresAt: Date,\n invitedBy: string,\n ): Promise<Invite | null> {\n const [row] = await this.db\n .update(invites)\n .set({ tokenHash, expiresAt, invitedBy })\n .where(and(eq(invites.orgId, orgId), eq(invites.id, id), eq(invites.status, \"pending\")))\n .returning();\n return row ? toInvite(row) : null;\n }\n\n async findOrgUser(orgId: string, userId: string): Promise<OrgUser | null> {\n const [row] = await this.db\n .select()\n .from(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.userId, userId)))\n .limit(1);\n return row ?? null;\n }\n\n async findOrgUsersByUser(userId: string): Promise<OrgUser[]> {\n const rows = await this.db\n .select()\n .from(orgUsers)\n .where(eq(orgUsers.userId, userId))\n .orderBy(orgUsers.createdAt);\n return rows;\n }\n\n async findOrgUserById(orgId: string, id: string): Promise<OrgUser | null> {\n const [row] = await this.db\n .select()\n .from(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.id, id)))\n .limit(1);\n return row ?? null;\n }\n\n async findOrgUsersByIds(orgId: string, ids: string[]): Promise<OrgUser[]> {\n if (ids.length === 0) {\n return [];\n }\n const rows = await this.db\n .select()\n .from(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), inArray(orgUsers.id, ids)));\n return rows;\n }\n\n async createOrgUser(input: CreateOrgUserInput): Promise<OrgUser> {\n try {\n const [row] = await this.db\n .insert(orgUsers)\n .values({\n orgId: input.orgId,\n userId: input.userId,\n status: input.status ?? \"active\",\n })\n .returning();\n if (!row) {\n throw new Error(\"failed to insert org user\");\n }\n return row;\n } catch (err) {\n if (isUniqueViolation(err)) {\n throw new ConflictError(\"That account already belongs to this organization\");\n }\n throw err;\n }\n }\n\n async updateOrgUser(\n orgId: string,\n id: string,\n patch: UpdateOrgUserInput,\n ): Promise<OrgUser | null> {\n const [row] = await this.db\n .update(orgUsers)\n .set({\n ...(patch.status !== undefined && { status: patch.status }),\n })\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.id, id)))\n .returning();\n return row ?? null;\n }\n\n async deleteOrgUser(orgId: string, id: string): Promise<OrgUser | null> {\n try {\n const [row] = await this.db\n .delete(orgUsers)\n .where(and(eq(orgUsers.orgId, orgId), eq(orgUsers.id, id)))\n .returning();\n return row ?? null;\n } catch (err) {\n if (pgErrorFields(err)?.code === \"23503\") {\n throw Object.assign(\n new ConflictError(\n \"This person has written posts, comments or messages and cannot be deleted\",\n ),\n { cause: err },\n );\n }\n throw err;\n }\n }\n}\ntranslateDbErrors(DrizzleOrganizationsRepository);\n"],"mappings":";;;;;;AAqBA,MAAM,kBAAkB;CAAC;CAAW;CAAY;CAAY;AAAU;AAEtE,MAAM,YAAY,MACf,gBAAsC,SAAS,CAAC,IAAK,IAAqB;AAE7E,SAAS,SAAS,KAA0C;CAC1D,OAAO;EACL,IAAI,IAAI;EACR,OAAO,IAAI;EACX,OAAO,IAAI;EACX,SAAS,IAAI;EACb,QAAQ,IAAI;EAC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AC,CAChB,OAAO;IACN,OAAO,MAAM;IACb,QAAQ,MAAM;IACd,QAAQ,MAAM,UAAU;GAC1B,CAAC,CAAC,CACD,UAAU;GACb,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,2BAA2B;GAE7C,OAAO;EACT,SAAS,KAAK;GACZ,IAAI,kBAAkB,GAAG,GACvB,MAAM,IAAI,cAAc,mDAAmD;GAE7E,MAAM;EACR;CACF;CAEA,MAAM,cACJ,OACA,IACA,OACyB;EACzB,MAAM,CAAC,OAAO,MAAM,KAAK,GACtB,OAAO,QAAQ,CAAC,CAChB,IAAI,EACH,GAAI,MAAM,WAAW,KAAA,KAAa,EAAE,QAAQ,MAAM,OAAO,EAC3D,CAAC,CAAC,CACD,MAAM,IAAI,GAAG,SAAS,OAAO,KAAK,GAAG,GAAG,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,CAC1D,UAAU;EACb,OAAO,OAAO;CAChB;CAEA,MAAM,cAAc,OAAe,IAAqC;EACtE,IAAI;GACF,MAAM,CAAC,OAAO,MAAM,KAAK,GACtB,OAAO,QAAQ,CAAC,CAChB,MAAM,IAAI,GAAG,SAAS,OAAO,KAAK,GAAG,GAAG,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,CAC1D,UAAU;GACb,OAAO,OAAO;EAChB,SAAS,KAAK;GACZ,IAAI,cAAc,GAAG,CAAC,EAAE,SAAS,SAC/B,MAAM,OAAO,OACX,IAAI,cACF,2EACF,GACA,EAAE,OAAO,IAAI,CACf;GAEF,MAAM;EACR;CACF;AACF;AACA,kBAAkB,8BAA8B"}
|
|
@@ -597,7 +597,6 @@ declare const notifications: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
597
597
|
identity: undefined;
|
|
598
598
|
generated: undefined;
|
|
599
599
|
}, {}, {
|
|
600
|
-
$type: Reason[];
|
|
601
600
|
size: undefined;
|
|
602
601
|
baseBuilder: import("drizzle-orm/pg-core").PgColumnBuilder<{
|
|
603
602
|
name: "reasons";
|
|
@@ -607,6 +606,7 @@ declare const notifications: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
607
606
|
enumValues: [string, ...string[]];
|
|
608
607
|
driverParam: string;
|
|
609
608
|
}, {}, {}, import("drizzle-orm").ColumnBuilderExtraConfig>;
|
|
609
|
+
$type: Reason[];
|
|
610
610
|
}>;
|
|
611
611
|
matchedReason: import("drizzle-orm/pg-core").PgColumn<{
|
|
612
612
|
name: "matched_reason";
|
package/dist/schema/content.d.ts
CHANGED
|
@@ -1993,6 +1993,57 @@ declare const spaces: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
1993
1993
|
requireReview: boolean;
|
|
1994
1994
|
};
|
|
1995
1995
|
}>;
|
|
1996
|
+
coverAssetId: import("drizzle-orm/pg-core").PgColumn<{
|
|
1997
|
+
name: "cover_asset_id";
|
|
1998
|
+
tableName: "spaces";
|
|
1999
|
+
dataType: "string";
|
|
2000
|
+
columnType: "PgText";
|
|
2001
|
+
data: string;
|
|
2002
|
+
driverParam: string;
|
|
2003
|
+
notNull: false;
|
|
2004
|
+
hasDefault: false;
|
|
2005
|
+
isPrimaryKey: false;
|
|
2006
|
+
isAutoincrement: false;
|
|
2007
|
+
hasRuntimeDefault: false;
|
|
2008
|
+
enumValues: [string, ...string[]];
|
|
2009
|
+
baseColumn: never;
|
|
2010
|
+
identity: undefined;
|
|
2011
|
+
generated: undefined;
|
|
2012
|
+
}, {}, {}>;
|
|
2013
|
+
backgroundAssetId: import("drizzle-orm/pg-core").PgColumn<{
|
|
2014
|
+
name: "background_asset_id";
|
|
2015
|
+
tableName: "spaces";
|
|
2016
|
+
dataType: "string";
|
|
2017
|
+
columnType: "PgText";
|
|
2018
|
+
data: string;
|
|
2019
|
+
driverParam: string;
|
|
2020
|
+
notNull: false;
|
|
2021
|
+
hasDefault: false;
|
|
2022
|
+
isPrimaryKey: false;
|
|
2023
|
+
isAutoincrement: false;
|
|
2024
|
+
hasRuntimeDefault: false;
|
|
2025
|
+
enumValues: [string, ...string[]];
|
|
2026
|
+
baseColumn: never;
|
|
2027
|
+
identity: undefined;
|
|
2028
|
+
generated: undefined;
|
|
2029
|
+
}, {}, {}>;
|
|
2030
|
+
iconAssetId: import("drizzle-orm/pg-core").PgColumn<{
|
|
2031
|
+
name: "icon_asset_id";
|
|
2032
|
+
tableName: "spaces";
|
|
2033
|
+
dataType: "string";
|
|
2034
|
+
columnType: "PgText";
|
|
2035
|
+
data: string;
|
|
2036
|
+
driverParam: string;
|
|
2037
|
+
notNull: false;
|
|
2038
|
+
hasDefault: false;
|
|
2039
|
+
isPrimaryKey: false;
|
|
2040
|
+
isAutoincrement: false;
|
|
2041
|
+
hasRuntimeDefault: false;
|
|
2042
|
+
enumValues: [string, ...string[]];
|
|
2043
|
+
baseColumn: never;
|
|
2044
|
+
identity: undefined;
|
|
2045
|
+
generated: undefined;
|
|
2046
|
+
}, {}, {}>;
|
|
1996
2047
|
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
1997
2048
|
name: "created_at";
|
|
1998
2049
|
tableName: "spaces";
|
package/dist/schema/content.js
CHANGED
|
@@ -318,6 +318,9 @@ const spaces = pgTable("spaces", {
|
|
|
318
318
|
reactions: true,
|
|
319
319
|
requireReview: false
|
|
320
320
|
}),
|
|
321
|
+
coverAssetId: text("cover_asset_id"),
|
|
322
|
+
backgroundAssetId: text("background_asset_id"),
|
|
323
|
+
iconAssetId: text("icon_asset_id"),
|
|
321
324
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
322
325
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
|
|
323
326
|
}, (t) => ({
|
|
@@ -328,7 +331,22 @@ const spaces = pgTable("spaces", {
|
|
|
328
331
|
foreignColumns: [communities.orgId, communities.id]
|
|
329
332
|
}).onDelete("cascade"),
|
|
330
333
|
capacityCk: check("spaces_capacity_check", sql`${t.capacity} is null or ${t.accessRule} <> 'all_members'`),
|
|
331
|
-
orderIdx: index("spaces_order_idx").on(t.orgId, t.communityId, t.seq)
|
|
334
|
+
orderIdx: index("spaces_order_idx").on(t.orgId, t.communityId, t.seq),
|
|
335
|
+
coverAssetFk: foreignKey({
|
|
336
|
+
columns: [t.orgId, t.coverAssetId],
|
|
337
|
+
foreignColumns: [assets.orgId, assets.id]
|
|
338
|
+
}),
|
|
339
|
+
backgroundAssetFk: foreignKey({
|
|
340
|
+
columns: [t.orgId, t.backgroundAssetId],
|
|
341
|
+
foreignColumns: [assets.orgId, assets.id]
|
|
342
|
+
}),
|
|
343
|
+
iconAssetFk: foreignKey({
|
|
344
|
+
columns: [t.orgId, t.iconAssetId],
|
|
345
|
+
foreignColumns: [assets.orgId, assets.id]
|
|
346
|
+
}),
|
|
347
|
+
coverIdx: index("spaces_cover_idx").on(t.orgId, t.coverAssetId),
|
|
348
|
+
backgroundIdx: index("spaces_background_idx").on(t.orgId, t.backgroundAssetId),
|
|
349
|
+
iconIdx: index("spaces_icon_idx").on(t.orgId, t.iconAssetId)
|
|
332
350
|
}));
|
|
333
351
|
const spaceTopics = pgTable("space_topics", {
|
|
334
352
|
orgId: text("org_id").notNull().references(() => organizations.id),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","names":[],"sources":["../../src/schema/content.ts"],"sourcesContent":["import {\n pgTable,\n text,\n integer,\n jsonb,\n timestamp,\n primaryKey,\n foreignKey,\n unique,\n index,\n check,\n} from \"drizzle-orm/pg-core\";\nimport { sql } from \"drizzle-orm\";\nimport type {\n Activity,\n ActivityAsset,\n Bundle,\n BundleItem,\n Community,\n ContentItem,\n Course,\n Download,\n DownloadAsset,\n Event,\n EventAsset,\n Module,\n Space,\n SpaceLink,\n SpaceTopic,\n} from \"@headless-lms/core/schemas\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { organizations } from \"./organizations.js\";\nimport { assets } from \"./assets.js\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\n// Bundles.\nexport const bundles = pgTable(\n \"bundles\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\").notNull(),\n name: text(\"name\").notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n typeUq: unique().on(t.orgId, t.id, t.name),\n }),\n);\n\n// The content registry one row per piece of content, any\n// type. this is so we can PK to content items of different types.\nexport const contentItems = pgTable(\n \"content_items\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\").notNull(),\n type: text(\"type\", { enum: [\"course\", \"download\", \"community\", \"event\"] }).notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // FK target for type-pinned references from concrete content tables.\n typeUq: unique().on(t.orgId, t.id, t.type),\n // Widened per new content type.\n typeCk: check(\n \"content_items_type_check\",\n sql`${t.type} in ('course', 'download', 'community', 'event')`,\n ),\n }),\n);\n\n// The content registry one row per piece of content, any\n// type. this is so we can PK to content items of different types.\nexport const bundleItems = pgTable(\n \"bundle_items\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n bundleId: text(\"bundle_id\").notNull(),\n contentId: text(\"content_id\").notNull(),\n\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.bundleId, t.contentId] }),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.contentId],\n foreignColumns: [contentItems.orgId, contentItems.id],\n }).onDelete(\"cascade\"),\n bundleFk: foreignKey({\n columns: [t.orgId, t.bundleId],\n foreignColumns: [bundles.orgId, bundles.id],\n }).onDelete(\"cascade\"),\n contentIdx: index(\"bundle_items_content_idx\").on(t.orgId, t.contentId),\n }),\n);\n\nexport const courses = pgTable(\n \"courses\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"course\")),\n // Pinned to 'course' so the composite FK below cannot attach this row to a\n // registry row of another content type.\n type: text(\"type\")\n .$type<Course[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'course'`),\n title: text(\"title\").notNull(),\n slug: text(\"slug\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n status: text(\"status\", { enum: [\"draft\", \"published\"] })\n .notNull()\n .default(\"draft\"),\n category: text(\"category\").notNull().default(\"\"),\n // Media-library asset rendered as the course's cover. Null = no cover.\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n slugUq: unique().on(t.orgId, t.slug),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n // Restrictive, like `activity_assets.assetFk` — the asset is owned by the\n // assets domain and must be unlinked before it can be deleted. MATCH SIMPLE\n // means the constraint is skipped entirely while the thumbnail is null.\n thumbnailAssetFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"courses_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n }),\n);\n\nexport const modules = pgTable(\n \"modules\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"module\")),\n courseId: text(\"course_id\").notNull(),\n title: text(\"title\").notNull(),\n seq: integer(\"seq\").notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // Modules are part of the course aggregate: deleting the course deletes them.\n courseFk: foreignKey({\n columns: [t.orgId, t.courseId],\n foreignColumns: [courses.orgId, courses.id],\n }).onDelete(\"cascade\"),\n // FK target for the course-pinned reference from activities.\n courseUq: unique().on(t.orgId, t.id, t.courseId),\n }),\n);\n\n// The leaf, directly in a module. Uniform content: seq + opaque settings blob.\nexport const activities = pgTable(\n \"activities\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"activity\")),\n moduleId: text(\"module_id\").notNull(),\n // Denormalised from the module: the course an activity belongs to is asked\n // for far more often than its module (progress, discussion, entitlements),\n // and the FK below pins the pair, so it cannot disagree with the module.\n courseId: text(\"course_id\").notNull(),\n seq: integer(\"seq\").notNull(),\n // Opaque per-activity blob: title, type, body, completion rule — whatever the\n // content needs. Assets are the one thing kept out of the blob.\n settings: jsonb(\"settings\").$type<Activity[\"settings\"]>(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // Course-pinned, like `courses.contentItemFk`: the module reference carries\n // `course_id`, so an activity whose stored course disagrees with its\n // module's is rejected by the database rather than silently rotting.\n moduleFk: foreignKey({\n columns: [t.orgId, t.moduleId, t.courseId],\n foreignColumns: [modules.orgId, modules.id, modules.courseId],\n }).onDelete(\"cascade\"),\n seqUq: unique().on(t.orgId, t.moduleId, t.seq),\n }),\n);\n\n// activity ↔ asset: many-to-many (an activity uses many assets; an asset can be\n// reused by many activities). Assets owned by the assets domain, tracked here.\nexport const activityAssets = pgTable(\n \"activity_assets\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"activityAsset\")),\n activityId: text(\"activity_id\").notNull(),\n assetId: text(\"asset_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // The link cascades with its activity; the asset itself is owned by the\n // assets domain and survives (assetFk stays restrictive).\n activityFk: foreignKey({\n columns: [t.orgId, t.activityId],\n foreignColumns: [activities.orgId, activities.id],\n }).onDelete(\"cascade\"),\n assetFk: foreignKey({\n columns: [t.orgId, t.assetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n activityAssetUq: unique().on(t.orgId, t.activityId, t.assetId),\n assetIdx: index(\"activity_assets_asset_idx\").on(t.orgId, t.assetId),\n }),\n);\n\n// A download: an ordered set of media-library assets. Shares its PK with a\n// registry row (same id) via the type-pinned composite FK, exactly like courses.\nexport const downloads = pgTable(\n \"downloads\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"download\")),\n // Pinned to 'download' so the composite FK below cannot attach this row to\n // a registry row of another content type.\n type: text(\"type\")\n .$type<Download[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'download'`),\n title: text(\"title\").notNull(),\n slug: text(\"slug\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n status: text(\"status\", { enum: [\"draft\", \"published\"] })\n .notNull()\n .default(\"draft\"),\n category: text(\"category\").notNull().default(\"\"),\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n slugUq: unique().on(t.orgId, t.slug),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n // Restrictive: a thumbnail in use blocks deleting the asset.\n thumbnailFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"downloads_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n }),\n);\n\n// download ↔ asset: the ordered set. Mirrors activity_assets one level\n// shallower — a download has no intermediate structure.\nexport const downloadAssets = pgTable(\n \"download_assets\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"downloadAsset\")),\n downloadId: text(\"download_id\").notNull(),\n assetId: text(\"asset_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n // Author's label; null falls back to the asset's filename.\n displayName: text(\"display_name\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // The link cascades with its download; the asset is owned by the assets\n // domain and survives (assetFk stays restrictive).\n downloadFk: foreignKey({\n columns: [t.orgId, t.downloadId],\n foreignColumns: [downloads.orgId, downloads.id],\n }).onDelete(\"cascade\"),\n assetFk: foreignKey({\n columns: [t.orgId, t.assetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n // Lets delivery key on asset_id rather than the link row id.\n downloadAssetUq: unique().on(t.orgId, t.downloadId, t.assetId),\n assetIdx: index(\"download_assets_asset_idx\").on(t.orgId, t.assetId),\n }),\n);\n\nexport const events = pgTable(\n \"events\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"contentEvent\")),\n type: text(\"type\")\n .$type<Event[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'event'`),\n title: text(\"title\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n status: text(\"status\", { enum: [\"draft\", \"published\", \"canceled\"] })\n .notNull()\n .default(\"draft\"),\n startsAt: timestamp(\"starts_at\", { withTimezone: true }).notNull(),\n endsAt: timestamp(\"ends_at\", { withTimezone: true }).notNull(),\n timeZone: text(\"time_zone\").notNull(),\n location: jsonb(\"location\")\n .$type<Event[\"location\"]>()\n .notNull()\n .default({ venue: null, online: null }),\n recording: jsonb(\"recording\").$type<Event[\"recording\"]>(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n thumbnailAssetFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"events_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n startsIdx: index(\"events_status_starts_idx\").on(t.orgId, t.status, t.startsAt),\n timesCk: check(\"events_times_check\", sql`${t.endsAt} > ${t.startsAt}`),\n }),\n);\n\nexport const eventAssets = pgTable(\n \"event_assets\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"eventAsset\")),\n eventId: text(\"event_id\").notNull(),\n assetId: text(\"asset_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n displayName: text(\"display_name\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n eventFk: foreignKey({\n columns: [t.orgId, t.eventId],\n foreignColumns: [events.orgId, events.id],\n }).onDelete(\"cascade\"),\n assetFk: foreignKey({\n columns: [t.orgId, t.assetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n eventAssetUq: unique().on(t.orgId, t.eventId, t.assetId),\n assetIdx: index(\"event_assets_asset_idx\").on(t.orgId, t.assetId),\n }),\n);\n\nexport const communities = pgTable(\n \"communities\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"community\")),\n type: text(\"type\")\n .$type<Community[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'community'`),\n title: text(\"title\").notNull(),\n slug: text(\"slug\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n status: text(\"status\", { enum: [\"draft\", \"published\"] })\n .notNull()\n .default(\"draft\"),\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n slugUq: unique().on(t.orgId, t.slug),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n thumbnailAssetFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"communities_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n }),\n);\n\nexport const spaces = pgTable(\n \"spaces\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"space\")),\n communityId: text(\"community_id\").notNull(),\n name: text(\"name\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n seq: integer(\"seq\").notNull(),\n accessRule: text(\"access_rule\", { enum: [\"all_members\", \"by_request\", \"by_invite\"] })\n .notNull()\n .default(\"all_members\"),\n capacity: integer(\"capacity\"),\n settings: jsonb(\"settings\")\n .$type<Space[\"settings\"]>()\n .notNull()\n .default({ comments: true, reactions: true, requireReview: false }),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n communityUq: unique().on(t.orgId, t.id, t.communityId),\n communityFk: foreignKey({\n columns: [t.orgId, t.communityId],\n foreignColumns: [communities.orgId, communities.id],\n }).onDelete(\"cascade\"),\n capacityCk: check(\n \"spaces_capacity_check\",\n sql`${t.capacity} is null or ${t.accessRule} <> 'all_members'`,\n ),\n orderIdx: index(\"spaces_order_idx\").on(t.orgId, t.communityId, t.seq),\n }),\n);\n\nexport const spaceTopics = pgTable(\n \"space_topics\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"topic\")),\n spaceId: text(\"space_id\").notNull(),\n name: text(\"name\").notNull(),\n seq: integer(\"seq\").notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n nameUq: unique().on(t.orgId, t.spaceId, t.name),\n spaceUq: unique().on(t.orgId, t.spaceId, t.id),\n spaceFk: foreignKey({\n columns: [t.orgId, t.spaceId],\n foreignColumns: [spaces.orgId, spaces.id],\n }).onDelete(\"cascade\"),\n }),\n);\n\nexport const spaceLinks = pgTable(\n \"space_links\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"spaceLink\")),\n spaceId: text(\"space_id\").notNull(),\n contentId: text(\"content_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n contentUq: unique().on(t.orgId, t.spaceId, t.contentId),\n spaceFk: foreignKey({\n columns: [t.orgId, t.spaceId],\n foreignColumns: [spaces.orgId, spaces.id],\n }).onDelete(\"cascade\"),\n contentFk: foreignKey({\n columns: [t.orgId, t.contentId],\n foreignColumns: [contentItems.orgId, contentItems.id],\n }).onDelete(\"cascade\"),\n contentIdx: index(\"space_links_content_idx\").on(t.orgId, t.contentId),\n }),\n);\n\ntype _BundlesDrift = Expect<NoDrift<typeof bundles.$inferSelect, Bundle>>;\ntype _BundleItemsDrift = Expect<NoDrift<typeof bundleItems.$inferSelect, BundleItem>>;\ntype _ContentItemsDrift = Expect<NoDrift<typeof contentItems.$inferSelect, ContentItem>>;\ntype _CoursesDrift = Expect<NoDrift<typeof courses.$inferSelect, Omit<Course, \"settings\">>>;\ntype _ModulesDrift = Expect<NoDrift<typeof modules.$inferSelect, Module>>;\ntype _ActivitiesDrift = Expect<NoDrift<typeof activities.$inferSelect, Activity>>;\ntype _ActivityAssetsDrift = Expect<NoDrift<typeof activityAssets.$inferSelect, ActivityAsset>>;\ntype _DownloadsDrift = Expect<NoDrift<typeof downloads.$inferSelect, Download>>;\ntype _DownloadAssetsDrift = Expect<NoDrift<typeof downloadAssets.$inferSelect, DownloadAsset>>;\ntype _EventsDrift = Expect<NoDrift<typeof events.$inferSelect, Omit<Event, \"settings\">>>;\ntype _EventAssetsDrift = Expect<NoDrift<typeof eventAssets.$inferSelect, EventAsset>>;\ntype _CommunitiesDrift = Expect<\n NoDrift<typeof communities.$inferSelect, Omit<Community, \"settings\">>\n>;\ntype _SpacesDrift = Expect<NoDrift<typeof spaces.$inferSelect, Space>>;\ntype _SpaceTopicsDrift = Expect<NoDrift<typeof spaceTopics.$inferSelect, SpaceTopic>>;\ntype _SpaceLinksDrift = Expect<NoDrift<typeof spaceLinks.$inferSelect, SpaceLink>>;\n"],"mappings":";;;;;;AAoCA,MAAa,UAAU,QACrB,WACA;CACE,OAAO,KAAK,QAAQ,CAAC,CAClB,QAAQ,CAAC,CACT,iBAAiB,cAAc,EAAE;CACpC,IAAI,KAAK,IAAI,CAAC,CAAC,QAAQ;CACvB,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ;CAC3B,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW;CAChF,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CACvD,QAAQ,CAAC,CACT,WAAW,CAAC,CACZ,gCAAgB,IAAI,KAAK,CAAC;AAC/B,IACC,OAAO;CACN,IAAI,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;CAC3C,QAAQ,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI;AAC3C,EACF;AAI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,YAAY,CAAC,CAAC,QAAQ;CACtC,KAAK,QAAQ,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;CACvC,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW;CAChF,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CACvD,QAAQ,CAAC,CACT,WAAW,CAAC,CACZ,gCAAgB,IAAI,KAAK,CAAC;AAC/B,IACC,OAAO;CACN,IAAI,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;CAC3C,WAAW,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;CACtD,SAAS,WAAW;EAClB,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO;EAC5B,gBAAgB,CAAC,OAAO,OAAO,OAAO,EAAE;CAC1C,CAAC,CAAC,CAAC,SAAS,SAAS;CACrB,WAAW,WAAW;EACpB,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS;EAC9B,gBAAgB,CAAC,aAAa,OAAO,aAAa,EAAE;CACtD,CAAC,CAAC,CAAC,SAAS,SAAS;CACrB,YAAY,MAAM,yBAAyB,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS;AACtE,EACF"}
|
|
1
|
+
{"version":3,"file":"content.js","names":[],"sources":["../../src/schema/content.ts"],"sourcesContent":["import {\n pgTable,\n text,\n integer,\n jsonb,\n timestamp,\n primaryKey,\n foreignKey,\n unique,\n index,\n check,\n} from \"drizzle-orm/pg-core\";\nimport { sql } from \"drizzle-orm\";\nimport type {\n Activity,\n ActivityAsset,\n Bundle,\n BundleItem,\n Community,\n ContentItem,\n Course,\n Download,\n DownloadAsset,\n Event,\n EventAsset,\n Module,\n Space,\n SpaceLink,\n SpaceTopic,\n} from \"@headless-lms/core/schemas\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { organizations } from \"./organizations.js\";\nimport { assets } from \"./assets.js\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\n// Bundles.\nexport const bundles = pgTable(\n \"bundles\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\").notNull(),\n name: text(\"name\").notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n typeUq: unique().on(t.orgId, t.id, t.name),\n }),\n);\n\n// The content registry one row per piece of content, any\n// type. this is so we can PK to content items of different types.\nexport const contentItems = pgTable(\n \"content_items\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\").notNull(),\n type: text(\"type\", { enum: [\"course\", \"download\", \"community\", \"event\"] }).notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // FK target for type-pinned references from concrete content tables.\n typeUq: unique().on(t.orgId, t.id, t.type),\n // Widened per new content type.\n typeCk: check(\n \"content_items_type_check\",\n sql`${t.type} in ('course', 'download', 'community', 'event')`,\n ),\n }),\n);\n\n// The content registry one row per piece of content, any\n// type. this is so we can PK to content items of different types.\nexport const bundleItems = pgTable(\n \"bundle_items\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n bundleId: text(\"bundle_id\").notNull(),\n contentId: text(\"content_id\").notNull(),\n\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.bundleId, t.contentId] }),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.contentId],\n foreignColumns: [contentItems.orgId, contentItems.id],\n }).onDelete(\"cascade\"),\n bundleFk: foreignKey({\n columns: [t.orgId, t.bundleId],\n foreignColumns: [bundles.orgId, bundles.id],\n }).onDelete(\"cascade\"),\n contentIdx: index(\"bundle_items_content_idx\").on(t.orgId, t.contentId),\n }),\n);\n\nexport const courses = pgTable(\n \"courses\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"course\")),\n // Pinned to 'course' so the composite FK below cannot attach this row to a\n // registry row of another content type.\n type: text(\"type\")\n .$type<Course[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'course'`),\n title: text(\"title\").notNull(),\n slug: text(\"slug\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n status: text(\"status\", { enum: [\"draft\", \"published\"] })\n .notNull()\n .default(\"draft\"),\n category: text(\"category\").notNull().default(\"\"),\n // Media-library asset rendered as the course's cover. Null = no cover.\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n slugUq: unique().on(t.orgId, t.slug),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n // Restrictive, like `activity_assets.assetFk` — the asset is owned by the\n // assets domain and must be unlinked before it can be deleted. MATCH SIMPLE\n // means the constraint is skipped entirely while the thumbnail is null.\n thumbnailAssetFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"courses_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n }),\n);\n\nexport const modules = pgTable(\n \"modules\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"module\")),\n courseId: text(\"course_id\").notNull(),\n title: text(\"title\").notNull(),\n seq: integer(\"seq\").notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // Modules are part of the course aggregate: deleting the course deletes them.\n courseFk: foreignKey({\n columns: [t.orgId, t.courseId],\n foreignColumns: [courses.orgId, courses.id],\n }).onDelete(\"cascade\"),\n // FK target for the course-pinned reference from activities.\n courseUq: unique().on(t.orgId, t.id, t.courseId),\n }),\n);\n\n// The leaf, directly in a module. Uniform content: seq + opaque settings blob.\nexport const activities = pgTable(\n \"activities\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"activity\")),\n moduleId: text(\"module_id\").notNull(),\n // Denormalised from the module: the course an activity belongs to is asked\n // for far more often than its module (progress, discussion, entitlements),\n // and the FK below pins the pair, so it cannot disagree with the module.\n courseId: text(\"course_id\").notNull(),\n seq: integer(\"seq\").notNull(),\n // Opaque per-activity blob: title, type, body, completion rule — whatever the\n // content needs. Assets are the one thing kept out of the blob.\n settings: jsonb(\"settings\").$type<Activity[\"settings\"]>(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // Course-pinned, like `courses.contentItemFk`: the module reference carries\n // `course_id`, so an activity whose stored course disagrees with its\n // module's is rejected by the database rather than silently rotting.\n moduleFk: foreignKey({\n columns: [t.orgId, t.moduleId, t.courseId],\n foreignColumns: [modules.orgId, modules.id, modules.courseId],\n }).onDelete(\"cascade\"),\n seqUq: unique().on(t.orgId, t.moduleId, t.seq),\n }),\n);\n\n// activity ↔ asset: many-to-many (an activity uses many assets; an asset can be\n// reused by many activities). Assets owned by the assets domain, tracked here.\nexport const activityAssets = pgTable(\n \"activity_assets\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"activityAsset\")),\n activityId: text(\"activity_id\").notNull(),\n assetId: text(\"asset_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // The link cascades with its activity; the asset itself is owned by the\n // assets domain and survives (assetFk stays restrictive).\n activityFk: foreignKey({\n columns: [t.orgId, t.activityId],\n foreignColumns: [activities.orgId, activities.id],\n }).onDelete(\"cascade\"),\n assetFk: foreignKey({\n columns: [t.orgId, t.assetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n activityAssetUq: unique().on(t.orgId, t.activityId, t.assetId),\n assetIdx: index(\"activity_assets_asset_idx\").on(t.orgId, t.assetId),\n }),\n);\n\n// A download: an ordered set of media-library assets. Shares its PK with a\n// registry row (same id) via the type-pinned composite FK, exactly like courses.\nexport const downloads = pgTable(\n \"downloads\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"download\")),\n // Pinned to 'download' so the composite FK below cannot attach this row to\n // a registry row of another content type.\n type: text(\"type\")\n .$type<Download[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'download'`),\n title: text(\"title\").notNull(),\n slug: text(\"slug\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n status: text(\"status\", { enum: [\"draft\", \"published\"] })\n .notNull()\n .default(\"draft\"),\n category: text(\"category\").notNull().default(\"\"),\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n slugUq: unique().on(t.orgId, t.slug),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n // Restrictive: a thumbnail in use blocks deleting the asset.\n thumbnailFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"downloads_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n }),\n);\n\n// download ↔ asset: the ordered set. Mirrors activity_assets one level\n// shallower — a download has no intermediate structure.\nexport const downloadAssets = pgTable(\n \"download_assets\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"downloadAsset\")),\n downloadId: text(\"download_id\").notNull(),\n assetId: text(\"asset_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n // Author's label; null falls back to the asset's filename.\n displayName: text(\"display_name\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // The link cascades with its download; the asset is owned by the assets\n // domain and survives (assetFk stays restrictive).\n downloadFk: foreignKey({\n columns: [t.orgId, t.downloadId],\n foreignColumns: [downloads.orgId, downloads.id],\n }).onDelete(\"cascade\"),\n assetFk: foreignKey({\n columns: [t.orgId, t.assetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n // Lets delivery key on asset_id rather than the link row id.\n downloadAssetUq: unique().on(t.orgId, t.downloadId, t.assetId),\n assetIdx: index(\"download_assets_asset_idx\").on(t.orgId, t.assetId),\n }),\n);\n\nexport const events = pgTable(\n \"events\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"contentEvent\")),\n type: text(\"type\")\n .$type<Event[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'event'`),\n title: text(\"title\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n status: text(\"status\", { enum: [\"draft\", \"published\", \"canceled\"] })\n .notNull()\n .default(\"draft\"),\n startsAt: timestamp(\"starts_at\", { withTimezone: true }).notNull(),\n endsAt: timestamp(\"ends_at\", { withTimezone: true }).notNull(),\n timeZone: text(\"time_zone\").notNull(),\n location: jsonb(\"location\")\n .$type<Event[\"location\"]>()\n .notNull()\n .default({ venue: null, online: null }),\n recording: jsonb(\"recording\").$type<Event[\"recording\"]>(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n thumbnailAssetFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"events_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n startsIdx: index(\"events_status_starts_idx\").on(t.orgId, t.status, t.startsAt),\n timesCk: check(\"events_times_check\", sql`${t.endsAt} > ${t.startsAt}`),\n }),\n);\n\nexport const eventAssets = pgTable(\n \"event_assets\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"eventAsset\")),\n eventId: text(\"event_id\").notNull(),\n assetId: text(\"asset_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n displayName: text(\"display_name\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n eventFk: foreignKey({\n columns: [t.orgId, t.eventId],\n foreignColumns: [events.orgId, events.id],\n }).onDelete(\"cascade\"),\n assetFk: foreignKey({\n columns: [t.orgId, t.assetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n eventAssetUq: unique().on(t.orgId, t.eventId, t.assetId),\n assetIdx: index(\"event_assets_asset_idx\").on(t.orgId, t.assetId),\n }),\n);\n\nexport const communities = pgTable(\n \"communities\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"community\")),\n type: text(\"type\")\n .$type<Community[\"type\"]>()\n .notNull()\n .generatedAlwaysAs(sql`'community'`),\n title: text(\"title\").notNull(),\n slug: text(\"slug\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n status: text(\"status\", { enum: [\"draft\", \"published\"] })\n .notNull()\n .default(\"draft\"),\n thumbnailAssetId: text(\"thumbnail_asset_id\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n slugUq: unique().on(t.orgId, t.slug),\n contentItemFk: foreignKey({\n columns: [t.orgId, t.id, t.type],\n foreignColumns: [contentItems.orgId, contentItems.id, contentItems.type],\n }).onDelete(\"cascade\"),\n thumbnailAssetFk: foreignKey({\n columns: [t.orgId, t.thumbnailAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n thumbnailIdx: index(\"communities_thumbnail_idx\").on(t.orgId, t.thumbnailAssetId),\n }),\n);\n\nexport const spaces = pgTable(\n \"spaces\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"space\")),\n communityId: text(\"community_id\").notNull(),\n name: text(\"name\").notNull(),\n description: text(\"description\").notNull().default(\"\"),\n seq: integer(\"seq\").notNull(),\n accessRule: text(\"access_rule\", { enum: [\"all_members\", \"by_request\", \"by_invite\"] })\n .notNull()\n .default(\"all_members\"),\n capacity: integer(\"capacity\"),\n settings: jsonb(\"settings\")\n .$type<Space[\"settings\"]>()\n .notNull()\n .default({ comments: true, reactions: true, requireReview: false }),\n coverAssetId: text(\"cover_asset_id\"),\n backgroundAssetId: text(\"background_asset_id\"),\n iconAssetId: text(\"icon_asset_id\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n communityUq: unique().on(t.orgId, t.id, t.communityId),\n communityFk: foreignKey({\n columns: [t.orgId, t.communityId],\n foreignColumns: [communities.orgId, communities.id],\n }).onDelete(\"cascade\"),\n capacityCk: check(\n \"spaces_capacity_check\",\n sql`${t.capacity} is null or ${t.accessRule} <> 'all_members'`,\n ),\n orderIdx: index(\"spaces_order_idx\").on(t.orgId, t.communityId, t.seq),\n coverAssetFk: foreignKey({\n columns: [t.orgId, t.coverAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n backgroundAssetFk: foreignKey({\n columns: [t.orgId, t.backgroundAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n iconAssetFk: foreignKey({\n columns: [t.orgId, t.iconAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n coverIdx: index(\"spaces_cover_idx\").on(t.orgId, t.coverAssetId),\n backgroundIdx: index(\"spaces_background_idx\").on(t.orgId, t.backgroundAssetId),\n iconIdx: index(\"spaces_icon_idx\").on(t.orgId, t.iconAssetId),\n }),\n);\n\nexport const spaceTopics = pgTable(\n \"space_topics\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"topic\")),\n spaceId: text(\"space_id\").notNull(),\n name: text(\"name\").notNull(),\n seq: integer(\"seq\").notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n nameUq: unique().on(t.orgId, t.spaceId, t.name),\n spaceUq: unique().on(t.orgId, t.spaceId, t.id),\n spaceFk: foreignKey({\n columns: [t.orgId, t.spaceId],\n foreignColumns: [spaces.orgId, spaces.id],\n }).onDelete(\"cascade\"),\n }),\n);\n\nexport const spaceLinks = pgTable(\n \"space_links\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"spaceLink\")),\n spaceId: text(\"space_id\").notNull(),\n contentId: text(\"content_id\").notNull(),\n seq: integer(\"seq\").notNull().default(0),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n contentUq: unique().on(t.orgId, t.spaceId, t.contentId),\n spaceFk: foreignKey({\n columns: [t.orgId, t.spaceId],\n foreignColumns: [spaces.orgId, spaces.id],\n }).onDelete(\"cascade\"),\n contentFk: foreignKey({\n columns: [t.orgId, t.contentId],\n foreignColumns: [contentItems.orgId, contentItems.id],\n }).onDelete(\"cascade\"),\n contentIdx: index(\"space_links_content_idx\").on(t.orgId, t.contentId),\n }),\n);\n\ntype _BundlesDrift = Expect<NoDrift<typeof bundles.$inferSelect, Bundle>>;\ntype _BundleItemsDrift = Expect<NoDrift<typeof bundleItems.$inferSelect, BundleItem>>;\ntype _ContentItemsDrift = Expect<NoDrift<typeof contentItems.$inferSelect, ContentItem>>;\ntype _CoursesDrift = Expect<NoDrift<typeof courses.$inferSelect, Omit<Course, \"settings\">>>;\ntype _ModulesDrift = Expect<NoDrift<typeof modules.$inferSelect, Module>>;\ntype _ActivitiesDrift = Expect<NoDrift<typeof activities.$inferSelect, Activity>>;\ntype _ActivityAssetsDrift = Expect<NoDrift<typeof activityAssets.$inferSelect, ActivityAsset>>;\ntype _DownloadsDrift = Expect<NoDrift<typeof downloads.$inferSelect, Download>>;\ntype _DownloadAssetsDrift = Expect<NoDrift<typeof downloadAssets.$inferSelect, DownloadAsset>>;\ntype _EventsDrift = Expect<NoDrift<typeof events.$inferSelect, Omit<Event, \"settings\">>>;\ntype _EventAssetsDrift = Expect<NoDrift<typeof eventAssets.$inferSelect, EventAsset>>;\ntype _CommunitiesDrift = Expect<\n NoDrift<typeof communities.$inferSelect, Omit<Community, \"settings\">>\n>;\ntype _SpacesDrift = Expect<NoDrift<typeof spaces.$inferSelect, Space>>;\ntype _SpaceTopicsDrift = Expect<NoDrift<typeof spaceTopics.$inferSelect, SpaceTopic>>;\ntype _SpaceLinksDrift = Expect<NoDrift<typeof spaceLinks.$inferSelect, SpaceLink>>;\n"],"mappings":";;;;;;AAoCA,MAAa,UAAU,QACrB,WACA;CACE,OAAO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,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;CACvC,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW;CAChF,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CACvD,QAAQ,CAAC,CACT,WAAW,CAAC,CACZ,gCAAgB,IAAI,KAAK,CAAC;AAC/B,IACC,OAAO;CACN,IAAI,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;CAC3C,WAAW,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;CACtD,SAAS,WAAW;EAClB,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO;EAC5B,gBAAgB,CAAC,OAAO,OAAO,OAAO,EAAE;CAC1C,CAAC,CAAC,CAAC,SAAS,SAAS;CACrB,WAAW,WAAW;EACpB,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS;EAC9B,gBAAgB,CAAC,aAAa,OAAO,aAAa,EAAE;CACtD,CAAC,CAAC,CAAC,SAAS,SAAS;CACrB,YAAY,MAAM,yBAAyB,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS;AACtE,EACF"}
|
|
@@ -180,7 +180,7 @@ declare const posts: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
180
180
|
tableName: "posts";
|
|
181
181
|
dataType: "string";
|
|
182
182
|
columnType: "PgText";
|
|
183
|
-
data: "pending" | "draft" | "
|
|
183
|
+
data: "pending" | "draft" | "published" | "scheduled" | "removed";
|
|
184
184
|
driverParam: string;
|
|
185
185
|
notNull: true;
|
|
186
186
|
hasDefault: true;
|
|
@@ -88,6 +88,25 @@ declare const organizations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
88
88
|
identity: undefined;
|
|
89
89
|
generated: undefined;
|
|
90
90
|
}, {}, {}>;
|
|
91
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
92
|
+
name: "metadata";
|
|
93
|
+
tableName: "organizations";
|
|
94
|
+
dataType: "json";
|
|
95
|
+
columnType: "PgJsonb";
|
|
96
|
+
data: Record<string, string>;
|
|
97
|
+
driverParam: unknown;
|
|
98
|
+
notNull: true;
|
|
99
|
+
hasDefault: true;
|
|
100
|
+
isPrimaryKey: false;
|
|
101
|
+
isAutoincrement: false;
|
|
102
|
+
hasRuntimeDefault: false;
|
|
103
|
+
enumValues: undefined;
|
|
104
|
+
baseColumn: never;
|
|
105
|
+
identity: undefined;
|
|
106
|
+
generated: undefined;
|
|
107
|
+
}, {}, {
|
|
108
|
+
$type: Record<string, string>;
|
|
109
|
+
}>;
|
|
91
110
|
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
92
111
|
name: "created_at";
|
|
93
112
|
tableName: "organizations";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { users } from "./identity.js";
|
|
2
2
|
import { sql } from "drizzle-orm";
|
|
3
|
-
import { pgTable, primaryKey, text, timestamp, unique, uniqueIndex } from "drizzle-orm/pg-core";
|
|
3
|
+
import { jsonb, pgTable, primaryKey, text, timestamp, unique, uniqueIndex } from "drizzle-orm/pg-core";
|
|
4
4
|
import { genId } from "@headless-lms/core/shared/id";
|
|
5
5
|
//#region src/schema/organizations.ts
|
|
6
6
|
const organizations = pgTable("organizations", {
|
|
@@ -9,6 +9,7 @@ const organizations = pgTable("organizations", {
|
|
|
9
9
|
name: text("name").notNull(),
|
|
10
10
|
slug: text("slug").notNull().unique(),
|
|
11
11
|
ownerId: text("owner_id").notNull().references(() => users.id),
|
|
12
|
+
metadata: jsonb("metadata").$type().notNull().default({}),
|
|
12
13
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13
14
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
|
|
14
15
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizations.js","names":[],"sources":["../../src/schema/organizations.ts"],"sourcesContent":["import { sql } from \"drizzle-orm\";\nimport {
|
|
1
|
+
{"version":3,"file":"organizations.js","names":[],"sources":["../../src/schema/organizations.ts"],"sourcesContent":["import { sql } from \"drizzle-orm\";\nimport {\n jsonb,\n pgTable,\n text,\n timestamp,\n primaryKey,\n unique,\n uniqueIndex,\n} from \"drizzle-orm/pg-core\";\nimport type {\n Invite,\n Organization,\n OrganizationMetadata,\n OrgUser,\n} from \"@headless-lms/core/schemas\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { users } from \"./identity.js\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\nexport const organizations = pgTable(\"organizations\", {\n id: text(\"id\")\n .primaryKey()\n .$defaultFn(() => genId(\"organization\")),\n // Links to the better-auth organization record.\n externalId: text(\"external_id\").unique(),\n name: text(\"name\").notNull(),\n slug: text(\"slug\").notNull().unique(),\n ownerId: text(\"owner_id\")\n .notNull()\n .references(() => users.id),\n metadata: jsonb(\"metadata\").$type<OrganizationMetadata>().notNull().default({}),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n});\n\n// A person's link to an organization\nexport const orgUsers = pgTable(\n \"org_users\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"orgUser\")),\n\n userId: text(\"user_id\")\n .notNull()\n .references(() => users.id),\n // 'invited' from the moment a person is invited until they accept.\n status: text(\"status\", { enum: [\"invited\", \"active\"] })\n .notNull()\n .default(\"active\"),\n\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n userUq: unique().on(t.orgId, t.userId),\n }),\n);\n\nexport const invites = pgTable(\n \"invites\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"invite\")),\n email: text(\"email\").notNull(),\n roleKey: text(\"role\").notNull().default(\"member\"),\n status: text(\"status\", {\n enum: [\"pending\", \"accepted\", \"rejected\", \"canceled\"],\n }).notNull(),\n invitedBy: text(\"invited_by\")\n .notNull()\n .references(() => users.id),\n tokenHash: text(\"token_hash\").unique(),\n expiresAt: timestamp(\"expires_at\", { withTimezone: true }),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n // One pending invite per (org, email) — the upsert's conflict target.\n pendingEmailUq: uniqueIndex(\"invites_pending_email_uq\")\n .on(t.orgId, t.email)\n .where(sql`${t.status} = 'pending'`),\n }),\n);\n\ntype _OrganizationsDrift = Expect<NoDrift<typeof organizations.$inferSelect, Organization>>;\ntype _OrgUsersDrift = Expect<NoDrift<typeof orgUsers.$inferSelect, OrgUser>>;\ntype _InvitesDrift = Expect<NoDrift<typeof invites.$inferSelect, Invite>>;\n"],"mappings":";;;;;AAoBA,MAAa,gBAAgB,QAAQ,iBAAiB;CACpD,IAAI,KAAK,IAAI,CAAC,CACX,WAAW,CAAC,CACZ,iBAAiB,MAAM,cAAc,CAAC;CAEzC,YAAY,KAAK,aAAa,CAAC,CAAC,OAAO;CACvC,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ;CAC3B,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO;CACpC,SAAS,KAAK,UAAU,CAAC,CACtB,QAAQ,CAAC,CACT,iBAAiB,MAAM,EAAE;CAC5B,UAAU,MAAM,UAAU,CA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KAAK,OAAO,CAAC,CAAC,QAAQ;CAC7B,SAAS,KAAK,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,QAAQ;CAChD,QAAQ,KAAK,UAAU,EACrB,MAAM;EAAC;EAAW;EAAY;EAAY;CAAU,EACtD,CAAC,CAAC,CAAC,QAAQ;CACX,WAAW,KAAK,YAAY,CAAC,CAC1B,QAAQ,CAAC,CACT,iBAAiB,MAAM,EAAE;CAC5B,WAAW,KAAK,YAAY,CAAC,CAAC,OAAO;CACrC,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC;CACzD,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW;CAChF,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CACvD,QAAQ,CAAC,CACT,WAAW,CAAC,CACZ,gCAAgB,IAAI,KAAK,CAAC;AAC/B,IACC,OAAO;CACN,IAAI,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;CAE3C,gBAAgB,YAAY,0BAA0B,CAAC,CACpD,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CACpB,MAAM,GAAG,GAAG,EAAE,OAAO,aAAa;AACvC,EACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ALTER TABLE "spaces" ADD COLUMN "cover_asset_id" text;--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "spaces" ADD COLUMN "background_asset_id" text;--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "spaces" ADD COLUMN "icon_asset_id" text;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "spaces" ADD CONSTRAINT "spaces_org_id_cover_asset_id_assets_org_id_id_fk" FOREIGN KEY ("org_id","cover_asset_id") REFERENCES "public"."assets"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "spaces" ADD CONSTRAINT "spaces_org_id_background_asset_id_assets_org_id_id_fk" FOREIGN KEY ("org_id","background_asset_id") REFERENCES "public"."assets"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
6
|
+
ALTER TABLE "spaces" ADD CONSTRAINT "spaces_org_id_icon_asset_id_assets_org_id_id_fk" FOREIGN KEY ("org_id","icon_asset_id") REFERENCES "public"."assets"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
7
|
+
CREATE INDEX "spaces_cover_idx" ON "spaces" USING btree ("org_id","cover_asset_id");--> statement-breakpoint
|
|
8
|
+
CREATE INDEX "spaces_background_idx" ON "spaces" USING btree ("org_id","background_asset_id");--> statement-breakpoint
|
|
9
|
+
CREATE INDEX "spaces_icon_idx" ON "spaces" USING btree ("org_id","icon_asset_id");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "organizations" ADD COLUMN "metadata" jsonb DEFAULT '{}'::jsonb NOT NULL;
|