create table dumper

This commit is contained in:
Jan Prochazka 2021-09-05 09:44:40 +02:00
parent d75397d793
commit 2cb3a6b446
2 changed files with 75 additions and 20 deletions

View File

@ -91,4 +91,63 @@ describe('Table create', () => {
});
})
);
test.each(engines.map(engine => [engine.label, engine]))(
'Table with foreign key - %s',
testWrapper(async (conn, driver, engine) => {
await testTableCreate(conn, driver, {
columns: [
{
columnName: 'col1',
dataType: 'int',
notNull: true,
},
{
columnName: 'col2',
dataType: 'int',
notNull: true,
},
],
primaryKey: {
columns: [{ columnName: 'col1' }],
},
foreignKeys: [
{
pureName: 'tested',
refTableName: 't0',
columns: [{ columnName: 'col2', refColumnName: 'id' }],
},
],
});
})
);
test.each(engines.map(engine => [engine.label, engine]))(
'Table with unique - %s',
testWrapper(async (conn, driver, engine) => {
await testTableCreate(conn, driver, {
columns: [
{
columnName: 'col1',
dataType: 'int',
notNull: true,
},
{
columnName: 'col2',
dataType: 'int',
notNull: true,
},
],
primaryKey: {
columns: [{ columnName: 'col1' }],
},
uniques: [
{
pureName: 'tested',
columns: [{ columnName: 'col2' }],
},
],
});
})
);
});

View File

@ -229,29 +229,25 @@ export class SqlDumper implements AlterProcessor {
table.primaryKey.columns.map(x => x.columnName)
);
}
if (table.foreignKeys) {
table.foreignKeys.forEach(fk => {
(table.foreignKeys || []).forEach(fk => {
this.put(',&n');
this.createForeignKeyFore(fk);
});
}
// foreach (var cnt in table.Uniques)
// {
// if (!first) this.put(", &n");
// first = false;
// CreateUniqueCore(cnt);
// }
// foreach (var cnt in table.Checks)
// {
// if (!first) this.put(", &n");
// first = false;
// CreateCheckCore(cnt);
// }
(table.uniques || []).forEach(uq => {
this.put(',&n');
this.createUniqueCore(uq);
});
(table.checks || []).forEach(chk => {
this.put(',&n');
this.createCheckCore(chk);
});
this.put('&<&n)');
this.endCommand();
for (const ix of table.indexes) {
(table.indexes || []).forEach(ix => {
this.createIndex(ix);
}
});
}
createForeignKeyFore(fk: ForeignKeyInfo) {