Skip to content
Merged
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
19 changes: 19 additions & 0 deletions TECH_REF.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Technical Reference

## For Next Time
- Review and confirm our workflow terminology:
- Workflow actions: do not modify Pub metadata
- Internal side effects: modify Pub metadata, but directly in the app
- External side effects: modify Pub metadata, but via an integration
Comment on lines +6 to +7
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't my understanding. My understanding was that integrations can cause either internal or external side-effects (perhaps both), and that those were defined as:

  • Internal side effects: changes pub metadata
  • External side-effects: triggers off-platform events.

The former is internal to our platform (e.g. edits the title, generates a new file, creates a review). The latter is external to our platform (e.g. builds a website, posts to slack, deposits to archival service).

- How do we handle internal and external side effects?

## Thursday, June 22, 2023

### Pub Tables
- Existence of a field on a pub is sufficient validation for PubTypes for the MVP -- both for integrations and stages.
- EAV vs. JSONB: going to maintain both for now so we can look into performance as we build.

### Workflows
- Integrations can be connected to any workflow stage.
- An integration doesn't know anything about the workflow or stage. Either modifies pub metadata or performs a side effect.
- Anything that modifies a Pub's relationship with the workflow is an action.
- Actions shouldn't change Pub metadata — Pub metadata should be directly edited or changed via integrations.

## Wednesday, June 21, 2023

