Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stageId to pubs #966

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/lib/server/stages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ export type CommunityStage = AutoReturnType<typeof getStages>["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 }])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "pubs" ADD COLUMN "stageId" TEXT;

-- AddForeignKey
ALTER TABLE "pubs" ADD CONSTRAINT "pubs_stageId_fkey" FOREIGN KEY ("stageId") REFERENCES "stages"("id") ON DELETE SET NULL ON UPDATE CASCADE;
5 changes: 5 additions & 0 deletions core/prisma/schema/schema.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Table pubs {
createdAt DateTime [default: `now()`, not null]
updatedAt DateTime [default: `now()`, not null]
title String
stage stages
stageId String
parent pubs
parentId String
children pubs [not null]
Expand Down Expand Up @@ -196,6 +198,7 @@ Table stages {
actionInstances action_instances [not null]
formElements form_elements [not null]
members stage_memberships [not null]
Pub pubs [not null]
}

Table PubsInStages {
Expand Down Expand Up @@ -621,6 +624,8 @@ Ref: pubs.communityId > communities.id

Ref: pubs.assigneeId > users.id

Ref: pubs.stageId > stages.id [delete: Set Null]

Ref: pubs.parentId - pubs.id [delete: Cascade]

Ref: pub_fields.pubFieldSchemaId > PubFieldSchema.id
Expand Down
3 changes: 3 additions & 0 deletions core/prisma/schema/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ model Pub {
// and the _PubFieldToPubType table
// do not attempt to set this manually
title String?
stage Stage? @relation(fields: [stageId], references: [id], onDelete: SetNull)
stageId String?

parent Pub? @relation("pub_parent", fields: [parentId], references: [id], onDelete: Cascade)
parentId String?
Expand Down Expand Up @@ -265,6 +267,7 @@ model Stage {
actionInstances ActionInstance[]
formElements FormElement[]
members StageMembership[]
Pub Pub[]

@@map(name: "stages")
}
Expand Down
56 changes: 28 additions & 28 deletions packages/db/src/public/PublicSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ import type { StagesTable } from "./Stages";
import type { UsersTable } from "./Users";

export interface PublicSchema {
rules: RulesTable;

action_runs: ActionRunsTable;

forms: FormsTable;

api_access_tokens: ApiAccessTokensTable;

api_access_logs: ApiAccessLogsTable;

api_access_permissions: ApiAccessPermissionsTable;

form_elements: FormElementsTable;

sessions: SessionsTable;

community_memberships: CommunityMembershipsTable;

pub_memberships: PubMembershipsTable;

stage_memberships: StageMembershipsTable;

form_memberships: FormMembershipsTable;

membership_capabilities: MembershipCapabilitiesTable;

pub_values_history: PubValuesHistoryTable;

_prisma_migrations: PrismaMigrationsTable;

users: UsersTable;
Expand Down Expand Up @@ -64,32 +92,4 @@ export interface PublicSchema {
action_instances: ActionInstancesTable;

PubsInStages: PubsInStagesTable;

rules: RulesTable;

action_runs: ActionRunsTable;

forms: FormsTable;

api_access_tokens: ApiAccessTokensTable;

api_access_logs: ApiAccessLogsTable;

api_access_permissions: ApiAccessPermissionsTable;

form_elements: FormElementsTable;

sessions: SessionsTable;

community_memberships: CommunityMembershipsTable;

pub_memberships: PubMembershipsTable;

stage_memberships: StageMembershipsTable;

form_memberships: FormMembershipsTable;

membership_capabilities: MembershipCapabilitiesTable;

pub_values_history: PubValuesHistoryTable;
}
7 changes: 7 additions & 0 deletions packages/db/src/public/Pubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { z } from "zod";

import type { CommunitiesId } from "./Communities";
import type { PubTypesId } from "./PubTypes";
import type { StagesId } from "./Stages";
import type { UsersId } from "./Users";
import { communitiesIdSchema } from "./Communities";
import { pubTypesIdSchema } from "./PubTypes";
import { stagesIdSchema } from "./Stages";
import { usersIdSchema } from "./Users";

// @generated
Expand Down Expand Up @@ -36,6 +38,8 @@ export interface PubsTable {
title: ColumnType<string | null, string | null, string | null>;

searchVector: ColumnType<string | null, string | null, string | null>;

stageId: ColumnType<StagesId | null, StagesId | null, StagesId | null>;
}

export type Pubs = Selectable<PubsTable>;
Expand All @@ -57,6 +61,7 @@ export const pubsSchema = z.object({
assigneeId: usersIdSchema.nullable(),
title: z.string().nullable(),
searchVector: z.string().nullable(),
stageId: stagesIdSchema.nullable(),
});

export const pubsInitializerSchema = z.object({
Expand All @@ -70,6 +75,7 @@ export const pubsInitializerSchema = z.object({
assigneeId: usersIdSchema.optional().nullable(),
title: z.string().optional().nullable(),
searchVector: z.string().optional().nullable(),
stageId: stagesIdSchema.optional().nullable(),
});

export const pubsMutatorSchema = z.object({
Expand All @@ -83,4 +89,5 @@ export const pubsMutatorSchema = z.object({
assigneeId: usersIdSchema.optional().nullable(),
title: z.string().optional().nullable(),
searchVector: z.string().optional().nullable(),
stageId: stagesIdSchema.optional().nullable(),
});
8 changes: 8 additions & 0 deletions packages/db/src/table-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,14 @@ export const databaseTables = [
isAutoIncrementing: false,
hasDefaultValue: false,
},
{
name: "stageId",
dataType: "text",
dataTypeSchema: "pg_catalog",
isNullable: true,
isAutoIncrementing: false,
hasDefaultValue: false,
},
],
},
{
Expand Down
Loading