mirror of
https://github.com/dbgate/dbgate
synced 2024-11-21 15:28:20 +00:00
deploy - update fixed data works in test
This commit is contained in:
parent
40d53275e3
commit
3297253906
@ -250,4 +250,51 @@ describe('Deploy database', () => {
|
||||
expect(res.rows[0].cnt.toString()).toEqual('3');
|
||||
})
|
||||
);
|
||||
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Deploy preloaded data - update - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await testDatabaseDeploy(conn, driver, [
|
||||
[
|
||||
{
|
||||
name: 't1.table.yaml',
|
||||
json: {
|
||||
name: 't1',
|
||||
columns: [
|
||||
{ name: 'id', type: 'int' },
|
||||
{ name: 'val', type: 'int' },
|
||||
],
|
||||
primaryKey: ['id'],
|
||||
data: [
|
||||
{ id: 1, val: 1 },
|
||||
{ id: 2, val: 2 },
|
||||
{ id: 3, val: 3 },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 't1.table.yaml',
|
||||
json: {
|
||||
name: 't1',
|
||||
columns: [
|
||||
{ name: 'id', type: 'int' },
|
||||
{ name: 'val', type: 'int' },
|
||||
],
|
||||
primaryKey: ['id'],
|
||||
data: [
|
||||
{ id: 1, val: 1 },
|
||||
{ id: 2, val: 5 },
|
||||
{ id: 3, val: 3 },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
const res = await driver.query(conn, `select val from t1 where id = 2`);
|
||||
expect(res.rows[0].val.toString()).toEqual('5');
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -116,8 +116,8 @@ const engines = [
|
||||
|
||||
const filterLocal = [
|
||||
// filter local testing
|
||||
'MySQL',
|
||||
'PostgreSQL',
|
||||
'-MySQL',
|
||||
'-PostgreSQL',
|
||||
'-SQL Server',
|
||||
'SQLite',
|
||||
'-CockroachDB',
|
||||
|
@ -41,17 +41,14 @@ async function generateDeploySql({
|
||||
noRenameColumn: true,
|
||||
};
|
||||
const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
|
||||
const currentModelPairedPreloaded = await enrichWithPreloadedRows(
|
||||
deployedModel,
|
||||
currentModelPaired,
|
||||
pool,
|
||||
driver
|
||||
);
|
||||
const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, pool, driver);
|
||||
|
||||
// console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
|
||||
// console.log('deployedModel', deployedModel.tables[0]);
|
||||
// console.log('currentModel', currentModel.tables[0]);
|
||||
// console.log('currentModelPaired', currentModelPaired.tables[0]);
|
||||
const res = getAlterDatabaseScript(
|
||||
currentModelPaired,
|
||||
currentModelPairedPreloaded,
|
||||
deployedModel,
|
||||
opts,
|
||||
currentModelPairedPreloaded,
|
||||
|
@ -623,7 +623,7 @@ export class SqlDumper implements AlterProcessor {
|
||||
was = true;
|
||||
this.put('^update %f ^set ', table);
|
||||
this.putCollection(', ', updated, col => this.put('%i=%v', col, row[col]));
|
||||
this.put(' ^ where ');
|
||||
this.put(' ^where ');
|
||||
this.putCollection(' ^and ', key, col => this.put('%i=%v', col, row[col]));
|
||||
}
|
||||
} else {
|
||||
|
@ -11,9 +11,9 @@ export async function enrichWithPreloadedRows(
|
||||
const repl = {};
|
||||
for (const tableTarget of dbTarget.tables) {
|
||||
const tableModel = dbModel.tables.find(x => x.pairingId == tableTarget.pairingId);
|
||||
if (tableModel.preloadedRows?.length || 0 == 0) continue;
|
||||
if ((tableModel.preloadedRows?.length || 0) == 0) continue;
|
||||
const keyColumns = tableModel.preloadedRowsKey || tableModel.primaryKey?.columns?.map(x => x.columnName);
|
||||
if (keyColumns?.length || 0 == 0) continue;
|
||||
if ((keyColumns?.length || 0) == 0) continue;
|
||||
const dmp = driver.createDumper();
|
||||
if (keyColumns.length == 1) {
|
||||
dmp.putCmd(
|
||||
|
Loading…
Reference in New Issue
Block a user