├── .gitignore ├── src ├── index.ts ├── introspection.ts ├── all.ts ├── data-proxy.ts ├── query.ts ├── common.ts └── migration.ts ├── .github └── workflows │ ├── size.yml │ └── deploy.yml ├── README.md ├── LICENSE ├── package.json ├── tsconfig.json └── test └── index.test.ts /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | node_modules 4 | dist 5 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { PrismaError as default } from './all' 2 | export * from './all' 3 | export * from './common' 4 | export * from './query' 5 | export * from './migration' 6 | export * from './introspection' 7 | export * from './data-proxy' 8 | -------------------------------------------------------------------------------- /.github/workflows/size.yml: -------------------------------------------------------------------------------- 1 | name: size 2 | on: [pull_request] 3 | jobs: 4 | size: 5 | runs-on: ubuntu-latest 6 | env: 7 | CI_JOB_NUMBER: 1 8 | steps: 9 | - uses: actions/checkout@v1 10 | - uses: andresz1/size-limit-action@v1 11 | with: 12 | github_token: ${{ secrets.GITHUB_TOKEN }} 13 | -------------------------------------------------------------------------------- /src/introspection.ts: -------------------------------------------------------------------------------- 1 | /** `prisma db pull` (Introspection Engine) Error Codes `P4XXX` */ 2 | export const PrismaIntrospectionError = { 3 | /** 4 | * Introspection operation failed to produce a schema file: `{introspection_error}` 5 | */ 6 | FailedProducingSchemaFile: 'P4000', 7 | 8 | /** 9 | * The introspected database was empty. 10 | */ 11 | EmptyDatabase: 'P4001', 12 | 13 | /** 14 | * The schema of the introspected database was inconsistent: {explanation} 15 | */ 16 | InconsistentSchema: 'P4002', 17 | } as const 18 | 19 | export type PrismaIntrospectionError = typeof PrismaIntrospectionError 20 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | build: 8 | name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} 9 | 10 | runs-on: ${{ matrix.os }} 11 | strategy: 12 | matrix: 13 | node: ['14.x'] 14 | os: [ubuntu-latest] 15 | 16 | steps: 17 | - name: Checkout repo 18 | uses: actions/checkout@v2 19 | 20 | - name: Use Node ${{ matrix.node }} 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node }} 24 | 25 | - name: Install deps and build (with cache) 26 | uses: bahmutov/npm-install@v1 27 | 28 | - name: Lint 29 | run: yarn lint 30 | 31 | - name: Test 32 | run: yarn test --ci --coverage --maxWorkers=2 33 | 34 | - name: NPM Publish 35 | uses: JS-DevTools/npm-publish@v1 36 | with: 37 | token: ${{ secrets.NPM_TOKEN }} 38 | check-version: true 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Deploy](https://github.com/vinpac/prisma-error-enum/workflows/Deploy/badge.svg) 2 | [![npm version](https://badge.fury.io/js/prisma-error-enum.svg)](https://badge.fury.io/js/prisma-error-enum) 3 | # prisma-error-enum 4 | 5 | A more descriptive way to detect Prisma Errors. Reference: https://www.prisma.io/docs/reference/api-reference/error-reference#error-codes 6 | 7 | ## Installation 8 | ```shell 9 | yarn add prisma-error-enum 10 | ``` 11 | 12 | ## Usage 13 | ```typescript 14 | import { PrismaError } from 'prisma-error-enum' 15 | 16 | const createUser = () => { 17 | try { 18 | return await prisma.user.create({ 19 | data: { 20 | email, 21 | }, 22 | }) 23 | } catch (error) { 24 | if ( 25 | error.code === PrismaError.UniqueConstraintViolation && 26 | error.meta.target[0] === 'email' 27 | ) { 28 | throw new BetterError( 29 | 'unique_email', 30 | 'This email is already registered by another user', 31 | 'email', 32 | ) 33 | } 34 | 35 | throw error 36 | } 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Vinicius Pacheco 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/all.ts: -------------------------------------------------------------------------------- 1 | import { PrismaCommonError } from './common' 2 | import { PrismaQueryError } from './query' 3 | import { PrismaMigrationError } from './migration' 4 | import { PrismaIntrospectionError } from './introspection' 5 | import { PrismaDataProxyError } from './data-proxy' 6 | 7 | /** Prisma Error Codes */ 8 | export const PrismaError = { 9 | ...PrismaDataProxyError, 10 | ...PrismaIntrospectionError, 11 | ...PrismaMigrationError, 12 | ...PrismaQueryError, 13 | ...PrismaCommonError, 14 | } as const 15 | 16 | export type PrismaError = typeof PrismaError 17 | export type PrismaErrorKey = keyof PrismaError 18 | export type PrismaErrorGroup = 19 | | 'PrismaCommonError' 20 | | 'PrismaQueryError' 21 | | 'PrismaMigrationError' 22 | | 'PrismaIntrospectionError' 23 | | 'PrismaDataProxyError' 24 | export type PrismaErrorGroupKey< 25 | T extends PrismaErrorGroup 26 | > = T extends 'PrismaCommonError' 27 | ? keyof PrismaCommonError 28 | : T extends 'PrismaQueryError' 29 | ? keyof PrismaQueryError 30 | : T extends 'PrismaMigrationError' 31 | ? keyof PrismaMigrationError 32 | : T extends 'PrismaIntrospectionError' 33 | ? keyof PrismaIntrospectionError 34 | : T extends 'PrismaDataProxyError' 35 | ? keyof PrismaDataProxyError 36 | : never 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.3", 3 | "license": "MIT", 4 | "main": "dist/index.js", 5 | "typings": "dist/index.d.ts", 6 | "files": [ 7 | "dist", 8 | "src" 9 | ], 10 | "engines": { 11 | "node": ">=10" 12 | }, 13 | "scripts": { 14 | "start": "tsdx watch", 15 | "build": "tsdx build", 16 | "test": "tsdx test", 17 | "lint": "tsdx lint", 18 | "prepare": "tsdx build", 19 | "size": "size-limit", 20 | "analyze": "size-limit --why" 21 | }, 22 | "peerDependencies": {}, 23 | "husky": { 24 | "hooks": { 25 | "pre-commit": "tsdx lint" 26 | } 27 | }, 28 | "prettier": { 29 | "printWidth": 80, 30 | "semi": false, 31 | "singleQuote": true, 32 | "trailingComma": "all" 33 | }, 34 | "name": "prisma-error-enum", 35 | "author": "Vinicius Pacheco", 36 | "module": "dist/prisma-error-enum.esm.js", 37 | "size-limit": [ 38 | { 39 | "path": "dist/prisma-error-enum.cjs.production.min.js", 40 | "limit": "10 KB" 41 | }, 42 | { 43 | "path": "dist/prisma-error-enum.esm.js", 44 | "limit": "10 KB" 45 | } 46 | ], 47 | "devDependencies": { 48 | "@size-limit/preset-small-lib": "^4.9.2", 49 | "husky": "^5.0.9", 50 | "size-limit": "^4.9.2", 51 | "tsdx": "^0.14.1", 52 | "tslib": "^2.1.0", 53 | "typescript": "^4.1.5" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "module": "esnext", 6 | "lib": ["dom", "esnext"], 7 | "importHelpers": true, 8 | // output .d.ts declaration files for consumers 9 | "declaration": true, 10 | // output .js.map sourcemap files for consumers 11 | "sourceMap": true, 12 | // match output dir to input dir. e.g. dist/index instead of dist/src/index 13 | "rootDir": "./src", 14 | // stricter type-checking for stronger correctness. Recommended by TS 15 | "strict": true, 16 | // linter checks for common issues 17 | "noImplicitReturns": true, 18 | "noFallthroughCasesInSwitch": true, 19 | // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | // use Node's module resolution algorithm, instead of the legacy TS one 23 | "moduleResolution": "node", 24 | // transpile JSX to React.createElement 25 | "jsx": "react", 26 | // interop between ESM and CJS modules. Recommended by TS 27 | "esModuleInterop": true, 28 | // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS 29 | "skipLibCheck": true, 30 | // error out if import and file system have a casing mismatch. Recommended by TS 31 | "forceConsistentCasingInFileNames": true, 32 | // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` 33 | "noEmit": true 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/index.test.ts: -------------------------------------------------------------------------------- 1 | import PrismaErrorEnum, { 2 | PrismaError, 3 | PrismaErrorKey, 4 | PrismaErrorGroup, 5 | PrismaErrorGroupKey, 6 | PrismaCommonError, 7 | PrismaMigrationError, 8 | PrismaQueryError, 9 | PrismaIntrospectionError, 10 | PrismaDataProxyError, 11 | CommonError, 12 | MigrationError, 13 | QueryError, 14 | } from '../src' 15 | 16 | /** Typed Object.keys() */ 17 | const keys = (o: T) => Object.keys(o) as (keyof T)[] 18 | 19 | describe('PrismaError', () => { 20 | test('Default export should be PrismaError', () => { 21 | expect(PrismaErrorEnum).toBe(PrismaError) 22 | }) 23 | 24 | test('PrismaError should contain PrismaCommonError, PrismaMigrationError, PrismaQueryError, PrismaIntrospectionError and PrismaDataProxyError', () => { 25 | expect(PrismaError).toMatchObject({ 26 | ...PrismaCommonError, 27 | ...PrismaMigrationError, 28 | ...PrismaQueryError, 29 | ...PrismaIntrospectionError, 30 | ...PrismaDataProxyError, 31 | }) 32 | }) 33 | 34 | test('PrismaError should not eliminate any errors', () => { 35 | const record: Partial> = {} 36 | const check = (name: T) => ( 37 | key: PrismaErrorGroupKey, 38 | ) => { 39 | if (record[key]) { 40 | throw new Error( 41 | `Both ${record[key]} and ${name} have an error called ${key}. This is a problem for PrismaError`, 42 | ) 43 | } 44 | 45 | record[key] = name 46 | } 47 | 48 | keys(PrismaCommonError).forEach(check('PrismaCommonError')) 49 | keys(PrismaMigrationError).forEach(check('PrismaMigrationError')) 50 | keys(PrismaQueryError).forEach(check('PrismaQueryError')) 51 | keys(PrismaIntrospectionError).forEach(check('PrismaIntrospectionError')) 52 | keys(PrismaDataProxyError).forEach(check('PrismaDataProxyError')) 53 | }) 54 | 55 | test('Should be backward compatible with old variables CommonError, MigrationError and QueryError', () => { 56 | expect(CommonError).toMatchObject(PrismaCommonError) 57 | expect(MigrationError).toMatchObject(PrismaMigrationError) 58 | expect(QueryError).toMatchObject(PrismaQueryError) 59 | expect(PrismaError).toMatchObject({ 60 | ...CommonError, 61 | ...MigrationError, 62 | ...QueryError, 63 | ...PrismaIntrospectionError, 64 | ...PrismaDataProxyError, 65 | }) 66 | }) 67 | }) 68 | -------------------------------------------------------------------------------- /src/data-proxy.ts: -------------------------------------------------------------------------------- 1 | /** Prisma Data Proxy Error Codes `P5XXX` */ 2 | export const PrismaDataProxyError = { 3 | /** 4 | * This request could not be understood by the server 5 | */ 6 | BadRequest: 'P5000', 7 | 8 | /** 9 | * This request must be retried 10 | */ 11 | Retry: 'P5001', 12 | 13 | /** 14 | * The datasource provided is invalid: 15 | * - Could not parse the URL of the datasource 16 | * - Datasource URL must use `prisma://` protocol when `--data-proxy` is used 17 | * - No valid API key found 18 | */ 19 | InvalidDatasource: 'P5002', 20 | 21 | /** 22 | * Requested resource does not exist 23 | */ 24 | ResourceNotFound: 'P5003', 25 | 26 | /** 27 | * The feature is not yet implemented: 28 | * - `beforeExit` event is not yet supported 29 | */ 30 | NotImplemented: 'P5004', 31 | 32 | /** 33 | * Schema needs to be uploaded 34 | */ 35 | SchemaNotUploaded: 'P5005', 36 | 37 | /** 38 | * Unknown server error 39 | */ 40 | UnknownServerError: 'P5006', 41 | 42 | /** 43 | * Unauthorized, check your connection string 44 | */ 45 | Unauthorized: 'P5007', 46 | 47 | /** 48 | * Usage exceeded, retry again later 49 | */ 50 | UsageExceeded: 'P5008', 51 | 52 | /** 53 | * Request timed out 54 | */ 55 | RequestTimedOut: 'P5009', 56 | 57 | /** 58 | * Cannot fetch data from service 59 | */ 60 | CannotFetchFromService: 'P5010', 61 | 62 | /** 63 | * Request parameters are invalid. 64 | * 65 | * Note 66 | * ---- 67 | * You see error {@link PrismaDataProxyError.BadRequest|P5000} when the server cannot understand the request. 68 | * 69 | * In comparison, {@link PrismaDataProxyError.InvalidRequestParameters|P5011} indicates that the server understands the request but rejects it due to failed validation checks, such as parameters being out of range. 70 | */ 71 | InvalidRequestParameters: 'P5011', 72 | 73 | /** 74 | * Engine version is not supported 75 | */ 76 | EngineVersionNotSupported: 'P5012', 77 | 78 | /** 79 | * Engine not started: healthcheck timeout 80 | */ 81 | EngineNotStarted: 'P5013', 82 | 83 | /** 84 | * Unknown engine startup error (contains message and logs) 85 | */ 86 | UnknownEngineStartupError: 'P5014', 87 | 88 | /** 89 | * Interactive transaction error: 90 | * - Could not parse interactive transaction ID 91 | * - Could not find Query Engine for the specified host and transaction ID 92 | * - Could not start interactive transaction 93 | */ 94 | InteractiveTransactionError: 'P5015', 95 | } as const 96 | 97 | export type PrismaDataProxyError = typeof PrismaDataProxyError 98 | -------------------------------------------------------------------------------- /src/query.ts: -------------------------------------------------------------------------------- 1 | /** Prisma Client (Query Engine) Error Codes `P2XXX` */ 2 | export const PrismaQueryError = { 3 | /** 4 | * The provided value for the column is too long for the column's type. Column: `{column_name}` 5 | */ 6 | ValueTooLongForColumnType: 'P2000', 7 | 8 | /** 9 | * The record searched for in the where condition (`{model_name}.{argument_name} = {argument_value}`) does not exist 10 | */ 11 | RecordDoesNotExist: 'P2001', 12 | 13 | /** 14 | * Unique constraint failed on the `{constraint}` 15 | */ 16 | UniqueConstraintViolation: 'P2002', 17 | 18 | /** 19 | * Foreign key constraint failed on the field: `{field_name}` 20 | */ 21 | ForeignConstraintViolation: 'P2003', 22 | 23 | /** 24 | * A constraint failed on the database: `{database_error}` 25 | */ 26 | ConstraintViolation: 'P2004', 27 | 28 | /** 29 | * The value `{field_value}` stored in the database for the field `{field_name}` is invalid for the field's type 30 | */ 31 | InvalidValueForFieldType: 'P2005', 32 | 33 | /** 34 | * The provided value `{field_value}` for `{model_name}` field `{field_name}` is not valid 35 | */ 36 | InvalidValue: 'P2006', 37 | 38 | /** 39 | * Data validation error `{database_error}` 40 | */ 41 | ValidationError: 'P2007', 42 | 43 | /** 44 | * Failed to parse the query `{query_parsing_error}` at `{query_position}` 45 | */ 46 | QueryParsingError: 'P2008', 47 | 48 | /** 49 | * Failed to validate the query: `{query_validation_error}` at `{query_position}` 50 | */ 51 | QueryValidationError: 'P2009', 52 | 53 | /** 54 | * Raw query failed. Code: `{code}`. Message: `{message}` 55 | */ 56 | RawQueryError: 'P2010', 57 | 58 | /** 59 | * Null constraint violation on the `{constraint}` 60 | */ 61 | NullConstraintViolation: 'P2011', 62 | 63 | /** 64 | * Missing a required value at `{path}` 65 | */ 66 | MissingRequiredValue: 'P2012', 67 | 68 | /** 69 | * Missing the required argument `{argument_name}` for field `{field_name}` on `{object_name}`. 70 | */ 71 | MissingRequiredArgument: 'P2013', 72 | 73 | /** 74 | * The change you are trying to make would violate the required relation '{relation_name}' between the `{model_a_name}` and `{model_b_name}` models. 75 | */ 76 | RequiredRelationViolation: 'P2014', 77 | 78 | /** 79 | * A related record could not be found. `{details}` 80 | */ 81 | RelatedRecordNotFound: 'P2015', 82 | 83 | /** 84 | * Query interpretation error. `{details}` 85 | */ 86 | InterpretationError: 'P2016', 87 | 88 | /** 89 | * The records for relation `{relation_name}` between the `{parent_name}` and `{child_name}` models are not connected. 90 | */ 91 | RecordsForParentAndChildNotConnected: 'P2017', 92 | 93 | /** 94 | * The required connected records were not found. `{details}` 95 | */ 96 | RequiredConnnectedRecordsNotFound: 'P2018', 97 | 98 | /** 99 | * Input error. `{details}` 100 | */ 101 | InputError: 'P2019', 102 | 103 | /** 104 | * Value out of range for the type. `{details}` 105 | */ 106 | ValueOutOfRange: 'P2020', 107 | 108 | /** 109 | * The table `{table}` does not exist in the current database. 110 | */ 111 | TableDoesNotExist: 'P2021', 112 | 113 | /** 114 | * The column `{column}` does not exist in the current database. 115 | */ 116 | ColumnDoesNotExist: 'P2022', 117 | 118 | /** 119 | * Inconsistent column data: `{message}` 120 | */ 121 | InconsistentColumnData: 'P2023', 122 | 123 | /** 124 | * Timed out fetching a new connection from the connection pool. (More info: {@link http://pris.ly/d/connection-pool} (Current connection pool timeout: {timeout}, connection limit: {connection_limit}) 125 | */ 126 | TimedOutFetchingConnectionFromThePool: 'P2024', 127 | 128 | /** 129 | * An operation failed because it depends on one or more records that were required but not found. `{cause}` 130 | */ 131 | RecordsNotFound: 'P2025', 132 | 133 | /** 134 | * The current database provider doesn't support a feature that the query used: `{feature}` 135 | */ 136 | UnsupportedProviderFeature: 'P2026', 137 | 138 | /** 139 | * Multiple errors occurred on the database during query execution: `{errors}` 140 | */ 141 | MultipleErrors: 'P2027', 142 | 143 | /** 144 | * Transaction API error: {error} 145 | */ 146 | TransactionAPIError: 'P2028', 147 | 148 | /** 149 | * Cannot find a fulltext index to use for the search, try adding a @@fulltext([Fields...]) to your schema 150 | */ 151 | NoFulltextIndex: 'P2030', 152 | 153 | /** 154 | * Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set. See details: {@link https://pris.ly/d/mongodb-replica-set} 155 | */ 156 | MongoDbReplicaSetRequired: 'P2031', 157 | 158 | /** 159 | * A number used in the query does not fit into a 64 bit signed integer. Consider using `BigInt` as field type if you're trying to store large integers 160 | */ 161 | NumberOutOfRange: 'P2033', 162 | 163 | /** 164 | * Transaction failed due to a write conflict or a deadlock. Please retry your transaction 165 | */ 166 | TransactionFailed: 'P2034', 167 | } as const 168 | 169 | export type PrismaQueryError = typeof PrismaQueryError 170 | 171 | /** 172 | * @deprecated Use {@link PrismaQueryError} instead. 173 | * @example 174 | * ```ts 175 | * import { PrismaQueryError } from 'prisma-error-enum' 176 | * ``` 177 | */ 178 | export const QueryError = PrismaQueryError 179 | -------------------------------------------------------------------------------- /src/common.ts: -------------------------------------------------------------------------------- 1 | /** Prisma Common Error Codes `P1XXX` */ 2 | export const PrismaCommonError = { 3 | /** 4 | * Authentication failed against database server at `{database_host}`, the provided database credentials for `{database_user}` are not valid. Please make sure to provide valid database credentials for the database server at `{database_host}`. 5 | */ 6 | AuthenticationFailed: 'P1000', 7 | 8 | /** 9 | * Can't reach database server at `{database_host}`:`{database_port}` Please make sure your database server is running at `{database_host}`:`{database_port}`. 10 | */ 11 | CouldNotConnectToDatabase: 'P1001', 12 | 13 | /** 14 | * The database server at `{database_host}`:`{database_port}` was reached but timed out. Please try again. Please make sure your database server is running at `{database_host}`:`{database_port}`. 15 | */ 16 | ConnectionTimedOut: 'P1002', 17 | 18 | /** 19 | * Database `{database_file_name}` does not exist at `{database_file_path}` 20 | * 21 | * Database `{database_name}.{database_schema_name}` does not exist on the database server at `{database_host}:{database_port}`. 22 | * 23 | * Database `{database_name}` does not exist on the database server at `{database_host}:{database_port}`. 24 | */ 25 | DatabaseFileNotFound: 'P1003', 26 | 27 | /** 28 | * Operations timed out after `{time}` 29 | */ 30 | OperationsTimedOut: 'P1008', 31 | 32 | /** 33 | * Database `{database_name}` already exists on the database server at `{database_host}:{database_port}` 34 | */ 35 | DatabaseAlreadyExists: 'P1009', 36 | 37 | /** 38 | * User `{database_user}` was denied access on the database `{database_name}` 39 | */ 40 | AccessDeniedForUser: 'P1010', 41 | 42 | /** 43 | * Error opening a TLS connection: `{message}` 44 | */ 45 | TLSConnectionError: 'P1011', 46 | 47 | /** 48 | * Note: If you get error code {@link PrismaCommonError.Error|P1012} after you upgrade Prisma to version 4.0.0 or later, 49 | * see the {@link https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-4#upgrade-your-prisma-schema|version 4.0.0 upgrade guide}. 50 | * A schema that was valid before version 4.0.0 might be invalid in version 4.0.0 and later. The upgrade guide explains how to update your schema to make it valid. 51 | * 52 | * `{full_error}` 53 | * 54 | * Possible {@link PrismaCommonError.Error|P1012} error messages: 55 | * - Argument `{}` is missing. 56 | * - Function `{}` takes `{}` arguments, but received `{}`. 57 | * - Argument `{}` is missing in attribute `@{}`. 58 | * - Argument `{}` is missing in data source block `{}`. 59 | * - Argument `{}` is missing in generator block `{}`. 60 | * - Error parsing attribute `@{}`: `{}` 61 | * - Attribute `@{}` is defined twice. 62 | * - The model with database name `{}` could not be defined because another model with this name exists: `{}` 63 | * - `{}` is a reserved scalar type name and can not be used. 64 | * - The `{}` `{}` cannot be defined because a `{}` with that name already exists. 65 | * - Key `{}` is already defined in `{}`. 66 | * - Argument `{}` is already specified as unnamed argument. 67 | * - Argument `{}` is already specified. 68 | * - No such argument. 69 | * - Field `{}` is already defined on model `{}`. 70 | * - Field `{}` in model `{}` can't be a list. The current connector does not support lists of primitive types. 71 | * - The index name `{}` is declared multiple times. With the current connector index names have to be globally unique. 72 | * - Value `{}` is already defined on enum `{}`. 73 | * - Attribute not known: `@{}`. 74 | * - Function not known: `{}`. 75 | * - Datasource provider not known: `{}`. 76 | * - `shadowDatabaseUrl` is the same as url for datasource `{}`. Please specify a different database as shadow database. 77 | * - The preview feature `{}` is not known. Expected one of: `{}` 78 | * - `{}` is not a valid value for `{}`. 79 | * - Type `{}` is neither a built-in type, nor refers to another model, custom type, or enum. 80 | * - Type `{}` is not a built-in type. 81 | * - Unexpected token. Expected one of: `{}` 82 | * - Environment variable not found: `{}`. 83 | * - Expected a `{}` value, but received `{}` value `{}`. 84 | * - Expected a `{}` value, but failed while parsing `{}`: `{}`. 85 | * - Error validating model `{}`: `{}` 86 | * - Error validating field `{}` in model `{}`: `{}` 87 | * - Error validating datasource `{datasource}`: `{message}` 88 | * - Error validating enum `{}`: `{}` 89 | * - Error validating: `{}` 90 | */ 91 | Error: 'P1012', 92 | 93 | /** 94 | * The provided database string is invalid. `{details}` 95 | */ 96 | InvalidDatabaseString: 'P1013', 97 | 98 | /** 99 | * The underlying `{kind}` for model `{model}` does not exist. 100 | */ 101 | KindForModelDoesNotExist: 'P1014', 102 | 103 | /** 104 | * Your Prisma schema is using features that are not supported for the version of the database. Database version: `{database_version}` 105 | * 106 | * Errors: `{errors}` 107 | */ 108 | UnsupportedFeaturesAtPrismaSchema: 'P1015', 109 | 110 | /** 111 | * Your raw query had an incorrect number of parameters. Expected: `{expected}`, actual: `{actual}`. 112 | */ 113 | IncorrectNumberOfParameters: 'P1016', 114 | 115 | /** 116 | * Server has closed the connection. 117 | */ 118 | ServerClosedConnection: 'P1017', 119 | } as const 120 | 121 | export type PrismaCommonError = typeof PrismaCommonError 122 | 123 | /** 124 | * @deprecated Use {@link PrismaCommonError} instead. 125 | * @example 126 | * ```ts 127 | * import { PrismaCommonError } from 'prisma-error-enum' 128 | * ``` 129 | */ 130 | export const CommonError = PrismaCommonError 131 | -------------------------------------------------------------------------------- /src/migration.ts: -------------------------------------------------------------------------------- 1 | /** Prisma Migrate (Migration Engine) Error Codes `P3XXX` */ 2 | export const PrismaMigrationError = { 3 | /** 4 | * Failed to create database: `{database_error}` 5 | */ 6 | FailedToCreateDatabase: 'P3000', 7 | 8 | /** 9 | * Migration possible with destructive changes and possible data loss: `{migration_engine_destructive_details}` 10 | */ 11 | PossibleDestructiveOrDataLossChanges: 'P3001', 12 | 13 | /** 14 | * The attempted migration was rolled back: `{database_error}` 15 | */ 16 | MigrationRolledBack: 'P3002', 17 | 18 | /** 19 | * The format of migrations changed, the saved migrations are no longer valid. To solve this problem, please follow the steps at: {@link https://pris.ly/d/migrate} 20 | */ 21 | InvalidMigrationFormat: 'P3003', 22 | 23 | /** 24 | * The `{database_name}` database is a system database, it should not be altered with prisma migrate. Please connect to another database. 25 | */ 26 | SystemDatabaseNotSupported: 'P3004', 27 | 28 | /** 29 | * The database schema is not empty. Read more about how to baseline an existing production database: {@link https://pris.ly/d/migrate-baseline} 30 | */ 31 | DatabaseNotEmpty: 'P3005', 32 | 33 | /** 34 | * Migration `{migration_name}` failed to apply cleanly to a temporary database. 35 | * 36 | * `{error_code}`Error: 37 | * 38 | * `{inner_error}` 39 | */ 40 | CouldNotApplyCleanlyToTemporaryDatabase: 'P3006', 41 | 42 | /** 43 | * Some of the requested preview features are not yet allowed in migration engine. Please remove them from your data model before using migrations. (blocked: `{list_of_blocked_features}`) 44 | */ 45 | PreviewFeaturesNotAllowedInMigrationEngine: 'P3007', 46 | 47 | /** 48 | * The migration `{migration_name}` is already recorded as applied in the database. 49 | */ 50 | MigrationAlreadyApplied: 'P3008', 51 | 52 | /** 53 | * migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: {@link https://pris.ly/d/migrate-resolve} 54 | * 55 | * `{details}` 56 | */ 57 | FailedMigrationsFound: 'P3009', 58 | 59 | /** 60 | * The name of the migration is too long. It must not be longer than 200 characters (bytes). 61 | */ 62 | MigrationNameTooLong: 'P3010', 63 | 64 | /** 65 | * Migration `{migration_name}` cannot be rolled back because it was never applied to the database. Hint: did you pass in the whole migration name? (example: `"20201207184859_initial_migration"`) 66 | */ 67 | CannotRollBackANeverAppliedMigration: 'P3011', 68 | 69 | /** 70 | * Migration `{migration_name}` cannot be rolled back because it is not in a failed state. 71 | */ 72 | CannotRollBackANotFailedMigration: 'P3012', 73 | 74 | /** 75 | * Datasource provider arrays are no longer supported in migrate. Please change your datasource to use a single provider. Read more at {@link https://pris.ly/multi-provider-deprecation} 76 | */ 77 | DatasourceProviderArraysNotSupported: 'P3013', 78 | 79 | /** 80 | * Prisma Migrate could not create the shadow database. Please make sure the database user has permission to create databases. Read more about the shadow database (and workarounds) at {@link https://pris.ly/d/migrate-shadow}. 81 | * 82 | * Original error: `{error_code}` 83 | * 84 | * `{inner_error}` 85 | */ 86 | DatasourceProviderDontMatchMigrationLock: 'P3014', 87 | 88 | /** 89 | * Could not find the migration file at `{migration_file_path}`. Please delete the directory or restore the migration file. 90 | */ 91 | MissingMigrationFile: 'P3015', 92 | 93 | /** 94 | * The fallback method for database resets failed, meaning Migrate could not clean up the database entirely. Original error: `{error_code}` 95 | * 96 | * `{inner_error}` 97 | */ 98 | CouldNotCleanupDatabase: 'P3016', 99 | 100 | /** 101 | * The migration `{migration_name}` could not be found. Please make sure that the migration exists, and that you included the whole name of the directory. (example: `"20201207184859_initial_migration"`) 102 | */ 103 | MigrationNotFound: 'P3017', 104 | 105 | /** 106 | * A migration failed to apply. New migrations can not be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: {@link https://pris.ly/d/migrate-resolve} 107 | * 108 | * Migration name: `{migration_name}` 109 | * 110 | * Database error code: `{database_error_code}` 111 | * 112 | * Database error: `{database_error}` 113 | */ 114 | FailedToApplyMigration: 'P3018', 115 | 116 | /** 117 | * The datasource provider `{provider}` specified in your schema does not match the one specified in the migration_lock.toml, `{expected_provider}`. Please remove your current migration directory and start a new migration history with prisma migrate dev. Read more: {@link https://pris.ly/d/migrate-provider-switch} 118 | */ 119 | DatasourceProvidersDontMatch: 'P3019', 120 | 121 | /** 122 | * The automatic creation of shadow databases is disabled on Azure SQL. Please set up a shadow database using the `shadowDatabaseUrl` datasource attribute. 123 | * 124 | * Read the docs page for more details: {@link https://pris.ly/d/migrate-shadow} 125 | */ 126 | ShadowDatabasesAutomaticCreationIsDisabled: 'P3020', 127 | 128 | /** 129 | * Foreign keys cannot be created on this database. Learn more how to handle this: {@link https://pris.ly/d/migrate-no-foreign-keys} 130 | */ 131 | ForeignKeysNotSupported: 'P3021', 132 | 133 | /** 134 | * Direct execution of DDL (Data Definition Language) SQL statements is disabled on this database. Please read more here about how to handle this: {@link https://pris.ly/d/migrate-no-direct-ddl} 135 | */ 136 | DirectDdlIsNotSupported: 'P3022', 137 | } as const 138 | 139 | export type PrismaMigrationError = typeof PrismaMigrationError 140 | 141 | /** 142 | * @deprecated Use {@link PrismaMigrationError} instead. 143 | * @example 144 | * ```ts 145 | * import { PrismaMigrationError } from 'prisma-error-enum' 146 | * ``` 147 | */ 148 | export const MigrationError = PrismaMigrationError 149 | --------------------------------------------------------------------------------