From ebc68d90d310e4520c1e1bd508cd521448d3a7bc Mon Sep 17 00:00:00 2001 From: Jenn Date: Fri, 2 Apr 2021 07:48:13 -0700 Subject: [PATCH] feat: upgrade prisma to 2.19.0 (#130) * upgrade prisma to 2.19.0 --- .../_templates/graphql/new/graphql.ejs | 2 +- .../template/graphql/context.ts | 2 +- .../template/graphql/modules/profile.ts | 2 +- .../template/graphql/modules/scalars.ts | 2 +- .../template/graphql/modules/user.ts.ejs | 10 +- .../template/graphql/schema.ts | 12 +- .../template/package.json.ejs | 29 +- .../README.md | 69 ----- .../schema.prisma | 33 --- .../steps.json | 271 ------------------ .../README.md | 55 ---- .../schema.prisma | 36 --- .../steps.json | 69 ----- .../migration.sql | 35 +++ .../template/prisma/migrations/migrate.lock | 4 - .../prisma/migrations/migration_lock.toml | 3 + .../template/prisma/schema.prisma | 4 +- 17 files changed, 71 insertions(+), 567 deletions(-) delete mode 100644 packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/README.md delete mode 100644 packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/schema.prisma delete mode 100644 packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/steps.json delete mode 100644 packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/README.md delete mode 100644 packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/schema.prisma delete mode 100644 packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/steps.json create mode 100644 packages/create-bison-app/template/prisma/migrations/20210322221918_initial-migration/migration.sql delete mode 100644 packages/create-bison-app/template/prisma/migrations/migrate.lock create mode 100644 packages/create-bison-app/template/prisma/migrations/migration_lock.toml diff --git a/packages/create-bison-app/template/_templates/graphql/new/graphql.ejs b/packages/create-bison-app/template/_templates/graphql/new/graphql.ejs index 75bf04bd..5bb213e6 100644 --- a/packages/create-bison-app/template/_templates/graphql/new/graphql.ejs +++ b/packages/create-bison-app/template/_templates/graphql/new/graphql.ejs @@ -3,7 +3,7 @@ to: graphql/modules/<%= name %>.ts --- <% camelized = h.inflection.camelize(name) -%> <% plural = h.inflection.pluralize(camelized) -%> -import { objectType, extendType } from '@nexus/schema'; +import { objectType, extendType } from 'nexus'; import { UserInputError, /*ForbiddenError*/ } from 'apollo-server-micro'; // import { isAdmin } from '../services/permissions'; diff --git a/packages/create-bison-app/template/graphql/context.ts b/packages/create-bison-app/template/graphql/context.ts index 9e982a0a..a15b99e6 100644 --- a/packages/create-bison-app/template/graphql/context.ts +++ b/packages/create-bison-app/template/graphql/context.ts @@ -16,7 +16,7 @@ export async function createContext(context: ApolloApiContext): Promise let user: User | null = null; if (authHeader) { - user = await prisma.user.findOne({ where: { id: authHeader.userId } }); + user = await prisma.user.findUnique({ where: { id: authHeader.userId } }); } return { diff --git a/packages/create-bison-app/template/graphql/modules/profile.ts b/packages/create-bison-app/template/graphql/modules/profile.ts index 3f8d84d7..0ef5a5b8 100644 --- a/packages/create-bison-app/template/graphql/modules/profile.ts +++ b/packages/create-bison-app/template/graphql/modules/profile.ts @@ -1,4 +1,4 @@ -import { objectType } from '@nexus/schema'; +import { objectType } from 'nexus'; // Profile Type export const Profile = objectType({ diff --git a/packages/create-bison-app/template/graphql/modules/scalars.ts b/packages/create-bison-app/template/graphql/modules/scalars.ts index 71ad876d..225d4992 100644 --- a/packages/create-bison-app/template/graphql/modules/scalars.ts +++ b/packages/create-bison-app/template/graphql/modules/scalars.ts @@ -1,5 +1,5 @@ import { DateTimeResolver, JSONObjectResolver } from 'graphql-scalars'; -import { asNexusMethod } from '@nexus/schema'; +import { asNexusMethod } from 'nexus'; export const jsonScalar = asNexusMethod(JSONObjectResolver, 'json'); export const dateTimeScalar = asNexusMethod(DateTimeResolver, 'date'); diff --git a/packages/create-bison-app/template/graphql/modules/user.ts.ejs b/packages/create-bison-app/template/graphql/modules/user.ts.ejs index a7f964af..2178cfec 100644 --- a/packages/create-bison-app/template/graphql/modules/user.ts.ejs +++ b/packages/create-bison-app/template/graphql/modules/user.ts.ejs @@ -1,4 +1,4 @@ -import { objectType, extendType, inputObjectType, stringArg, arg } from '@nexus/schema'; +import { objectType, extendType, inputObjectType, stringArg, arg } from 'nexus'; import { Role } from '@prisma/client'; <% if (host.name === 'vercel') { -%> import { UserInputError, ForbiddenError } from 'apollo-server-micro'; @@ -84,7 +84,7 @@ export const Mutations = extendType({ }, resolve: async (_root, args, ctx) => { const { email, password } = args; - const user = await ctx.db.user.findOne({ where: { email } }); + const user = await ctx.db.user.findUnique({ where: { email } }); if (!user) { throw new UserInputError(`No user found for email: ${email}`, { @@ -117,7 +117,7 @@ export const Mutations = extendType({ throw new ForbiddenError('Not authorized'); } - const user = await ctx.db.user.findOne({ where: { email: args.data.email } }); + const user = await ctx.db.user.findUnique({ where: { email: args.data.email } }); if (user) { throw new UserInputError('Email already exists.', { @@ -144,7 +144,7 @@ export const Mutations = extendType({ data: arg({ type: 'SignupInput', required: true }), }, resolve: async (_root, args, ctx) => { - const existingUser = await ctx.db.user.findOne({ where: { email: args.data.email } }); + const existingUser = await ctx.db.user.findUnique({ where: { email: args.data.email } }); if (existingUser) { throw new UserInputError('Email already exists.', { @@ -178,6 +178,6 @@ export const SignupInput = inputObjectType({ definition: (t) => { t.string('email', { required: true }); t.string('password', { required: true }); - t.field('profile', { type: 'ProfileCreateOneWithoutUserInput' }); + t.field('profile', { type: 'ProfileCreateNestedOneWithoutUserInput' }); }, }); diff --git a/packages/create-bison-app/template/graphql/schema.ts b/packages/create-bison-app/template/graphql/schema.ts index 02023e75..90e1532a 100644 --- a/packages/create-bison-app/template/graphql/schema.ts +++ b/packages/create-bison-app/template/graphql/schema.ts @@ -1,6 +1,6 @@ import path from 'path'; -import { fieldAuthorizePlugin, makeSchema } from '@nexus/schema'; +import { declarativeWrappingPlugin, fieldAuthorizePlugin, makeSchema } from 'nexus'; import { nexusPrisma } from 'nexus-plugin-prisma'; import prettierConfig from '../prettier.config'; @@ -13,6 +13,7 @@ export const schema = makeSchema({ types, plugins: [ fieldAuthorizePlugin(), + declarativeWrappingPlugin(), nexusPrisma({ experimentalCRUD: true, outputs: { @@ -27,18 +28,17 @@ export const schema = makeSchema({ schema: path.join(currentDirectory, 'api.graphql'), typegen: path.join(currentDirectory, 'node_modules/@types/nexus-typegen/index.d.ts'), }, - typegenAutoConfig: { - sources: [ + sourceTypes: { + modules: [ { - source: path.join(currentDirectory, 'node_modules/.prisma/client/index.d.ts'), + module: path.join(currentDirectory, 'node_modules/.prisma/client/index.d.ts'), alias: 'db', }, { - source: path.join(currentDirectory, 'graphql', 'context.ts'), + module: path.join(currentDirectory, 'graphql', 'context.ts'), alias: 'ContextModule', }, ], - contextType: 'ContextModule.Context', }, prettierConfig, }); diff --git a/packages/create-bison-app/template/package.json.ejs b/packages/create-bison-app/template/package.json.ejs index 8763a526..96af5caa 100644 --- a/packages/create-bison-app/template/package.json.ejs +++ b/packages/create-bison-app/template/package.json.ejs @@ -6,14 +6,15 @@ "cacheDirectories": [".next/cache"], <% } -%> "scripts": { - "build": "ts-node ./scripts/buildProd", + "build": "ts-node -P tsconfig.cjs.json ./scripts/buildProd", "build:prisma": "prisma generate", "build:next": "next build", "build:nexus": "NODE_ENV=development ts-node -P tsconfig.cjs.json --transpile-only graphql/schema.ts", "cypress:open": "cypress open", "cypress:run": "cypress run", - "db:migrate": "yarn -s prisma migrate up --experimental && yarn build:prisma", - "db:rollback": "yarn prisma migrate down --experimental && yarn build:prisma", + "db:migrate": "yarn -s prisma migrate dev && yarn build:prisma", + "db:deploy": "yarn -s primsa deploy && yarn build:prisma", + "db:reset": "yarn prisma migrate reset && yarn build:prisma", "db:setup": "yarn db:migrate && yarn prisma generate", "db:drop": "DOTENV_CONFIG_PATH=./prisma/.env ts-node -r dotenv/config ./scripts/dropDatabase", "dev": "concurrently -n \"WATCHERS,NEXT\" -c \"black.bgYellow.dim,black.bgCyan.dim\" \"yarn watch:all\" \"next dev\"", @@ -22,7 +23,7 @@ "g:component": "hygen component new --name", "g:graphql": "hygen graphql new --name", "g:page": "hygen page new --name", - "g:migration": "yarn -s prisma migrate save --experimental", + "g:migration": "yarn -s prisma migrate dev", "g:test:component": "hygen test component --name", "g:test:factory": "hygen test factory --name", "g:test:request": "hygen test request --name", @@ -44,8 +45,7 @@ "@apollo/client": "^3.0.2", "@chakra-ui/react": "1.3.4", "@chakra-ui/theme": "1.7.1", - "@nexus/schema": "^0.16.0", - "@prisma/client": "2.8.1", + "@prisma/client": "^2.19.0", <% if (host.name === 'vercel') { -%> "apollo-server-micro": "^2.18.1", <% } -%> @@ -62,7 +62,8 @@ "graphql-type-json": "^0.3.1", "jsonwebtoken": "^8.5.1", "next": "9.5.3", - "nexus-plugin-prisma": "^0.21.0", + "nexus": "^1.0.0", + "nexus-plugin-prisma": "^0.33.0", "react": "16.13.1", "react-dom": "16.13.1", "react-hook-form": "^6.1.0", @@ -70,12 +71,11 @@ }, "devDependencies": { "@apollo/react-testing": "^4.0.0", - "@graphql-codegen/cli": "1.17.6", - "@graphql-codegen/typescript": "1.17.6", + "@graphql-codegen/cli": "^1.21.3", + "@graphql-codegen/typescript": "^1.17.6", "@graphql-codegen/typescript-operations": "^1.17.6", - "@graphql-codegen/typescript-react-apollo": "1.17.6", - "@graphql-codegen/typescript-resolvers": "1.17.4", - "@prisma/cli": "2.8.1", + "@graphql-codegen/typescript-react-apollo": "^1.17.6", + "@graphql-codegen/typescript-resolvers": "^1.17.4", "@testing-library/cypress": "^7.0.2", "@testing-library/dom": "^7.21.7", "@testing-library/jest-dom": "^5.11.2", @@ -83,7 +83,7 @@ "@testing-library/user-event": "^12.0.17", "@types/bcryptjs": "^2.4.2", "@types/jest": "^26.0.6", - "@types/node": "^14.0.26", + "@types/node": "^14.14.21", "@types/react": "^16.9.43", "@types/supertest": "^2.0.10", "@vercel/node": "^1.7.3", @@ -104,11 +104,12 @@ "nanoid": "^3.1.10", "pg": "^8.3.0", "prettier": "^2.0.5", + "prisma": "^2.19.0", "start-server-and-test": "^1.11.2", "supertest": "^4.0.2", "ts-jest": "^26.1.3", "ts-node-dev": "^1.0.0", - "typescript": "^3.9.7" + "typescript": "^4.1.3" }, "bison": { "version": "<%= bisonVersion %>", diff --git a/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/README.md b/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/README.md deleted file mode 100644 index f9c25377..00000000 --- a/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# Migration `20200726094736-initial-migration` - -This migration has been generated by Chris Ball at 7/26/2020, 9:47:36 AM. -You can check out the [state of the schema](./schema.prisma) after the migration. - -## Database Steps - -```sql -CREATE TYPE "Role" AS ENUM ('USER', 'ADMIN'); - -CREATE TABLE "public"."Profile" ( -"id" text NOT NULL ,"userId" text NOT NULL , - PRIMARY KEY ("id")) - -CREATE TABLE "public"."User" ( -"createdAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" text NOT NULL ,"id" text NOT NULL ,"password" text NOT NULL ,"roles" "Role"[] ,"updatedAt" timestamp(3) NOT NULL , - PRIMARY KEY ("id")) - -CREATE UNIQUE INDEX "Profile_userId" ON "public"."Profile"("userId") - -CREATE UNIQUE INDEX "User.email" ON "public"."User"("email") - -ALTER TABLE "public"."Profile" ADD FOREIGN KEY ("userId")REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE -``` - -## Changes - -```diff -diff --git schema.prisma schema.prisma -migration ..20200726094736-initial-migration ---- datamodel.dml -+++ datamodel.dml -@@ -1,0 +1,33 @@ -+// This is your Prisma schema file, -+// learn more about it in the docs: https://pris.ly/d/prisma-schema -+ -+datasource db { -+ provider = "postgresql" -+ url = "***" -+} -+ -+generator client { -+ provider = "prisma-client-js" -+} -+ -+model Profile { -+ id String @id @default(cuid()) -+ userId String -+ user User @relation(fields: [userId], references: [id]) -+} -+ -+model User { -+ id String @id @default(cuid()) -+ email String @unique -+ password String -+ // role Role @default(USER) -+ roles Role[] -+ profile Profile? -+ createdAt DateTime @default(now()) -+ updatedAt DateTime @updatedAt -+} -+ -+enum Role { -+ USER -+ ADMIN -+} -``` - - diff --git a/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/schema.prisma b/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/schema.prisma deleted file mode 100644 index 58f34547..00000000 --- a/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/schema.prisma +++ /dev/null @@ -1,33 +0,0 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -datasource db { - provider = "postgresql" - url = "***" -} - -generator client { - provider = "prisma-client-js" -} - -model Profile { - id String @id @default(cuid()) - userId String - user User @relation(fields: [userId], references: [id]) -} - -model User { - id String @id @default(cuid()) - email String @unique - password String - // role Role @default(USER) - roles Role[] - profile Profile? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -enum Role { - USER - ADMIN -} diff --git a/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/steps.json b/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/steps.json deleted file mode 100644 index 19aa54ac..00000000 --- a/packages/create-bison-app/template/prisma/migrations/20200726094736-initial-migration/steps.json +++ /dev/null @@ -1,271 +0,0 @@ -{ - "version": "0.3.14-fixed", - "steps": [ - { - "tag": "CreateEnum", - "enum": "Role", - "values": [ - "USER", - "ADMIN" - ] - }, - { - "tag": "CreateSource", - "source": "db" - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Source", - "source": "db" - }, - "argument": "provider", - "value": "\"postgresql\"" - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Source", - "source": "db" - }, - "argument": "url", - "value": "\"***\"" - }, - { - "tag": "CreateModel", - "model": "Profile" - }, - { - "tag": "CreateField", - "model": "Profile", - "field": "id", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Profile", - "field": "id" - }, - "directive": "id" - } - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Profile", - "field": "id" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Profile", - "field": "id" - }, - "directive": "default" - }, - "argument": "", - "value": "cuid()" - }, - { - "tag": "CreateField", - "model": "Profile", - "field": "userId", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateField", - "model": "Profile", - "field": "user", - "type": "User", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Profile", - "field": "user" - }, - "directive": "relation" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Profile", - "field": "user" - }, - "directive": "relation" - }, - "argument": "fields", - "value": "[userId]" - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Profile", - "field": "user" - }, - "directive": "relation" - }, - "argument": "references", - "value": "[id]" - }, - { - "tag": "CreateModel", - "model": "User" - }, - { - "tag": "CreateField", - "model": "User", - "field": "id", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "User", - "field": "id" - }, - "directive": "id" - } - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "User", - "field": "id" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "User", - "field": "id" - }, - "directive": "default" - }, - "argument": "", - "value": "cuid()" - }, - { - "tag": "CreateField", - "model": "User", - "field": "email", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "User", - "field": "email" - }, - "directive": "unique" - } - }, - { - "tag": "CreateField", - "model": "User", - "field": "password", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateField", - "model": "User", - "field": "roles", - "type": "Role", - "arity": "List" - }, - { - "tag": "CreateField", - "model": "User", - "field": "profile", - "type": "Profile", - "arity": "Optional" - }, - { - "tag": "CreateField", - "model": "User", - "field": "createdAt", - "type": "DateTime", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "User", - "field": "createdAt" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "User", - "field": "createdAt" - }, - "directive": "default" - }, - "argument": "", - "value": "now()" - }, - { - "tag": "CreateField", - "model": "User", - "field": "updatedAt", - "type": "DateTime", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "User", - "field": "updatedAt" - }, - "directive": "updatedAt" - } - } - ] -} \ No newline at end of file diff --git a/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/README.md b/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/README.md deleted file mode 100644 index 7e3afdea..00000000 --- a/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# Migration `20200726203519-profile-timestamps` - -This migration has been generated by Chris Ball at 7/26/2020, 8:35:19 PM. -You can check out the [state of the schema](./schema.prisma) after the migration. - -## Database Steps - -```sql -ALTER TABLE "public"."Profile" ADD COLUMN "createdAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, -ADD COLUMN "firstName" text NOT NULL , -ADD COLUMN "lastName" text NOT NULL , -ADD COLUMN "updatedAt" timestamp(3) NOT NULL ; -``` - -## Changes - -```diff -diff --git schema.prisma schema.prisma -migration 20200726094736-initial-migration..20200726203519-profile-timestamps ---- datamodel.dml -+++ datamodel.dml -@@ -2,26 +2,29 @@ - // learn more about it in the docs: https://pris.ly/d/prisma-schema - datasource db { - provider = "postgresql" -- url = "***" -+ url = "***" - } - generator client { - provider = "prisma-client-js" - } - model Profile { -- id String @id @default(cuid()) -- userId String -- user User @relation(fields: [userId], references: [id]) -+ id String @id @default(cuid()) -+ firstName String -+ lastName String -+ userId String -+ user User @relation(fields: [userId], references: [id]) -+ createdAt DateTime @default(now()) -+ updatedAt DateTime @updatedAt - } - model User { - id String @id @default(cuid()) - email String @unique - password String -- // role Role @default(USER) - roles Role[] - profile Profile? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -``` - - diff --git a/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/schema.prisma b/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/schema.prisma deleted file mode 100644 index 75219fd7..00000000 --- a/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/schema.prisma +++ /dev/null @@ -1,36 +0,0 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -datasource db { - provider = "postgresql" - url = "***" -} - -generator client { - provider = "prisma-client-js" -} - -model Profile { - id String @id @default(cuid()) - firstName String - lastName String - userId String - user User @relation(fields: [userId], references: [id]) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -model User { - id String @id @default(cuid()) - email String @unique - password String - roles Role[] - profile Profile? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -enum Role { - USER - ADMIN -} diff --git a/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/steps.json b/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/steps.json deleted file mode 100644 index c27f3767..00000000 --- a/packages/create-bison-app/template/prisma/migrations/20200726203519-profile-timestamps/steps.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "version": "0.3.14-fixed", - "steps": [ - { - "tag": "CreateField", - "model": "Profile", - "field": "firstName", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateField", - "model": "Profile", - "field": "lastName", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateField", - "model": "Profile", - "field": "createdAt", - "type": "DateTime", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Profile", - "field": "createdAt" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Profile", - "field": "createdAt" - }, - "directive": "default" - }, - "argument": "", - "value": "now()" - }, - { - "tag": "CreateField", - "model": "Profile", - "field": "updatedAt", - "type": "DateTime", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Profile", - "field": "updatedAt" - }, - "directive": "updatedAt" - } - } - ] -} \ No newline at end of file diff --git a/packages/create-bison-app/template/prisma/migrations/20210322221918_initial-migration/migration.sql b/packages/create-bison-app/template/prisma/migrations/20210322221918_initial-migration/migration.sql new file mode 100644 index 00000000..0010546c --- /dev/null +++ b/packages/create-bison-app/template/prisma/migrations/20210322221918_initial-migration/migration.sql @@ -0,0 +1,35 @@ +-- CreateEnum +CREATE TYPE "Role" AS ENUM ('ADMIN', 'USER'); + +-- CreateTable +CREATE TABLE "Profile" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "firstName" TEXT NOT NULL, + "lastName" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "email" TEXT NOT NULL, + "password" TEXT NOT NULL, + "roles" "Role"[], + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Profile.userId_unique" ON "Profile"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User.email_unique" ON "User"("email"); + +-- AddForeignKey +ALTER TABLE "Profile" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/create-bison-app/template/prisma/migrations/migrate.lock b/packages/create-bison-app/template/prisma/migrations/migrate.lock deleted file mode 100644 index a07cc46a..00000000 --- a/packages/create-bison-app/template/prisma/migrations/migrate.lock +++ /dev/null @@ -1,4 +0,0 @@ -# Prisma Migrate lockfile v1 - -20200726094736-initial-migration -20200726203519-profile-timestamps \ No newline at end of file diff --git a/packages/create-bison-app/template/prisma/migrations/migration_lock.toml b/packages/create-bison-app/template/prisma/migrations/migration_lock.toml new file mode 100644 index 00000000..fbffa92c --- /dev/null +++ b/packages/create-bison-app/template/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/packages/create-bison-app/template/prisma/schema.prisma b/packages/create-bison-app/template/prisma/schema.prisma index 1e22bf62..9fb7960d 100644 --- a/packages/create-bison-app/template/prisma/schema.prisma +++ b/packages/create-bison-app/template/prisma/schema.prisma @@ -1,12 +1,14 @@ // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema +// Latest about migrations: https://www.prisma.io/blog/prisma-migrate-ga-b5eno5g08d0b + datasource db { provider = "postgresql" url = env("DATABASE_URL") } -generator client { +generator prisma_client { provider = "prisma-client-js" }