Skip to content

Commit

Permalink
Add initial forms schema
Browse files Browse the repository at this point in the history
  • Loading branch information
kalilsn committed May 29, 2024
1 parent 04dd034 commit b6330b3
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 2 deletions.
33 changes: 33 additions & 0 deletions core/kysely/types/public/FormInputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.

import { type ColumnType, type Insertable, type Selectable, type Updateable } from "kysely";

import { type FormsId } from "./Forms";
import { type PubFieldsId } from "./PubFields";

/** Identifier type for public.form_inputs */
export type FormInputsId = string & { __brand: "FormInputsId" };

/** Represents the table public.form_inputs */
export default interface FormInputsTable {
id: ColumnType<FormInputsId, FormInputsId | undefined, FormInputsId>;

field_id: ColumnType<PubFieldsId, PubFieldsId, PubFieldsId>;

form_id: ColumnType<FormsId, FormsId, FormsId>;

order: ColumnType<string, string, string>;

label: ColumnType<string, string, string>;

required: ColumnType<boolean, boolean, boolean>;

is_submit: ColumnType<boolean, boolean, boolean>;
}

export type FormInputs = Selectable<FormInputsTable>;

export type NewFormInputs = Insertable<FormInputsTable>;

export type FormInputsUpdate = Updateable<FormInputsTable>;
24 changes: 24 additions & 0 deletions core/kysely/types/public/Forms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.

import { type ColumnType, type Insertable, type Selectable, type Updateable } from "kysely";

import { type PubTypesId } from "./PubTypes";

/** Identifier type for public.forms */
export type FormsId = string & { __brand: "FormsId" };

/** Represents the table public.forms */
export default interface FormsTable {
id: ColumnType<FormsId, FormsId | undefined, FormsId>;

name: ColumnType<string, string, string>;

pub_type_id: ColumnType<PubTypesId, PubTypesId, PubTypesId>;
}

export type Forms = Selectable<FormsTable>;

export type NewForms = Insertable<FormsTable>;

export type FormsUpdate = Updateable<FormsTable>;
6 changes: 6 additions & 0 deletions core/kysely/types/public/PublicSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { type default as ActionInstancesTable } from "./ActionInstances";
import { type default as ActionMoveTable } from "./ActionMove";
import { type default as AuthTokensTable } from "./AuthTokens";
import { type default as CommunitiesTable } from "./Communities";
import { type default as FormInputsTable } from "./FormInputs";
import { type default as FormsTable } from "./Forms";
import { type default as IntegrationInstancesTable } from "./IntegrationInstances";
import { type default as IntegrationInstanceStateTable } from "./IntegrationInstanceState";
import { type default as IntegrationInstanceToPubTable } from "./IntegrationInstanceToPub";
Expand Down Expand Up @@ -83,4 +85,8 @@ export default interface PublicSchema {
PubsInStages: PubsInStagesTable;

rules: RulesTable;

forms: FormsTable;

form_inputs: FormInputsTable;
}
30 changes: 30 additions & 0 deletions core/prisma/migrations/20240529145416_add_forms/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- CreateTable
CREATE TABLE "forms" (
"id" TEXT NOT NULL DEFAULT gen_random_uuid(),
"name" TEXT NOT NULL,
"pub_type_id" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "form_inputs" (
"id" TEXT NOT NULL DEFAULT gen_random_uuid(),
"field_id" TEXT NOT NULL,
"form_id" TEXT NOT NULL,
"order" TEXT NOT NULL,
"label" TEXT NOT NULL,
"required" BOOLEAN NOT NULL,
"is_submit" BOOLEAN NOT NULL,

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

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

-- AddForeignKey
ALTER TABLE "form_inputs" ADD CONSTRAINT "form_inputs_field_id_fkey" FOREIGN KEY ("field_id") REFERENCES "pub_fields"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "form_inputs" ADD CONSTRAINT "form_inputs_form_id_fkey" FOREIGN KEY ("form_id") REFERENCES "forms"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
30 changes: 28 additions & 2 deletions core/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ model PubField {
schema PubFieldSchema? @relation(fields: [pubFieldSchemaId], references: [id])
pubFieldSchemaId String?
values PubValue[]
pubTypes PubType[]
values PubValue[]
pubTypes PubType[]
FormInput FormInput[]
@@map(name: "pub_fields")
}
Expand Down Expand Up @@ -148,6 +149,7 @@ model PubType {
fields PubField[]
pubs Pub[]
Form Form[]
@@map(name: "pub_types")
}
Expand Down Expand Up @@ -364,3 +366,27 @@ enum Event {
pubEnteredStage
pubLeftStage
}

model Form {
id String @id @default(dbgenerated("gen_random_uuid()"))
name String
pubType PubType @relation(fields: [pubTypeId], references: [id])
pubTypeId String @map(name: "pub_type_id")
FormInput FormInput[]
@@map(name: "forms")
}

model FormInput {
id String @id @default(dbgenerated("gen_random_uuid()"))
fieldId String @map(name: "field_id")
field PubField @relation(fields: [fieldId], references: [id])
formId String @map(name: "form_id")
order String
label String
required Boolean
form Form @relation(fields: [formId], references: [id])
isSubmit Boolean @map(name: "is_submit") // TODO: add partial index so only one of these can be true per formId
@@map(name: "form_inputs")
}

0 comments on commit b6330b3

Please sign in to comment.