Skip to content

Commit

Permalink
feat: add User and Role to schema (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
dysmento authored Dec 7, 2023
1 parent fd49812 commit ebd6ae2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ dist

# Terraform cache
terraform/.terraform
.tool-versions
32 changes: 32 additions & 0 deletions api/db/migrations/20231207173812_add_user_and_role/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT,
"agencyId" INTEGER,
"organizationId" INTEGER NOT NULL,
"roleId" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "Role" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

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

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_agencyId_fkey" FOREIGN KEY ("agencyId") REFERENCES "Agency"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE SET NULL ON UPDATE CASCADE;
24 changes: 24 additions & 0 deletions api/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@ model Agency {
code String
tenant Organization? @relation(fields: [organizationId], references: [id])
organizationId Int?
users User[]
}

model Organization {
id Int @id @default(autoincrement())
agencies Agency[]
users User[]
name String
}

model User {
id Int @id @default(autoincrement())
email String
name String?
agencyId Int?
organizationId Int
roleId Int?
createdAt DateTime @default(now())
updatedAt DateTime
agency Agency? @relation(fields: [agencyId], references: [id])
organization Organization @relation(fields: [organizationId], references: [id])
role Role? @relation(fields: [roleId], references: [id])
}

model Role {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime
users User[]
}
2 changes: 1 addition & 1 deletion api/types/graphql.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Prisma } from "@prisma/client"
import { MergePrismaWithSdlTypes, MakeRelationsOptional } from '@redwoodjs/api'
import { Agency as PrismaAgency, Organization as PrismaOrganization } from '@prisma/client'
import { Agency as PrismaAgency, Organization as PrismaOrganization, User as PrismaUser, Role as PrismaRole } from '@prisma/client'
import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql';
import { RedwoodGraphQLContext } from '@redwoodjs/graphql-server/dist/types';
export type Maybe<T> = T | null;
Expand Down

0 comments on commit ebd6ae2

Please sign in to comment.