mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 12:36:01 +00:00
default value test + fixed clickhouse default support
This commit is contained in:
@@ -6,9 +6,10 @@ const ix1Sql = 'CREATE index ix1 ON t1(val1, id)';
|
|||||||
const t2Sql = engine =>
|
const t2Sql = engine =>
|
||||||
`CREATE TABLE t2 (id int not null primary key, val2 varchar(50) ${engine.skipUnique ? '' : 'unique'})`;
|
`CREATE TABLE t2 (id int not null primary key, val2 varchar(50) ${engine.skipUnique ? '' : 'unique'})`;
|
||||||
const t3Sql = 'CREATE TABLE t3 (id int not null primary key, valfk int, foreign key (valfk) references t2(id))';
|
const t3Sql = 'CREATE TABLE t3 (id int not null primary key, valfk int, foreign key (valfk) references t2(id))';
|
||||||
|
const t4Sql = 'CREATE TABLE t4 (id int not null primary key, valdef int not null default 12)';
|
||||||
// const fkSql = 'ALTER TABLE t3 ADD FOREIGN KEY (valfk) REFERENCES t2(id)'
|
// const fkSql = 'ALTER TABLE t3 ADD FOREIGN KEY (valfk) REFERENCES t2(id)'
|
||||||
|
|
||||||
const txMatch = (engine, tname, vcolname, nextcol) =>
|
const txMatch = (engine, tname, vcolname, nextcol, defaultValue) =>
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
pureName: tname,
|
pureName: tname,
|
||||||
columns: [
|
columns: [
|
||||||
@@ -19,10 +20,14 @@ const txMatch = (engine, tname, vcolname, nextcol) =>
|
|||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
columnName: vcolname,
|
columnName: vcolname,
|
||||||
...(engine.skipNullability ? {} : { notNull: false }),
|
...(engine.skipNullability ? {} : { notNull: !!defaultValue }),
|
||||||
dataType: engine.skipStringLength
|
...(defaultValue
|
||||||
? expect.stringMatching(/.*string|char.*/i)
|
? { defaultValue }
|
||||||
: expect.stringMatching(/.*char.*\(50\)/i),
|
: {
|
||||||
|
dataType: engine.skipStringLength
|
||||||
|
? expect.stringMatching(/.*string|char.*/i)
|
||||||
|
: expect.stringMatching(/.*char.*\(50\)/i),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
...(nextcol
|
...(nextcol
|
||||||
? [
|
? [
|
||||||
@@ -48,6 +53,7 @@ const txMatch = (engine, tname, vcolname, nextcol) =>
|
|||||||
const t1Match = engine => txMatch(engine, 't1', 'val1');
|
const t1Match = engine => txMatch(engine, 't1', 'val1');
|
||||||
const t2Match = engine => txMatch(engine, 't2', 'val2');
|
const t2Match = engine => txMatch(engine, 't2', 'val2');
|
||||||
const t2NextColMatch = engine => txMatch(engine, 't2', 'val2', true);
|
const t2NextColMatch = engine => txMatch(engine, 't2', 'val2', true);
|
||||||
|
const t4Match = engine => txMatch(engine, 't4', 'valdef', null, '12');
|
||||||
|
|
||||||
describe('Table analyse', () => {
|
describe('Table analyse', () => {
|
||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
@@ -169,4 +175,16 @@ describe('Table analyse', () => {
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
|
'Table structure - default value - %s',
|
||||||
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
await driver.query(conn, t4Sql);
|
||||||
|
|
||||||
|
const structure = await driver.analyseFull(conn);
|
||||||
|
|
||||||
|
expect(structure.tables.length).toEqual(1);
|
||||||
|
expect(structure.tables[0]).toEqual(t4Match(engine));
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ select
|
|||||||
tables.uuid as "objectId",
|
tables.uuid as "objectId",
|
||||||
columns.name as "columnName",
|
columns.name as "columnName",
|
||||||
columns.type as "dataType",
|
columns.type as "dataType",
|
||||||
columns.comment as "columnComment"
|
columns.comment as "columnComment",
|
||||||
|
columns.default_expression as "defaultValue"
|
||||||
from system.columns
|
from system.columns
|
||||||
inner join system.tables on columns.table = tables.name and columns.database = tables.database
|
inner join system.tables on columns.table = tables.name and columns.database = tables.database
|
||||||
where columns.database='#DATABASE#' and tables.uuid =OBJECT_ID_CONDITION
|
where columns.database='#DATABASE#' and tables.uuid =OBJECT_ID_CONDITION
|
||||||
|
|||||||
Reference in New Issue
Block a user