mirror of
https://github.com/chartdb/chartdb.git
synced 2025-11-02 04:53:27 +00:00
fix(import-database): remove the default fetch from import database (#718)
* fix(import-database): remove the default fetch from import database * fix(import-default): keep the option to fetch extras like default and comments
This commit is contained in:
@@ -7,7 +7,7 @@ cols AS (
|
||||
',"ordinal_position":', toString(col_tuple.4),
|
||||
',"type":"', col_tuple.5, '"',
|
||||
',"nullable":"', if(col_tuple.6 = 'NULLABLE', 'true', 'false'), '"',
|
||||
',"default":"', if(col_tuple.7 = '', 'null', col_tuple.7), '"',
|
||||
',"default":"', col_tuple.7, '"',
|
||||
',"comment":', if(col_tuple.8 = '', '""', toString(toJSONString(col_tuple.8))), '}'),
|
||||
groupArray((
|
||||
col.database,
|
||||
@@ -15,7 +15,7 @@ cols AS (
|
||||
col.name,
|
||||
col.position,
|
||||
col.type,
|
||||
col.default_kind,
|
||||
null as default_kind,
|
||||
col.default_expression,
|
||||
col.comment
|
||||
))
|
||||
|
||||
@@ -124,7 +124,7 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END,
|
||||
',"nullable":', CASE WHEN (cols.IS_NULLABLE = 'YES') THEN true ELSE false END::TEXT,
|
||||
',"default":"', COALESCE(replace(replace(cols.column_default::TEXT, '"', '\\"'), '\\x', '\\\\x'), ''),
|
||||
',"default":"', null,
|
||||
'","collation":"', COALESCE(cols.COLLATION_NAME::TEXT, ''),
|
||||
'","comment":"', COALESCE(replace(replace(dsc.description::TEXT, '"', '\\"'), '\\x', '\\\\x'), ''),
|
||||
'"}')), ',') AS cols_metadata
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
const withExtras = false;
|
||||
const withDefault = `IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), '')`;
|
||||
const withoutDefault = `""`;
|
||||
|
||||
export const mariaDBQuery = `WITH fk_info as (
|
||||
(SELECT (@fk_info:=NULL),
|
||||
(SELECT (0)
|
||||
@@ -76,7 +80,7 @@ export const mariaDBQuery = `WITH fk_info as (
|
||||
END,
|
||||
',"ordinal_position":', cols.ordinal_position,
|
||||
',"nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
|
||||
',"default":"', IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', '\\"'), ''),
|
||||
',"default":"', ${withExtras ? withDefault : withoutDefault},
|
||||
'","collation":"', IFNULL(cols.collation_name, ''), '"}'
|
||||
)))))
|
||||
), indexes as (
|
||||
|
||||
@@ -8,6 +8,11 @@ export const getMySQLQuery = (
|
||||
const databaseEdition: DatabaseEdition | undefined =
|
||||
options.databaseEdition;
|
||||
|
||||
const withExtras = false;
|
||||
|
||||
const withDefault = `IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), '')`;
|
||||
const withoutDefault = `""`;
|
||||
|
||||
const newMySQLQuery = `WITH fk_info as (
|
||||
(SELECT (@fk_info:=NULL),
|
||||
(SELECT (0)
|
||||
@@ -86,7 +91,7 @@ export const getMySQLQuery = (
|
||||
END,
|
||||
',"ordinal_position":', cols.ordinal_position,
|
||||
',"nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
|
||||
',"default":"', IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), ''),
|
||||
',"default":"', ${withExtras ? withDefault : withoutDefault},
|
||||
'","collation":"', IFNULL(cols.collation_name, ''), '"}'
|
||||
)))))
|
||||
), indexes as (
|
||||
@@ -211,7 +216,7 @@ export const getMySQLQuery = (
|
||||
',"scale":', IFNULL(cols.numeric_scale, 'null'), '}'), 'null'),
|
||||
',"ordinal_position":', cols.ordinal_position,
|
||||
',"nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
|
||||
',"default":"', IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', '\\"'), ''),
|
||||
',"default":"', ${withExtras ? withDefault : withoutDefault},
|
||||
'","collation":"', IFNULL(cols.collation_name, ''), '"}')
|
||||
) FROM (
|
||||
SELECT cols.table_schema,
|
||||
|
||||
@@ -80,7 +80,7 @@ WITH fk_info AS (
|
||||
KEY 'ordinal_position' VALUE column_id,
|
||||
KEY 'nullable' VALUE CASE nullable
|
||||
WHEN 'Y' THEN 'true' ELSE 'false' END FORMAT JSON,
|
||||
KEY 'default' VALUE NULL,
|
||||
KEY 'default' VALUE '""' FORMAT JSON,
|
||||
KEY 'collation' VALUE '""' FORMAT JSON
|
||||
RETURNING CLOB
|
||||
) AS json_data
|
||||
|
||||
@@ -55,6 +55,14 @@ export const getPostgresQuery = (
|
||||
AND views.schemaname !~ '^(timescaledb_|_timescaledb_)'
|
||||
`;
|
||||
|
||||
const withExtras = false;
|
||||
|
||||
const withDefault = `COALESCE(replace(replace(cols.column_default, '"', '\\"'), '\\x', '\\\\x'), '')`;
|
||||
const withoutDefault = `null`;
|
||||
|
||||
const withComments = `COALESCE(replace(replace(dsc.description, '"', '\\"'), '\\x', '\\\\x'), '')`;
|
||||
const withoutComments = `null`;
|
||||
|
||||
// Define the base query
|
||||
const query = `${`/* ${databaseEdition ? databaseEditionToLabelMap[databaseEdition] : 'PostgreSQL'} edition */`}
|
||||
WITH fk_info${databaseEdition ? '_' + databaseEdition : ''} AS (
|
||||
@@ -175,9 +183,9 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END,
|
||||
',"nullable":', CASE WHEN (cols.IS_NULLABLE = 'YES') THEN 'true' ELSE 'false' END,
|
||||
',"default":"', COALESCE(replace(replace(cols.column_default, '"', '\\"'), '\\x', '\\\\x'), ''),
|
||||
',"default":"', ${withExtras ? withDefault : withoutDefault},
|
||||
'","collation":"', COALESCE(cols.COLLATION_NAME, ''),
|
||||
'","comment":"', COALESCE(replace(replace(dsc.description, '"', '\\"'), '\\x', '\\\\x'), ''),
|
||||
'","comment":"', ${withExtras ? withComments : withoutComments},
|
||||
'"}')), ',') AS cols_metadata
|
||||
FROM information_schema.columns cols
|
||||
LEFT JOIN pg_catalog.pg_class c
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { DatabaseEdition } from '@/lib/domain/database-edition';
|
||||
import { DatabaseClient } from '@/lib/domain/database-clients';
|
||||
|
||||
const withExtras = true;
|
||||
|
||||
const withDefault = `COALESCE(REPLACE(p.dflt_value, '"', '\\"'), '')`;
|
||||
const withoutDefault = `null`;
|
||||
|
||||
const sqliteQuery = `${`/* Standard SQLite */`}
|
||||
WITH fk_info AS (
|
||||
SELECT
|
||||
@@ -114,7 +119,7 @@ WITH fk_info AS (
|
||||
END
|
||||
ELSE null
|
||||
END,
|
||||
'default', COALESCE(REPLACE(p.dflt_value, '"', '\\"'), '')
|
||||
'default', ${withExtras ? withDefault : withoutDefault}
|
||||
)
|
||||
) AS cols_metadata
|
||||
FROM
|
||||
@@ -287,7 +292,7 @@ WITH fk_info AS (
|
||||
END
|
||||
ELSE null
|
||||
END,
|
||||
'default', COALESCE(REPLACE(p.dflt_value, '"', '\\"'), '')
|
||||
'default', ${withExtras ? withDefault : withoutDefault}
|
||||
)
|
||||
) AS cols_metadata
|
||||
FROM
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { DatabaseEdition } from '@/lib/domain/database-edition';
|
||||
|
||||
const withExtras = false;
|
||||
|
||||
const withDefault = `'"' + STRING_ESCAPE(COALESCE(REPLACE(CAST(cols.COLUMN_DEFAULT AS NVARCHAR(MAX)), '"', '\\"'), ''), 'json') + '"'`;
|
||||
const withoutDefault = `'""'`;
|
||||
|
||||
const sqlServerQuery = `${`/* SQL Server 2017 and above edition (14.0, 15.0, 16.0, 17.0)*/`}
|
||||
WITH fk_info AS (
|
||||
SELECT
|
||||
@@ -81,8 +86,7 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END +
|
||||
', "nullable": ' + CASE WHEN cols.IS_NULLABLE = 'YES' THEN 'true' ELSE 'false' END +
|
||||
', "default": ' +
|
||||
'"' + STRING_ESCAPE(COALESCE(REPLACE(CAST(cols.COLUMN_DEFAULT AS NVARCHAR(MAX)), '"', '\\"'), ''), 'json') + '"' +
|
||||
', "default": ' + ${withExtras ? withDefault : withoutDefault} +
|
||||
', "collation": ' + CASE
|
||||
WHEN cols.COLLATION_NAME IS NULL THEN 'null'
|
||||
ELSE '"' + STRING_ESCAPE(cols.COLLATION_NAME, 'json') + '"'
|
||||
@@ -275,8 +279,7 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END +
|
||||
', "nullable": ' + CASE WHEN cols.IS_NULLABLE = 'YES' THEN 'true' ELSE 'false' END +
|
||||
', "default": ' +
|
||||
'"' + STRING_ESCAPE(COALESCE(REPLACE(CAST(cols.COLUMN_DEFAULT AS NVARCHAR(MAX)), '"', '\\"'), ''), 'json') + '"' +
|
||||
', "default": ' + ${withExtras ? withDefault : withoutDefault} +
|
||||
', "collation": ' +
|
||||
CASE
|
||||
WHEN cols.COLLATION_NAME IS NULL THEN 'null'
|
||||
|
||||
Reference in New Issue
Block a user