diff --git a/core/actions/_lib/runActionInstance.ts b/core/actions/_lib/runActionInstance.ts index b4a6ea0b94..7adf0e137b 100644 --- a/core/actions/_lib/runActionInstance.ts +++ b/core/actions/_lib/runActionInstance.ts @@ -66,9 +66,9 @@ const _runActionInstance = async ( // often happens when an action is scheduled but a pub is moved before the action runs jsonObjectFrom( eb - .selectFrom("PubsInStages") - .select(["pubId", "stageId"]) - .where("pubId", "=", args.pubId) + .selectFrom("pubs") + .select(["pubs.id as pubId", "stageId"]) + .where("pubs.id", "=", args.pubId) .whereRef("stageId", "=", "action_instances.stageId") ).as("pubInStage"), ]) diff --git a/core/app/c/[communitySlug]/pubs/[pubId]/components/queries.ts b/core/app/c/[communitySlug]/pubs/[pubId]/components/queries.ts index 0afa852e0f..b28f16e1c7 100644 --- a/core/app/c/[communitySlug]/pubs/[pubId]/components/queries.ts +++ b/core/app/c/[communitySlug]/pubs/[pubId]/components/queries.ts @@ -66,7 +66,7 @@ export const getPubChildrenTable = (parentId: PubsId, selectedPubTypeId?: PubTyp eb .selectFrom("pubs") .where("parentId", "=", parentId) - .select((eb) => ["id", "pubTypeId", "createdAt"]) + .select(["id", "pubTypeId", "createdAt", "stageId"]) .orderBy("createdAt", "desc") ) .with("children_with_specific_pubtype", (eb) => @@ -85,15 +85,14 @@ export const getPubChildrenTable = (parentId: PubsId, selectedPubTypeId?: PubTyp .limit(1) ) ) - .leftJoin("PubsInStages", "PubsInStages.pubId", "all_children.id") - .selectAll(["all_children"]) + .selectAll("all_children") .select((eb) => [ pubValuesByRef( "all_children.id" as "pubs.id" ) as unknown as AliasedRawBuilder, memberFields(eb.ref("all_children.id")).as("memberFields"), - actionInstances(eb.ref("PubsInStages.stageId")).as("actionInstances"), - stages(eb.ref("PubsInStages.stageId")).as("stages"), + actionInstances(eb.ref("all_children.stageId")).as("actionInstances"), + stages(eb.ref("all_children.stageId")).as("stages"), ]) ) .with("counts_of_other_pub_types", (eb) => diff --git a/core/app/c/[communitySlug]/stages/manage/actions.ts b/core/app/c/[communitySlug]/stages/manage/actions.ts index 577ebd3aba..a27847c979 100644 --- a/core/app/c/[communitySlug]/stages/manage/actions.ts +++ b/core/app/c/[communitySlug]/stages/manage/actions.ts @@ -137,7 +137,7 @@ export const deleteStage = defineServerAction(async function deleteStage(stageId cause: error, }; } finally { - await revalidateTagsForCommunity(["stages", "PubsInStages"]); + await revalidateTagsForCommunity(["stages", "pubs"]); } }); @@ -266,7 +266,7 @@ export const revalidateStages = defineServerAction(async function revalidateStag return ApiError.NOT_LOGGED_IN; } - await revalidateTagsForCommunity(["stages", "PubsInStages"]); + await revalidateTagsForCommunity(["stages", "pubs"]); }); export const addAction = defineServerAction(async function addAction( diff --git a/core/app/components/pubs/PubEditor/queries.ts b/core/app/components/pubs/PubEditor/queries.ts index 5a71c3d2dd..24f6a1f460 100644 --- a/core/app/components/pubs/PubEditor/queries.ts +++ b/core/app/components/pubs/PubEditor/queries.ts @@ -98,9 +98,9 @@ export const availableStagesAndCurrentStage = ({ db .with("currentStageId", (eb) => eb - .selectFrom("PubsInStages") + .selectFrom("pubs") .select(["stageId as currentStageId"]) - .where("PubsInStages.pubId", "=", pubId) + .where("pubs.id", "=", pubId) ) .selectFrom("stages") .select((eb) => [ @@ -119,7 +119,7 @@ export const availableStagesAndCurrentStage = ({ .selectFrom("stages") .select(["id", "name", "order"]) .orderBy("order desc") - .where("stages.communityId", "=", communityId as CommunitiesId) + .where("stages.communityId", "=", communityId) ).as("availableStagesOfCurrentPub"), ]) ); diff --git a/core/lib/authorization/capabilities.ts b/core/lib/authorization/capabilities.ts index c5cc2cfa5e..521b992b29 100644 --- a/core/lib/authorization/capabilities.ts +++ b/core/lib/authorization/capabilities.ts @@ -84,14 +84,11 @@ export const userCan = async ( ) => { if (target.type === MembershipType.pub) { const capabilitiesQuery = db - .with("stage", (db) => + .with("pub", (db) => db - .selectFrom("PubsInStages") - .where("PubsInStages.pubId", "=", target.pubId) - .select("PubsInStages.stageId") - ) - .with("community", (db) => - db.selectFrom("pubs").where("pubs.id", "=", target.pubId).select("pubs.communityId") + .selectFrom("pubs") + .where("pubs.id", "=", target.pubId) + .select(["pubs.communityId", "pubs.stageId"]) ) .with("stage_ms", (db) => db @@ -104,7 +101,7 @@ export const userCan = async ( // one stage. But we don't actually expect there to be multiple stageIds // returned (for now) "in", - eb.selectFrom("stage").select("stageId") + eb.selectFrom("pub").select("stageId") ) ) .select("role") @@ -120,7 +117,7 @@ export const userCan = async ( db .selectFrom("community_memberships") .where("community_memberships.userId", "=", userId) - .whereRef("communityId", "=", db.selectFrom("community").select("communityId")) + .whereRef("communityId", "=", db.selectFrom("pub").select("communityId")) .select("role") ) diff --git a/core/lib/db/queries.ts b/core/lib/db/queries.ts index 251e0bf7f3..5772142c40 100644 --- a/core/lib/db/queries.ts +++ b/core/lib/db/queries.ts @@ -42,8 +42,7 @@ export const getStagePubs = cache((stageId: StagesId) => { .selectAll("pubs") .select(pubValuesByRef("pubs.id")) .select((eb) => pubType({ eb, pubTypeIdRef: "pubs.pubTypeId" })) - .innerJoin("PubsInStages", "PubsInStages.pubId", "pubs.id") - .where("PubsInStages.stageId", "=", stageId) + .where("pubs.stageId", "=", stageId) ); }); diff --git a/core/lib/server/cache/README.md b/core/lib/server/cache/README.md index 5a84ffdc2b..681d6a6936 100644 --- a/core/lib/server/cache/README.md +++ b/core/lib/server/cache/README.md @@ -215,11 +215,10 @@ Using this strategy, we can ensure that all data is fresh when it needs to be, b #### Example -We fetch all data associated with a specific `pub` quite often. All the data of a `pub` is dependend on +We fetch all data associated with a specific `pub` quite often. All the data of a `pub` is dependent on -- the state of `pub_values` and `pub_fields` table for the values associated with a `pub`. -- the state of the `pubs` table for the data of the `pub` itself, as well as its children. -- possibly the `pubsinstages` table for the stage the `pub` is in. +- the state of `pub_values` and `pub_fields` table for the values associated with a `pub`. +- the state of the `pubs` table for the data of the `pub` itself, as well as its children. When caching this data, we want to have the maximum balance between freshness and having a long cache time, while ideally not having to manually remember every single way we cache things. We can do this by invalidating the cache for a query for a specific `pub` when any of the tables are modified, as then we are assured that the data is fresh when needed. diff --git a/core/lib/server/pub.ts b/core/lib/server/pub.ts index 5334c31d98..fcd6550110 100644 --- a/core/lib/server/pub.ts +++ b/core/lib/server/pub.ts @@ -78,7 +78,7 @@ type FlatPub = PubNoChildren & { }; // pubValuesByRef adds a JSON object of pub_values keyed by their field name under the `fields` key to the output of a query -// pubIdRef should be a column name that refers to a pubId in the current query context, such as pubs.parentId or PubsInStages.pubId +// pubIdRef should be a column name that refers to a pubId in the current query context, such as pubs.parentId // It doesn't seem to work if you've aliased the table or column (although you can probably work around that with a cast) export const pubValuesByRef = (pubIdRef: StringReference) => { return (eb: ExpressionBuilder) => pubValues(eb, { pubIdRef }); @@ -200,11 +200,7 @@ const withPubChildren = ({ .$if(!!communityId, (qb) => qb.where("pubs.communityId", "=", communityId!).where("pubs.parentId", "is", null) ) - .$if(!!stageId, (qb) => - qb - .innerJoin("PubsInStages", "pubs.id", "PubsInStages.pubId") - .where("PubsInStages.stageId", "=", stageId!) - ) + .$if(!!stageId, (qb) => qb.where("pubs.stageId", "=", stageId!)) .unionAll((eb) => { return eb .selectFrom("pubs") @@ -248,6 +244,7 @@ const pubColumns = [ "assigneeId", "parentId", "title", + "stageId", ] as const satisfies SelectExpression[]; export const getPubBase = ( @@ -266,26 +263,10 @@ export const getPubBase = ( ...pubColumns, pubType({ eb, pubTypeIdRef: "pubs.pubTypeId" }), pubAssignee(eb), - jsonArrayFrom( - eb - .selectFrom("PubsInStages") - .select(["PubsInStages.stageId as id"]) - .whereRef("PubsInStages.pubId", "=", "pubs.id") - ).as("stages"), jsonArrayFrom( eb .selectFrom("children") - .select((eb) => [ - ...pubColumns, - "children.values", - "children.pubType", - jsonArrayFrom( - eb - .selectFrom("PubsInStages") - .select(["PubsInStages.stageId as id"]) - .whereRef("PubsInStages.pubId", "=", "children.id") - ).as("stages"), - ]) + .select([...pubColumns, "children.values", "children.pubType"]) .$narrowType<{ values: PubValues }>() ).as("children"), ]) @@ -366,11 +347,7 @@ export const _deprecated_getPubs = async ( .$if(Boolean(props.communityId), (eb) => eb.where("pubs.communityId", "=", props.communityId!) ) - .$if(Boolean(props.stageId), (eb) => - eb - .innerJoin("PubsInStages", "pubs.id", "PubsInStages.pubId") - .where("PubsInStages.stageId", "=", props.stageId!) - ) + .$if(Boolean(props.stageId), (eb) => eb.where("pubs.stageId", "=", props.stageId!)) .$if(Boolean(params.onlyParents), (eb) => eb.where("pubs.parentId", "is", null)) .limit(limit) .offset(offset) @@ -519,25 +496,11 @@ export const createPubRecursiveNew = async ({ - pubId: newPub.id, - stageId: expect(stageId), - })) - .returningAll() - ).executeTakeFirstOrThrow(); - - createdStageId = result.stageId; - } - if (body.members && Object.keys(body.members).length) { await trx .insertInto("pub_memberships") @@ -585,7 +548,6 @@ export const createPubRecursiveNew = async - autoCache(trx.selectFrom("PubsInStages").select("stageId").where("pubId", "=", pubId)); + autoCache(trx.selectFrom("pubs").select("stageId").where("id", "=", pubId)); export const getPlainPub = (pubId: PubsId, trx = db) => autoCache(trx.selectFrom("pubs").selectAll().where("id", "=", pubId)); @@ -1350,8 +1310,6 @@ export async function getPubsWithRelatedValuesAndChildren< // we need to do this weird cast, because kysely does not support typing the selecting from a later CTE // which is possible only in a with recursive query .selectFrom("root_pubs_limited as p" as unknown as "pubs as p") - // TODO: can we avoid doing this join again since it's already in root pubs? - .leftJoin("PubsInStages", "p.id", "PubsInStages.pubId") .$if(Boolean(withRelatedPubs), (qb) => qb .leftJoin("pub_values as pv", (join) => @@ -1371,7 +1329,7 @@ export async function getPubsWithRelatedValuesAndChildren< "p.createdAt", "p.updatedAt", "p.title", - "PubsInStages.stageId", + "p.stageId", "p.parentId", sql`1`.as("depth"), sql`false`.as("isCycle"), @@ -1408,7 +1366,6 @@ export async function getPubsWithRelatedValuesAndChildren< ]) ) ) - .leftJoin("PubsInStages", "pubs.id", "PubsInStages.pubId") .where((eb) => eb.exists( eb.selectFrom("capabilities" as any).where((ebb) => { @@ -1440,7 +1397,7 @@ export async function getPubsWithRelatedValuesAndChildren< eb( "capabilities.membId", "=", - eb.ref("PubsInStages.stageId") + eb.ref("pubs.stageId") ), ]), eb.and([ @@ -1490,7 +1447,7 @@ export async function getPubsWithRelatedValuesAndChildren< "pubs.createdAt", "pubs.updatedAt", "pubs.title", - "PubsInStages.stageId", + "pubs.stageId", "pubs.parentId", // increment the depth sql`pub_tree.depth + 1`.as("depth"), @@ -1631,8 +1588,6 @@ export async function getPubsWithRelatedValuesAndChildren< .selectFrom("pubs") .selectAll("pubs") .where("pubs.communityId", "=", props.communityId) - .leftJoin("PubsInStages", "pubs.id", "PubsInStages.pubId") - .select("PubsInStages.stageId") .where((eb) => eb.exists( eb @@ -1641,11 +1596,7 @@ export async function getPubsWithRelatedValuesAndChildren< eb.or([ eb.and([ eb("capabilities.type", "=", MembershipType.stage), - eb( - "capabilities.membId", - "=", - eb.ref("PubsInStages.stageId") - ), + eb("capabilities.membId", "=", eb.ref("pubs.stageId")), ]), eb.and([ eb("capabilities.type", "=", MembershipType.pub), @@ -1661,7 +1612,7 @@ export async function getPubsWithRelatedValuesAndChildren< ) .$if(Boolean(props.pubId), (qb) => qb.where("pubs.id", "=", props.pubId!)) .$if(Boolean(props.stageId), (qb) => - qb.where("PubsInStages.stageId", "=", props.stageId!) + qb.where("pubs.stageId", "=", props.stageId!) ) .$if(Boolean(props.pubTypeId), (qb) => qb.where("pubs.pubTypeId", "=", props.pubTypeId!) @@ -1894,11 +1845,7 @@ export const getPubsCount = async (props: { const pubs = await db .selectFrom("pubs") .where("pubs.communityId", "=", props.communityId) - .$if(Boolean(props.stageId), (qb) => - qb - .innerJoin("PubsInStages", "pubs.id", "PubsInStages.pubId") - .where("PubsInStages.stageId", "=", props.stageId!) - ) + .$if(Boolean(props.stageId), (qb) => qb.where("pubs.stageId", "=", props.stageId!)) .$if(Boolean(props.pubTypeId), (qb) => qb.where("pubs.pubTypeId", "=", props.pubTypeId!)) .select((eb) => eb.fn.countAll().as("count")) .executeTakeFirstOrThrow(); @@ -2066,10 +2013,8 @@ export const fullTextSearch = async ( jsonObjectFrom( eb .selectFrom("stages") - .leftJoin("PubsInStages", "stages.id", "PubsInStages.stageId") .select(["stages.id", "stages.name"]) - .whereRef("PubsInStages.pubId", "=", "pubs.id") - .limit(1) + .whereRef("stages.id", "=", "pubs.stageId") ).as("stage"), ]) .where("pubs.communityId", "=", communityId) diff --git a/core/lib/server/stages.ts b/core/lib/server/stages.ts index bd3d45bf88..922879384e 100644 --- a/core/lib/server/stages.ts +++ b/core/lib/server/stages.ts @@ -25,17 +25,7 @@ export const updateStage = (stageId: StagesId, props: StagesUpdate) => autoRevalidate(db.updateTable("stages").set(props).where("id", "=", stageId)); export const removeStages = (stageIds: StagesId[]) => - autoRevalidate( - db - .with("deleted_stages", (db) => - db - .deleteFrom("stages") - .where("id", "in", stageIds as StagesId[]) - .returning("id") - ) - .deleteFrom("PubsInStages") - .where("stageId", "in", (eb) => eb.selectFrom("deleted_stages").select("id")) - ); + autoRevalidate(db.deleteFrom("stages").where("id", "in", stageIds)); export const createMoveConstraint = (props: NewMoveConstraint) => autoRevalidate(db.insertInto("move_constraint").values(props)); @@ -46,8 +36,8 @@ export const createMoveConstraint = (props: NewMoveConstraint) => export const getPubIdsInStage = (stageId: StagesId) => autoCache( db - .selectFrom("PubsInStages") - .select(sql`array_agg("pubId")`.as("pubIds")) + .selectFrom("pubs") + .select(sql`array_agg("id")`.as("pubIds")) .where("stageId", "=", stageId) ); @@ -132,11 +122,11 @@ export const getStages = ({ communityId, stageId, userId }: CommunityStageProps) .select(["s.id", "s.name"]) ).as("moveConstraintSources"), eb - .selectFrom("PubsInStages") + .selectFrom("pubs") .select((eb) => eb.fn - .count("PubsInStages.pubId") - .filterWhereRef("PubsInStages.stageId", "=", "stages.id") + .count("pubs.id") + .filterWhereRef("pubs.stageId", "=", "stages.id") .as("pubsCount") ) .as("pubsCount"), @@ -168,15 +158,6 @@ export type CommunityStage = AutoReturnType["executeTakeFirstO export const movePub = (pubId: PubsId, stageId: StagesId, trx = db) => { return autoRevalidate( - trx - .with("update_pub", (db) => - db.updateTable("pubs").where("pubs.id", "=", pubId).set("stageId", stageId) - ) - .with("leave_stage", (db) => db.deleteFrom("PubsInStages").where("pubId", "=", pubId)) - .insertInto("PubsInStages") - .values([{ pubId, stageId }]) - // Without this on conflict clause, the db errors if this function is called with the - // stageId the pub already belongs to - .onConflict((oc) => oc.doNothing()) + trx.updateTable("pubs").where("pubs.id", "=", pubId).set("stageId", stageId) ); }; diff --git a/core/prisma/exampleCommunitySeeds/unjournal.ts b/core/prisma/exampleCommunitySeeds/unjournal.ts index 14a6046fd9..48c6392347 100644 --- a/core/prisma/exampleCommunitySeeds/unjournal.ts +++ b/core/prisma/exampleCommunitySeeds/unjournal.ts @@ -671,17 +671,10 @@ export default async function main(communityUUID: CommunitiesId) { .values({ communityId: communityUUID as CommunitiesId, pubTypeId: submissionTypeId as PubTypesId, + stageId: stageIds[3] as StagesId, }) .returning("id") ) - .with("pubs_in_stages", (db) => - db.insertInto("PubsInStages").values((eb) => [ - { - pubId: eb.selectFrom("new_pubs").select("id"), - stageId: stageIds[3] as StagesId, - }, - ]) - ) .insertInto("pub_values") .values((eb) => [ { diff --git a/core/prisma/migrations/20250206225213_remove_pubsinstages_table/migration.sql b/core/prisma/migrations/20250206225213_remove_pubsinstages_table/migration.sql new file mode 100644 index 0000000000..f577ae9cd8 --- /dev/null +++ b/core/prisma/migrations/20250206225213_remove_pubsinstages_table/migration.sql @@ -0,0 +1,56 @@ +-- Populate stageId column from PubsInStages table +UPDATE "pubs" SET "stageId" = "PubsInStages"."stageId" FROM "PubsInStages" WHERE "PubsInStages"."pubId" = "pubs"."id"; + +-- Remove trigger that updates pubs.updatedAt when a pub's stage is changed (this is handled by kysely updatedAt plugin now) +DROP TRIGGER IF EXISTS "trigger_pubs_in_stages_update_pub" ON "PubsInStages"; + +-- Update emitEvent trigger to work on pubs table +CREATE OR REPLACE FUNCTION emit_event() + RETURNS TRIGGER AS +$$ +DECLARE + community RECORD; +BEGIN + -- Determine the community + SELECT c.id, c.slug INTO community + FROM communities c + WHERE c.id = NEW."communityId"; + + PERFORM + graphile_worker.add_job( + 'emitEvent', + json_build_object( + 'table', TG_TABLE_NAME, + 'operation', TG_OP, + 'new', NEW, + 'old', OLD, + 'community', community + ) + ); + RETURN NEW; +END; +$$ +LANGUAGE plpgsql +VOLATILE; + +DROP TRIGGER IF EXISTS pub_moved ON "PubsInStages"; +CREATE OR REPLACE TRIGGER pub_moved + AFTER INSERT OR UPDATE ON "pubs" + FOR EACH ROW + EXECUTE FUNCTION emit_event(); + +/* + Warnings: + + - You are about to drop the `PubsInStages` table. If the table is not empty, all the data it contains will be lost. + +*/ + +-- DropForeignKey +ALTER TABLE "PubsInStages" DROP CONSTRAINT "PubsInStages_pubId_fkey"; + +-- DropForeignKey +ALTER TABLE "PubsInStages" DROP CONSTRAINT "PubsInStages_stageId_fkey"; + +-- DropTable +DROP TABLE "PubsInStages"; diff --git a/core/prisma/migrations/20250206225214_update_comments/migration.sql b/core/prisma/migrations/20250206225214_update_comments/migration.sql new file mode 100644 index 0000000000..45e4160264 --- /dev/null +++ b/core/prisma/migrations/20250206225214_update_comments/migration.sql @@ -0,0 +1,190 @@ +-- generator-version: 1.0.0 + +-- Model pub_values_history comments + + + +-- Model users comments + + + +-- Model sessions comments + +COMMENT ON COLUMN "sessions"."type" IS 'With what type of token is this session created? Used for determining on a page-by-page basis whether to allow a certain session to access it. For instance, a verify email token/session should not allow you to access the password reset page.'; + + +-- Model auth_tokens comments + + + +-- Model communities comments + + + +-- Model pubs comments + + + +-- Model pub_fields comments + + + +-- Model PubFieldSchema comments + +COMMENT ON COLUMN "PubFieldSchema"."schema" IS '@type(JSONSchemaType, ''ajv'', true, false, true)'; + + +-- Model pub_values comments + +COMMENT ON COLUMN "pub_values"."lastModifiedBy" IS '@type(LastModifiedBy, ''../types'', true, false, true)'; + + +-- Model pub_types comments + + + +-- Model _PubFieldToPubType comments + + + +-- Model stages comments + + + +-- Model move_constraint comments + + + +-- Model member_groups comments + + + +-- Model community_memberships comments + + + +-- Model pub_memberships comments + + + +-- Model stage_memberships comments + + + +-- Model form_memberships comments + + + +-- Model action_instances comments + + + +-- Model action_runs comments + + + +-- Model rules comments + + + +-- Model forms comments + + + +-- Model form_elements comments + + + +-- Model api_access_tokens comments + + + +-- Model api_access_logs comments + + + +-- Model api_access_permissions comments + +COMMENT ON COLUMN "api_access_permissions"."constraints" IS '@type(ApiAccessPermissionConstraints, ''../types'', true, false, true)'; + + +-- Model membership_capabilities comments + + + +-- Enum AuthTokenType comments + +COMMENT ON TYPE "AuthTokenType" IS '@property generic - For most use-cases. This will just authenticate you with a regular session. +@property passwordReset - For resetting your password only +@property signup - For signing up, but also when you''re invited to a community +@property verifyEmail - For verifying your email address'; + + +-- Enum CoreSchemaType comments + + + + +-- Enum OperationType comments + + + + +-- Enum MemberRole comments + + + + +-- Enum Action comments + + + + +-- Enum ActionRunStatus comments + + + + +-- Enum Event comments + + + + +-- Enum FormAccessType comments + + + + +-- Enum StructuralFormElement comments + + + + +-- Enum ElementType comments + + + + +-- Enum InputComponent comments + + + + +-- Enum ApiAccessType comments + + + + +-- Enum ApiAccessScope comments + + + + +-- Enum Capabilities comments + + + + +-- Enum MembershipType comments + + diff --git a/core/prisma/schema/comments/.comments-lock b/core/prisma/schema/comments/.comments-lock index 7d5a886990..45e4160264 100644 --- a/core/prisma/schema/comments/.comments-lock +++ b/core/prisma/schema/comments/.comments-lock @@ -51,10 +51,6 @@ COMMENT ON COLUMN "pub_values"."lastModifiedBy" IS '@type(LastModifiedBy, ''../t --- Model PubsInStages comments - - - -- Model move_constraint comments diff --git a/core/prisma/schema/schema.dbml b/core/prisma/schema/schema.dbml index 87c789c254..46327aa474 100644 --- a/core/prisma/schema/schema.dbml +++ b/core/prisma/schema/schema.dbml @@ -100,7 +100,6 @@ Table pubs { parentId String children pubs [not null] values pub_values [not null] - stages PubsInStages [not null] actionRuns action_runs [not null] relatedValues pub_values [not null] members pub_memberships [not null] @@ -192,26 +191,12 @@ Table stages { communityId String [not null] createdAt DateTime [default: `now()`, not null] updatedAt DateTime [default: `now()`, not null] - pubs PubsInStages [not null] + pubs pubs [not null] moveConstraints move_constraint [not null] moveConstraintSources move_constraint [not null] actionInstances action_instances [not null] formElements form_elements [not null] members stage_memberships [not null] - Pub pubs [not null] -} - -Table PubsInStages { - pub pubs [not null] - pubId String [not null] - stage stages [not null] - stageId String [not null] - createdAt DateTime [default: `now()`, not null] - updatedAt DateTime [default: `now()`, not null] - - indexes { - (pubId, stageId) [pk] - } } Table move_constraint { @@ -646,10 +631,6 @@ Ref: _PubFieldToPubType.B > pub_types.id [delete: Cascade] Ref: stages.communityId > communities.id -Ref: PubsInStages.pubId > pubs.id [delete: Cascade] - -Ref: PubsInStages.stageId > stages.id [delete: Cascade] - Ref: move_constraint.stageId > stages.id [delete: Cascade] Ref: move_constraint.destinationId > stages.id [delete: Cascade] diff --git a/core/prisma/schema/schema.prisma b/core/prisma/schema/schema.prisma index 9bb4bb08e2..15e2337081 100644 --- a/core/prisma/schema/schema.prisma +++ b/core/prisma/schema/schema.prisma @@ -132,7 +132,6 @@ model Pub { children Pub[] @relation("pub_parent") values PubValue[] @relation("original_pub") - stages PubsInStages[] actionRuns ActionRun[] relatedValues PubValue[] @relation("related_pub") members PubMembership[] @@ -261,28 +260,16 @@ model Stage { createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt - pubs PubsInStages[] + pubs Pub[] moveConstraints MoveConstraint[] @relation("move_constraint") moveConstraintSources MoveConstraint[] @relation("move_constraint_destination") actionInstances ActionInstance[] formElements FormElement[] members StageMembership[] - Pub Pub[] @@map(name: "stages") } -model PubsInStages { - pub Pub @relation(fields: [pubId], references: [id], onDelete: Cascade) - pubId String - stage Stage @relation(fields: [stageId], references: [id], onDelete: Cascade) - stageId String - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) @updatedAt - - @@id([pubId, stageId]) -} - model MoveConstraint { stage Stage @relation("move_constraint", fields: [stageId], references: [id], onDelete: Cascade) stageId String diff --git a/packages/contracts/src/resources/site.ts b/packages/contracts/src/resources/site.ts index bf94bdb848..3cfaeb322f 100644 --- a/packages/contracts/src/resources/site.ts +++ b/packages/contracts/src/resources/site.ts @@ -1,14 +1,11 @@ -import type { AppRouteResponse, ContractOtherResponse, Opaque } from "@ts-rest/core"; - import { initContract } from "@ts-rest/core"; -import { z, ZodNull } from "zod"; +import { z } from "zod"; import type { CommunitiesId, CoreSchemaType, MemberRole, PubFields, - PubFieldSchemaId, PubFieldsId, PubsId, PubTypes, @@ -21,7 +18,6 @@ import type { } from "db/public"; import { communitiesIdSchema, - communityMembershipsIdSchema, communityMembershipsSchema, coreSchemaTypeSchema, memberRoleSchema, @@ -241,8 +237,6 @@ type ProcessedPubBase = { * The `updatedAt` of the latest value, or of the pub if the pub itself has a higher `updatedAt` or if there are no values * * We do this because the Pub itself is rarely if ever changed over time. - * TODO: Possibly add the `updatedAt` of `PubsInStages` here as well? - * At time of writing (2024/11/04) I don't think that table has an `updatedAt`. */ updatedAt: Date; }; diff --git a/packages/db/src/public.ts b/packages/db/src/public.ts index 36c8cc3410..0c7cbd52a8 100644 --- a/packages/db/src/public.ts +++ b/packages/db/src/public.ts @@ -34,7 +34,6 @@ export * from "./public/PubFieldToPubType"; export * from "./public/PublicSchema"; export * from "./public/PubMemberships"; export * from "./public/Pubs"; -export * from "./public/PubsInStages"; export * from "./public/PubTypes"; export * from "./public/PubValues"; export * from "./public/PubValuesHistory"; diff --git a/packages/db/src/public/PubsInStages.ts b/packages/db/src/public/PubsInStages.ts deleted file mode 100644 index 29ada8075c..0000000000 --- a/packages/db/src/public/PubsInStages.ts +++ /dev/null @@ -1,49 +0,0 @@ -import type { ColumnType, Insertable, Selectable, Updateable } from "kysely"; - -import { z } from "zod"; - -import type { PubsId } from "./Pubs"; -import type { StagesId } from "./Stages"; -import { pubsIdSchema } from "./Pubs"; -import { stagesIdSchema } from "./Stages"; - -// @generated -// This file is automatically generated by Kanel. Do not modify manually. - -/** Represents the table public.PubsInStages */ -export interface PubsInStagesTable { - pubId: ColumnType; - - stageId: ColumnType; - - createdAt: ColumnType; - - updatedAt: ColumnType; -} - -export type PubsInStages = Selectable; - -export type NewPubsInStages = Insertable; - -export type PubsInStagesUpdate = Updateable; - -export const pubsInStagesSchema = z.object({ - pubId: pubsIdSchema, - stageId: stagesIdSchema, - createdAt: z.date(), - updatedAt: z.date(), -}); - -export const pubsInStagesInitializerSchema = z.object({ - pubId: pubsIdSchema, - stageId: stagesIdSchema, - createdAt: z.date().optional(), - updatedAt: z.date().optional(), -}); - -export const pubsInStagesMutatorSchema = z.object({ - pubId: pubsIdSchema.optional(), - stageId: stagesIdSchema.optional(), - createdAt: z.date().optional(), - updatedAt: z.date().optional(), -});