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

Commit

Permalink
fix: corrected data generation (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaxelr authored Jul 12, 2020
1 parent 3778d50 commit e109f7d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ export default class Pull {

return pool
.request()
.query(`SELECT * FROM ${item}`)
.query(`SELECT * FROM [${match.schema}].[${match.name}]`)
.then(result => ({
hasIdentity: match.identity_count > 0,
name: item,
name: match.name,
schema: match.schema,
result
}));
})
Expand Down Expand Up @@ -214,7 +215,7 @@ export default class Pull {

// data
data.forEach(item => {
const name = `${item.name}.sql`;
const name = `${item.schema}.${item.name}.sql`;
const content = generator.data(item);

file.write(config.output.data, name, content);
Expand Down
15 changes: 8 additions & 7 deletions src/generators/mssql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ export default class MSSQLGenerator {

switch (this.config.idempotency.data) {
case 'delete':
output += `DELETE FROM ${item.name}` + EOL;
output += `DELETE FROM [${item.schema}].[${item.name}]` + EOL;
output += EOL;
break;
case 'delete-and-reseed':
output += `DELETE FROM ${item.name}`;
output += `DELETE FROM [${item.schema}].[${item.name}]`;
output += EOL;
output += `DBCC CHECKIDENT ('${item.name}', RESEED, 0)`;
output += `DBCC CHECKIDENT ('[${item.schema}].[${item.name}]', RESEED, 0)`;
output += EOL;
break;
case 'truncate':
output += `TRUNCATE TABLE ${item.name}`;
output += `TRUNCATE TABLE [${item.schema}].[${item.name}]`;
output += EOL;
break;
}

output += EOL;

if (item.hasIdentity) {
output += `SET IDENTITY_INSERT ${item.name} ON`;
output += `SET IDENTITY_INSERT [${item.schema}].[${item.name}] ON`;
output += EOL;
output += EOL;
}
Expand All @@ -70,13 +70,14 @@ export default class MSSQLGenerator {
const columns = keys.join(', ');
const values = keys.map(key => this.safeValue(row[key])).join(', ');

output += `INSERT INTO ${item.name} (${columns}) VALUES (${values})`;
output += `INSERT INTO [${item.schema}].[${item.name}] (${columns}) VALUES (${values})`;
output += EOL;
});

if (item.hasIdentity) {
output += EOL;
output += `SET IDENTITY_INSERT ${item.name} OFF`;
output += `SET IDENTITY_INSERT [${item.schema}].[${item.name}]
OFF`;
output += EOL;
}

Expand Down
1 change: 1 addition & 0 deletions src/queries/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SqlSchema {
*/
export interface SqlDataResult {
name: string;
schema: string;
hasIdentity: number;
result: sql.IResult<any>;
}
Expand Down

0 comments on commit e109f7d

Please sign in to comment.