mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
deploy - update fixed data works in test
This commit is contained in:
@@ -250,4 +250,51 @@ describe('Deploy database', () => {
|
|||||||
expect(res.rows[0].cnt.toString()).toEqual('3');
|
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 = [
|
const filterLocal = [
|
||||||
// filter local testing
|
// filter local testing
|
||||||
'MySQL',
|
'-MySQL',
|
||||||
'PostgreSQL',
|
'-PostgreSQL',
|
||||||
'-SQL Server',
|
'-SQL Server',
|
||||||
'SQLite',
|
'SQLite',
|
||||||
'-CockroachDB',
|
'-CockroachDB',
|
||||||
|
|||||||
@@ -41,17 +41,14 @@ async function generateDeploySql({
|
|||||||
noRenameColumn: true,
|
noRenameColumn: true,
|
||||||
};
|
};
|
||||||
const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
|
const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
|
||||||
const currentModelPairedPreloaded = await enrichWithPreloadedRows(
|
const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, pool, driver);
|
||||||
deployedModel,
|
|
||||||
currentModelPaired,
|
// console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
|
||||||
pool,
|
|
||||||
driver
|
|
||||||
);
|
|
||||||
// console.log('deployedModel', deployedModel.tables[0]);
|
// console.log('deployedModel', deployedModel.tables[0]);
|
||||||
// console.log('currentModel', currentModel.tables[0]);
|
// console.log('currentModel', currentModel.tables[0]);
|
||||||
// console.log('currentModelPaired', currentModelPaired.tables[0]);
|
// console.log('currentModelPaired', currentModelPaired.tables[0]);
|
||||||
const res = getAlterDatabaseScript(
|
const res = getAlterDatabaseScript(
|
||||||
currentModelPaired,
|
currentModelPairedPreloaded,
|
||||||
deployedModel,
|
deployedModel,
|
||||||
opts,
|
opts,
|
||||||
currentModelPairedPreloaded,
|
currentModelPairedPreloaded,
|
||||||
|
|||||||
@@ -623,7 +623,7 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
was = true;
|
was = true;
|
||||||
this.put('^update %f ^set ', table);
|
this.put('^update %f ^set ', table);
|
||||||
this.putCollection(', ', updated, col => this.put('%i=%v', col, row[col]));
|
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]));
|
this.putCollection(' ^and ', key, col => this.put('%i=%v', col, row[col]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ export async function enrichWithPreloadedRows(
|
|||||||
const repl = {};
|
const repl = {};
|
||||||
for (const tableTarget of dbTarget.tables) {
|
for (const tableTarget of dbTarget.tables) {
|
||||||
const tableModel = dbModel.tables.find(x => x.pairingId == tableTarget.pairingId);
|
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);
|
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();
|
const dmp = driver.createDumper();
|
||||||
if (keyColumns.length == 1) {
|
if (keyColumns.length == 1) {
|
||||||
dmp.putCmd(
|
dmp.putCmd(
|
||||||
|
|||||||
Reference in New Issue
Block a user