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

fix: corrected data generation #117

Merged
merged 2 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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