### Pub Types
Expand Down
22 changes: 14 additions & 8 deletions app/@community/(community)/pubs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ export default async function Page() {
}
const pubs = await prisma.pub.findMany({
where: { communityId: onlyCommunity.id, parentId: null },
select: {
id: true,
pubType: { select: { name: true, fields: true } },
metadata: { select: { type: true, value: true } },
include: {
pubType: {
include: {
metadataFields: true,
},
},
metadataValues: true,
children: {
select: {
id: true,
pubType: { select: { name: true, fields: true } },
metadata: { select: { type: true, value: true } },
include: {
pubType: {
include: {
metadataFields: true,
},
},
metadataValues: true,
},
},
},
Expand Down
20 changes: 19 additions & 1 deletion app/@community/(community)/workflows/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
export default function Page() {
import prisma from "prisma/db";

export default async function Page() {
/* Normally, we would get the community based on the url or logged in user session */
const onlyCommunity = await prisma.community.findFirst();
if (!onlyCommunity) {
return null;
}
const workflows = await prisma.workflow.findMany({
where: { communityId: onlyCommunity.id },
include: {
stages: {
include: {
moveConstraints: true,
},
},
},
});
return (
<>
<h1>Workflows</h1>
<pre>{JSON.stringify(workflows, null, 4)}</pre>
</>
);
}
18 changes: 17 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@
"jsonwebtoken": "^9.0.0",
"next": "13.4.5",
"react": "18.2.0",
"react-dom": "18.2.0"
"react-dom": "18.2.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/diacritics": "^1.3.1",
"@types/jsonwebtoken": "^9.0.2",
"@types/node": "20.3.1",
"@types/react": "18.2.12",
"@types/react-dom": "18.2.5",
"@types/uuid": "^9.0.2",
"dotenv-cli": "^7.2.1",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
Expand Down
51 changes: 51 additions & 0 deletions prisma/migrations/20230622182329_metadata_refactor/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Warnings:

- You are about to drop the column `fields` on the `pub_types` table. All the data in the column will be lost.
- You are about to drop the `metadata` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `metadataBlob` to the `pubs` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "metadata" DROP CONSTRAINT "metadata_pub_id_fkey";

-- AlterTable
ALTER TABLE "pub_types" DROP COLUMN "fields";

-- AlterTable
ALTER TABLE "pubs" ADD COLUMN "metadataBlob" JSONB NOT NULL;

-- DropTable
DROP TABLE "metadata";

-- CreateTable
CREATE TABLE "metadata_fields" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"pub_type_id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "metadata_fields_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "metadata_values" (
"id" TEXT NOT NULL,
"field_id" TEXT NOT NULL,
"value" JSONB NOT NULL,
"pub_id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "metadata_values_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "metadata_fields" ADD CONSTRAINT "metadata_fields_pub_type_id_fkey" FOREIGN KEY ("pub_type_id") REFERENCES "pub_types"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "metadata_values" ADD CONSTRAINT "metadata_values_field_id_fkey" FOREIGN KEY ("field_id") REFERENCES "metadata_fields"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "metadata_values" ADD CONSTRAINT "metadata_values_pub_id_fkey" FOREIGN KEY ("pub_id") REFERENCES "pubs"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
2 changes: 2 additions & 0 deletions prisma/migrations/20230622182626_blob_optional/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "pubs" ALTER COLUMN "metadataBlob" DROP NOT NULL;
94 changes: 94 additions & 0 deletions prisma/migrations/20230622194921_workflow_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Warnings:

- Added the required column `workflow_id` to the `stages` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "stages" ADD COLUMN "workflow_id" TEXT NOT NULL;

-- CreateTable
CREATE TABLE "move_constraint" (
"id" TEXT NOT NULL,
"stage_id" TEXT NOT NULL,
"destination_id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "move_constraint_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "action_claim" (
"id" TEXT NOT NULL,
"stage_id" TEXT NOT NULL,
"pub_id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"releasedAt" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "action_claim_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "action_move" (
"id" TEXT NOT NULL,
"source_stage_id" TEXT NOT NULL,
"destination_stage_id" TEXT NOT NULL,
"pub_id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"note" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "action_move_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "_PubToStage" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "_PubToStage_AB_unique" ON "_PubToStage"("A", "B");

-- CreateIndex
CREATE INDEX "_PubToStage_B_index" ON "_PubToStage"("B");

-- AddForeignKey
ALTER TABLE "stages" ADD CONSTRAINT "stages_workflow_id_fkey" FOREIGN KEY ("workflow_id") REFERENCES "workflows"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "move_constraint" ADD CONSTRAINT "move_constraint_stage_id_fkey" FOREIGN KEY ("stage_id") REFERENCES "stages"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "move_constraint" ADD CONSTRAINT "move_constraint_destination_id_fkey" FOREIGN KEY ("destination_id") REFERENCES "stages"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_claim" ADD CONSTRAINT "action_claim_stage_id_fkey" FOREIGN KEY ("stage_id") REFERENCES "stages"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_claim" ADD CONSTRAINT "action_claim_pub_id_fkey" FOREIGN KEY ("pub_id") REFERENCES "pubs"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_claim" ADD CONSTRAINT "action_claim_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_move" ADD CONSTRAINT "action_move_source_stage_id_fkey" FOREIGN KEY ("source_stage_id") REFERENCES "stages"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_move" ADD CONSTRAINT "action_move_destination_stage_id_fkey" FOREIGN KEY ("destination_stage_id") REFERENCES "stages"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_move" ADD CONSTRAINT "action_move_pub_id_fkey" FOREIGN KEY ("pub_id") REFERENCES "pubs"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_move" ADD CONSTRAINT "action_move_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_PubToStage" ADD CONSTRAINT "_PubToStage_A_fkey" FOREIGN KEY ("A") REFERENCES "pubs"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_PubToStage" ADD CONSTRAINT "_PubToStage_B_fkey" FOREIGN KEY ("B") REFERENCES "stages"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:

- Added the required column `community_id` to the `workflows` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "workflows" ADD COLUMN "community_id" TEXT NOT NULL;

-- AddForeignKey
ALTER TABLE "workflows" ADD CONSTRAINT "workflows_community_id_fkey" FOREIGN KEY ("community_id") REFERENCES "communities"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
14 changes: 14 additions & 0 deletions prisma/migrations/20230622195558_stage_names_order/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:

- Added the required column `name` to the `stages` table without a default value. This is not possible if the table is not empty.
- Added the required column `order` to the `stages` table without a default value. This is not possible if the table is not empty.
- Added the required column `name` to the `workflows` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "stages" ADD COLUMN "name" TEXT NOT NULL,
ADD COLUMN "order" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "workflows" ADD COLUMN "name" TEXT NOT NULL;
Loading