Skip to content

Commit

Permalink
Merge pull request #3173 from quantified-uncertainty/modelExports-ren…
Browse files Browse the repository at this point in the history
…aming

ModelExport -> VariableRevision, new Variable Table
  • Loading branch information
OAGr authored Apr 13, 2024
2 parents e3cd3be + 84a61e8 commit e2f93c1
Show file tree
Hide file tree
Showing 47 changed files with 830 additions and 746 deletions.
5 changes: 4 additions & 1 deletion packages/hub/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
/tsconfig.tsbuildinfo
/.next
/.vscode
__generated__

# Ignore all of the generated files, but keep the directory
src/__generated__/*
!src/__generated__/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Warnings:
- You are about to drop the `ModelExport` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "ModelExport" DROP CONSTRAINT "ModelExport_modelRevisionId_fkey";

-- DropTable
DROP TABLE "ModelExport";

-- CreateTable
CREATE TABLE "Variable" (
"id" TEXT NOT NULL,
"variableName" TEXT NOT NULL,
"modelId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "VariableRevision" (
"id" TEXT NOT NULL,
"modelRevisionId" TEXT NOT NULL,
"variableId" TEXT NOT NULL,
"variableName" TEXT NOT NULL,
"title" TEXT,
"docstring" TEXT NOT NULL DEFAULT '',
"variableType" TEXT NOT NULL DEFAULT 'OTHER',

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

-- CreateIndex
CREATE UNIQUE INDEX "Variable_modelId_variableName_key" ON "Variable"("modelId", "variableName");

-- CreateIndex
CREATE UNIQUE INDEX "VariableRevision_modelRevisionId_variableName_key" ON "VariableRevision"("modelRevisionId", "variableName");

-- AddForeignKey
ALTER TABLE "Variable" ADD CONSTRAINT "Variable_modelId_fkey" FOREIGN KEY ("modelId") REFERENCES "Model"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "VariableRevision" ADD CONSTRAINT "VariableRevision_modelRevisionId_fkey" FOREIGN KEY ("modelRevisionId") REFERENCES "ModelRevision"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "VariableRevision" ADD CONSTRAINT "VariableRevision_variableId_fkey" FOREIGN KEY ("variableId") REFERENCES "Variable"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- A unique constraint covering the columns `[currentRevisionId]` on the table `Variable` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "Variable" ADD COLUMN "currentRevisionId" TEXT;

-- CreateIndex
CREATE UNIQUE INDEX "Variable_currentRevisionId_key" ON "Variable"("currentRevisionId");

-- AddForeignKey
ALTER TABLE "Variable" ADD CONSTRAINT "Variable_currentRevisionId_fkey" FOREIGN KEY ("currentRevisionId") REFERENCES "VariableRevision"("id") ON DELETE SET NULL ON UPDATE CASCADE;
27 changes: 23 additions & 4 deletions packages/hub/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ model Model {
currentRevisionId String? @unique
searchable Searchable?
variables Variable[]
@@unique([slug, ownerId])
@@index([createdAt])
Expand All @@ -219,7 +220,7 @@ model ModelRevision {
contentId String? @unique
relativeValuesExports RelativeValuesExport[]
exports ModelExport[]
variableRevisions VariableRevision[]
// required by Prisma, but unused since `model` field should point at the same entity
currentRevisionModel Model? @relation("CurrentRevision")
Expand Down Expand Up @@ -252,17 +253,35 @@ model SquiggleSnippet {
revision ModelRevision?
}

model ModelExport {
model Variable {
id String @id @default(cuid())
variableName String
model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
modelId String
revisions VariableRevision[] @relation("Revisions")
// technically nullable, but won't ever be null in practice
currentRevision VariableRevision? @relation("CurrentRevision", fields: [currentRevisionId], references: [id])
currentRevisionId String? @unique
@@unique([modelId, variableName])
}

model VariableRevision {
id String @id @default(cuid())
modelRevision ModelRevision @relation(fields: [modelRevisionId], references: [id], onDelete: Cascade)
modelRevisionId String
variable Variable @relation("Revisions", fields: [variableId], references: [id], onDelete: Cascade)
variableId String
variableName String
title String?
docstring String @default("")
variableType String @default("OTHER")
isCurrent Boolean @default(false)
@@unique([modelRevisionId, variableName], name: "uniqueKey")
// required by Prisma, but unused since `model` field should point at the same entity
currentRevisionVariable Variable? @relation("CurrentRevision")
@@unique([modelRevisionId, variableName])
}

// Definitions are polymorphic, but organized differently from Models, without content types.
Expand Down
102 changes: 60 additions & 42 deletions packages/hub/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ type Group implements Node & Owner {
inviteForMe: GroupInvite
invites(after: String, before: String, first: Int, last: Int): GroupInviteConnection
memberships(after: String, before: String, first: Int, last: Int): UserGroupMembershipConnection!
modelExports(after: String, before: String, first: Int, last: Int): ModelExport!
models(after: String, before: String, first: Int, last: Int): ModelConnection!
myMembership: UserGroupMembership
reusableInviteToken: String
slug: String!
updatedAtTimestamp: Float!
variableRevisions(after: String, before: String, first: Int, last: Int): VariableRevision!
}

type GroupConnection {
Expand Down Expand Up @@ -153,7 +153,6 @@ enum MembershipRole {
type Model implements Node {
createdAtTimestamp: Float!
currentRevision: ModelRevision!
exportRevisions(after: String, before: String, first: Int, last: Int, variableId: String!): ModelExportRevisionsConnection!
id: ID!
isEditable: Boolean!
isPrivate: Boolean!
Expand All @@ -163,6 +162,7 @@ type Model implements Node {
revisions(after: String, before: String, first: Int, last: Int): ModelRevisionConnection!
slug: String!
updatedAtTimestamp: Float!
variables: [Variable!]!
}

type ModelConnection {
Expand All @@ -177,56 +177,19 @@ type ModelEdge {
node: Model!
}

type ModelExport implements Node {
docstring: String!
id: ID!
isCurrent: Boolean!
modelRevision: ModelRevision!
owner: Owner!
title: String
variableName: String!
variableType: String!
}

type ModelExportConnection {
edges: [ModelExportEdge!]!
pageInfo: PageInfo!
}

type ModelExportEdge {
cursor: String!
node: ModelExport!
}

input ModelExportQueryInput {
modelId: String
owner: String
variableName: String
}

type ModelExportRevisionsConnection {
edges: [ModelExportRevisionsConnectionEdge!]!
pageInfo: PageInfo!
}

type ModelExportRevisionsConnectionEdge {
cursor: String!
node: ModelExport!
}

type ModelRevision implements Node {
author: User
buildStatus: ModelRevisionBuildStatus!
comment: String!
content: ModelContent!
createdAtTimestamp: Float!
exportNames: [String!]!
exports: [ModelExport!]!
forRelativeValues(input: ModelRevisionForRelativeValuesInput!): ModelRevisionForRelativeValuesResult!
id: ID!
lastBuild: ModelRevisionBuild
model: Model!
relativeValuesExports: [RelativeValuesExport!]!
variableRevisions: [VariableRevision!]!
}

type ModelRevisionBuild implements Node {
Expand Down Expand Up @@ -542,7 +505,6 @@ type Query {
groups(after: String, before: String, first: Int, input: GroupsQueryInput, last: Int): GroupConnection!
me: Me!
model(input: QueryModelInput!): QueryModelResult!
modelExports(after: String, before: String, first: Int, input: ModelExportQueryInput, last: Int): ModelExportConnection!
models(after: String, before: String, first: Int, last: Int): ModelConnection!

"""Admin-only query for listing models in /admin UI"""
Expand All @@ -555,6 +517,8 @@ type Query {
search(after: String, before: String, first: Int, last: Int, text: String!): QuerySearchResult!
userByUsername(username: String!): QueryUserByUsernameResult!
users(after: String, before: String, first: Int, input: UsersQueryInput, last: Int): QueryUsersConnection!
variable(input: QueryVariableInput!): QueryVariableResult!
variables(after: String, before: String, first: Int, input: VariableQueryInput, last: Int): VariableConnection!
}

union QueryGroupResult = BaseError | Group | NotFoundError
Expand Down Expand Up @@ -592,6 +556,14 @@ type QueryUsersConnectionEdge {
node: User!
}

input QueryVariableInput {
owner: String!
slug: String!
variableName: String!
}

union QueryVariableResult = BaseError | NotFoundError | Variable

type ReactToGroupInviteResult {
invite: GroupInvite!
membership: UserGroupMembership
Expand Down Expand Up @@ -756,11 +728,11 @@ type User implements Node & Owner {
groups(after: String, before: String, first: Int, last: Int): GroupConnection!
id: ID!
isRoot: Boolean!
modelExports(after: String, before: String, first: Int, last: Int): ModelExportConnection!
models(after: String, before: String, first: Int, last: Int): ModelConnection!
relativeValuesDefinitions(after: String, before: String, first: Int, last: Int): RelativeValuesDefinitionConnection!
slug: String!
username: String!
variables(after: String, before: String, first: Int, last: Int): VariableConnection!
}

type UserGroupInvite implements GroupInvite & Node {
Expand Down Expand Up @@ -803,4 +775,50 @@ type ValidationError implements Error {
type ValidationErrorIssue {
message: String!
path: [String!]!
}

type Variable implements Node {
currentRevision: VariableRevision
id: ID!
model: Model!
owner: Owner!
revisions(after: String, before: String, first: Int, last: Int): VariableRevisionConnection!
variableName: String!
}

type VariableConnection {
edges: [VariableEdge!]!
pageInfo: PageInfo!
}

type VariableEdge {
cursor: String!
node: Variable!
}

input VariableQueryInput {
modelId: String
owner: String
variableName: String
variableType: String
}

type VariableRevision implements Node {
docstring: String!
id: ID!
modelRevision: ModelRevision!
title: String
variable: Variable!
variableName: String!
variableType: String!
}

type VariableRevisionConnection {
edges: [VariableRevisionEdge!]!
pageInfo: PageInfo!
}

type VariableRevisionEdge {
cursor: String!
node: VariableRevision!
}
8 changes: 4 additions & 4 deletions packages/hub/src/app/FrontPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { usePageQuery } from "@/relay/usePageQuery";

import { FrontPageDefinitionList } from "./FrontPageDefinitionList";
import { FrontPageGroupList } from "./FrontPageGroupList";
import { FrontPageModelExportList } from "./FrontPageModelExportList";
import { FrontPageModelList } from "./FrontPageModelList";
import { FrontPageVariableList } from "./FrontPageVariableList";

import { FrontPageQuery } from "@/__generated__/FrontPageQuery.graphql";

const Query = graphql`
query FrontPageQuery {
...FrontPageModelList
...FrontPageModelExportList
...FrontPageVariableList
...FrontPageDefinitionList
...FrontPageGroupList
}
Expand All @@ -33,7 +33,7 @@ export const FrontPage: FC<{
<StyledTab.Group>
<StyledTab.List>
<StyledTab name="Models" />
<StyledTab name="Exports" />
<StyledTab name="Variables" />
<StyledTab name="Definitions" />
<StyledTab name="Groups" />
</StyledTab.List>
Expand All @@ -43,7 +43,7 @@ export const FrontPage: FC<{
<FrontPageModelList dataRef={data} />
</StyledTab.Panel>
<StyledTab.Panel>
<FrontPageModelExportList dataRef={data} />
<FrontPageVariableList dataRef={data} />
</StyledTab.Panel>
<StyledTab.Panel>
<FrontPageDefinitionList dataRef={data} />
Expand Down
43 changes: 0 additions & 43 deletions packages/hub/src/app/FrontPageModelExportList.tsx

This file was deleted.

Loading

0 comments on commit e2f93c1

Please sign in to comment.