mirror of
https://github.com/chartdb/chartdb.git
synced 2026-02-10 13:39:39 -06:00
fix: add defaults in import for all databases (#1014)
This commit is contained in:
@@ -24,9 +24,9 @@ WITH fk_info AS (
|
||||
',"table":"', replace(table_name::TEXT, '"', ''), '"',
|
||||
',"column":"', replace(fk_column::TEXT, '"', ''), '"',
|
||||
',"foreign_key_name":"', foreign_key_name::TEXT, '"',
|
||||
',"reference_schema":"', COALESCE(reference_schema::TEXT, 'public'), '"',
|
||||
',"reference_table":"', reference_table::TEXT, '"',
|
||||
',"reference_column":"', reference_column::TEXT, '"',
|
||||
',"reference_schema":"', COALESCE(replace(reference_schema::TEXT, '"', ''), 'public'), '"',
|
||||
',"reference_table":"', replace(reference_table::TEXT, '"', ''), '"',
|
||||
',"reference_column":"', replace(reference_column::TEXT, '"', ''), '"',
|
||||
',"fk_def":"', replace(fk_def::TEXT, '"', ''),
|
||||
'"}')), ',') as fk_metadata
|
||||
FROM (
|
||||
@@ -124,7 +124,7 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END,
|
||||
',"nullable":', CASE WHEN (cols.IS_NULLABLE = 'YES') THEN true ELSE false END::TEXT,
|
||||
',"default":"', null,
|
||||
',"default":"', COALESCE(replace(replace(cols.column_default::TEXT, '"', '\\"'), '\\x', '\\\\x'), ''),
|
||||
'","collation":"', COALESCE(cols.COLLATION_NAME::TEXT, ''),
|
||||
'","comment":"', COALESCE(replace(replace(dsc.description::TEXT, '"', '\\"'), '\\x', '\\\\x'), ''),
|
||||
'","is_identity":', CASE
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const withExtras = false;
|
||||
const withDefault = `IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), '')`;
|
||||
const withDefault = true;
|
||||
|
||||
const withDefaultExpr = `IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), '')`;
|
||||
const withoutDefault = `""`;
|
||||
|
||||
export const mariaDBQuery = `SET SESSION group_concat_max_len = 10000000;
|
||||
@@ -68,7 +69,7 @@ SELECT CAST(CONCAT(
|
||||
',"scale":', IFNULL(cols.numeric_scale, 'null'), '}'), 'null'),
|
||||
',"ordinal_position":', cols.ordinal_position,
|
||||
',"nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
|
||||
',"default":"', ${withExtras ? withDefault : withoutDefault},
|
||||
',"default":"', ${withDefault ? withDefaultExpr : withoutDefault},
|
||||
'","collation":"', IFNULL(cols.collation_name, ''),
|
||||
'","is_identity":', IF(cols.extra LIKE '%auto_increment%', 'true', 'false'),
|
||||
',"comment":"', REPLACE(REPLACE(IFNULL(cols.column_comment, ''), '"', '\\"'), '\\n', ' '), '"}')
|
||||
|
||||
@@ -8,9 +8,9 @@ export const getMySQLQuery = (
|
||||
const databaseEdition: DatabaseEdition | undefined =
|
||||
options.databaseEdition;
|
||||
|
||||
const withExtras = false;
|
||||
const withDefault = true;
|
||||
|
||||
const withDefault = `IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), '')`;
|
||||
const withDefaultExpr = `IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), '')`;
|
||||
const withoutDefault = `""`;
|
||||
|
||||
const newMySQLQuery = `WITH fk_info as (
|
||||
@@ -91,7 +91,7 @@ export const getMySQLQuery = (
|
||||
END,
|
||||
',"ordinal_position":', cols.ordinal_position,
|
||||
',"nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
|
||||
',"default":"', ${withExtras ? withDefault : withoutDefault},
|
||||
',"default":"', ${withDefault ? withDefaultExpr : withoutDefault},
|
||||
'","collation":"', IFNULL(cols.collation_name, ''),
|
||||
'","is_identity":', IF(cols.extra LIKE '%auto_increment%', 'true', 'false'),
|
||||
',"comment":"', REPLACE(REPLACE(IFNULL(cols.column_comment, ''), '"', '\\\\"'), '\\n', ' '),
|
||||
@@ -220,7 +220,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":"', ${withExtras ? withDefault : withoutDefault},
|
||||
',"default":"', ${withDefault ? withDefaultExpr : withoutDefault},
|
||||
'","collation":"', IFNULL(cols.collation_name, ''),
|
||||
'","comment":"', REPLACE(REPLACE(IFNULL(cols.column_comment, ''), '"', '\\"'), '\\n', ' '), '"}')
|
||||
) FROM (
|
||||
|
||||
@@ -64,8 +64,9 @@ export const getPostgresQuery = (
|
||||
`;
|
||||
|
||||
const withExtras = false;
|
||||
const withDefault = true;
|
||||
|
||||
const withDefault = `COALESCE(replace(replace(cols.column_default, '"', '\\"'), '\\x', '\\\\x'), '')`;
|
||||
const withDefaultExpr = `COALESCE(replace(replace(cols.column_default, '"', '\\"'), '\\x', '\\\\x'), '')`;
|
||||
const withoutDefault = `null`;
|
||||
|
||||
const withComments = `COALESCE(replace(replace(dsc.description, '"', '\\"'), '\\x', '\\\\x'), '')`;
|
||||
@@ -78,9 +79,9 @@ WITH fk_info${databaseEdition ? '_' + databaseEdition : ''} AS (
|
||||
',"table":"', replace(table_name::text, '"', ''), '"',
|
||||
',"column":"', replace(fk_column::text, '"', ''), '"',
|
||||
',"foreign_key_name":"', foreign_key_name, '"',
|
||||
',"reference_schema":"', COALESCE(reference_schema, 'public'), '"',
|
||||
',"reference_table":"', reference_table, '"',
|
||||
',"reference_column":"', reference_column, '"',
|
||||
',"reference_schema":"', COALESCE(replace(reference_schema, '"', ''), 'public'), '"',
|
||||
',"reference_table":"', replace(reference_table, '"', ''), '"',
|
||||
',"reference_column":"', replace(reference_column, '"', ''), '"',
|
||||
',"fk_def":"', replace(fk_def, '"', ''),
|
||||
'"}')), ',') as fk_metadata
|
||||
FROM (
|
||||
@@ -197,7 +198,7 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END,
|
||||
',"nullable":', CASE WHEN (cols.IS_NULLABLE = 'YES') THEN 'true' ELSE 'false' END,
|
||||
',"default":"', ${withExtras ? withDefault : withoutDefault},
|
||||
',"default":"', ${withDefault ? withDefaultExpr : withoutDefault},
|
||||
'","collation":"', COALESCE(cols.COLLATION_NAME, ''),
|
||||
'","comment":"', ${withExtras ? withComments : withoutComments},
|
||||
'","is_identity":', CASE
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DatabaseEdition } from '@/lib/domain/database-edition';
|
||||
|
||||
const withExtras = false;
|
||||
const withDefault = true;
|
||||
|
||||
const withDefault = `'"' + STRING_ESCAPE(COALESCE(REPLACE(CAST(cols.COLUMN_DEFAULT AS NVARCHAR(MAX)), '"', '\\"'), ''), 'json') + '"'`;
|
||||
const withDefaultExpr = `'"' + 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)*/`}
|
||||
@@ -86,7 +86,7 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END +
|
||||
', "nullable": ' + CASE WHEN cols.IS_NULLABLE = 'YES' THEN 'true' ELSE 'false' END +
|
||||
', "default": ' + ${withExtras ? withDefault : withoutDefault} +
|
||||
', "default": ' + ${withDefault ? withDefaultExpr : withoutDefault} +
|
||||
', "collation": ' + CASE
|
||||
WHEN cols.COLLATION_NAME IS NULL THEN 'null'
|
||||
ELSE '"' + STRING_ESCAPE(cols.COLLATION_NAME, 'json') + '"'
|
||||
@@ -284,7 +284,7 @@ cols AS (
|
||||
ELSE 'null'
|
||||
END +
|
||||
', "nullable": ' + CASE WHEN cols.IS_NULLABLE = 'YES' THEN 'true' ELSE 'false' END +
|
||||
', "default": ' + ${withExtras ? withDefault : withoutDefault} +
|
||||
', "default": ' + ${withDefault ? withDefaultExpr : withoutDefault} +
|
||||
', "collation": ' +
|
||||
CASE
|
||||
WHEN cols.COLLATION_NAME IS NULL THEN 'null'
|
||||
|
||||
Reference in New Issue
Block a user