This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0a3c63
commit 1306da8
Showing
4 changed files
with
218 additions
and
82 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
105 changes: 105 additions & 0 deletions
105
cli/packages/prisma-cli-engine/src/Client/migrationFragment.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,105 @@ | ||
const RELATION_MANIFESTATION_FRAGMENT = ` | ||
type | ||
... on Inline { | ||
model | ||
column | ||
} | ||
... on LinkTable { | ||
table | ||
modelAColumn | ||
modelBColumn | ||
idColumn | ||
type | ||
} | ||
` | ||
|
||
/** | ||
* Generated a graphql fragment for the step type of the management api | ||
* @param r renderMigrationManifestations | ||
*/ | ||
export const renderStepFragment = (r: boolean) => ` | ||
type | ||
__typename | ||
... on CreateEnum { | ||
name | ||
ce_values: values | ||
} | ||
... on CreateField { | ||
model | ||
name | ||
cf_typeName: typeName | ||
cf_isRequired: isRequired | ||
cf_isList: isList | ||
cf_isUnique: unique | ||
cf_relation: relation | ||
cf_defaultValue: default | ||
cf_enum: enum | ||
} | ||
... on CreateModel { | ||
name | ||
} | ||
... on CreateRelation { | ||
name | ||
leftModel | ||
rightModel | ||
${r ? `after { ${RELATION_MANIFESTATION_FRAGMENT} }` : ''} | ||
} | ||
${ | ||
r | ||
? ` | ||
... on UpdateRelation { | ||
ur_name: name | ||
ur_newName: newName | ||
before { ${RELATION_MANIFESTATION_FRAGMENT} } | ||
ur_after: after { ${RELATION_MANIFESTATION_FRAGMENT} } | ||
} | ||
` | ||
: '' | ||
} | ||
... on DeleteEnum { | ||
name | ||
} | ||
... on DeleteField { | ||
model | ||
name | ||
} | ||
... on DeleteModel { | ||
name | ||
} | ||
... on DeleteRelation { | ||
name | ||
} | ||
... on UpdateEnum { | ||
name | ||
newName | ||
values | ||
} | ||
... on UpdateField { | ||
model | ||
name | ||
newName | ||
typeName | ||
isRequired | ||
isList | ||
isUnique: unique | ||
relation | ||
default | ||
enum | ||
} | ||
... on UpdateModel { | ||
name | ||
um_newName: newName | ||
} | ||
` | ||
|
||
export const renderMigrationFragment = ( | ||
renderRelationManifestations: boolean, | ||
) => ` | ||
fragment MigrationFragment on Migration { | ||
revision | ||
steps { | ||
${renderStepFragment(renderRelationManifestations)} | ||
} | ||
} | ||
` |
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