This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(graphql-migrations): migration failed for auto increments column
Migrations failed if the field was not "id" and the scalar was "ID"
- Loading branch information
Enda Phelan
committed
Sep 18, 2020
1 parent
2a1ffb9
commit f82f88c
Showing
3 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/graphql-migrations/src/util/isAutoIncrementableColumn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Knex from 'knex'; | ||
|
||
/** | ||
* Detect if the column is incrementable based on column information | ||
* | ||
* @param {string} client - database client | ||
* @param {Knex.ColumnInfo} columnInfo - metadata for column | ||
*/ | ||
export function isAutoIncrementableColumn (client: string, columnInfo: Knex.ColumnInfo): boolean { | ||
switch (client) { | ||
case 'pg': | ||
return columnInfo.defaultValue?.toString().startsWith('nextval('); | ||
case 'sqlite3': | ||
// sqlite3 primary keys not supported | ||
return false; | ||
default: | ||
console.warn(`${client} increments column detection not supported`) | ||
|
||
return false; | ||
} | ||
} |