Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
feat: add includeConstraintName config option
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlettau committed Sep 10, 2019
1 parent 7367c73 commit 0235d94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ following properties are supported.
1. `if-exists-drop`, `if-not-exists`, or `false`.
2. `delete-and-reseed`, `delete`, `truncate`, or `false`.

**includeConstraintName** (`boolean`): Optional. Indicates if constraint names should be scripted. Default is `false`.

# Examples

### Connections
Expand Down
6 changes: 6 additions & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export default class Config implements IConfig {
views: 'if-exists-drop'
};

/**
* Indicates if constraint names should be scripted.
*/
includeConstraintName = false;

/**
* Get root output directory.
*/
Expand Down Expand Up @@ -217,6 +222,7 @@ export default class Config implements IConfig {
this.files = config.files || this.files;
Object.assign(this.output, config.output);
Object.assign(this.idempotency, config.idempotency);
this.includeConstraintName = config.includeConstraintName || this.includeConstraintName;
} catch (error) {
console.error('Could not find or parse config file. You can use the `init` command to create one!');
process.exit();
Expand Down
3 changes: 2 additions & 1 deletion src/generators/mssql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,10 @@ export default class MSSQLGenerator {
output += item.is_nullable ? ' NULL' : ' NOT NULL';

if (item.definition) {
if (item.default_name) {
if (this.config.includeConstraintName && item.default_name) {
output += ` CONSTRAINT [${item.default_name}]`;
}

output += ` DEFAULT${item.definition}`;
}

Expand Down

0 comments on commit 0235d94

Please sign in to comment.