Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

fix pg import query for comments cols+tbls (#288)

Jonathan Fishner637bfe9611f9
diff --git a/src/lib/data/import-metadata/scripts/postgres-script.ts b/src/lib/data/import-metadata/scripts/postgres-script.ts
index a7c8dc1f..a8f6b893 100644
--- a/src/lib/data/import-metadata/scripts/postgres-script.ts
+++ b/src/lib/data/import-metadata/scripts/postgres-script.ts
@@ -161,7 +161,8 @@ cols AS (
',"nullable":', CASE WHEN (cols.IS_NULLABLE = 'YES') THEN 'true' ELSE 'false' END,
',"default":"', COALESCE(replace(replace(cols.column_default, '"', '\\"'), '\\x', '\\\\x'), ''),
'","collation":"', COALESCE(cols.COLLATION_NAME, ''),
- '","comment":"', COALESCE(dsc.description, ''), '"}')), ',') AS cols_metadata
+ '","comment":"', COALESCE(replace(replace(dsc.description, '"', '\\"'), '\\x', '\\\\x'), ''),
+ '"}')), ',') AS cols_metadata
FROM information_schema.columns cols
LEFT JOIN pg_catalog.pg_class c
ON c.relname = cols.table_name
@@ -204,7 +205,8 @@ cols AS (
FROM pg_stat_user_tables s
WHERE tbls.TABLE_SCHEMA = s.schemaname AND tbls.TABLE_NAME = s.relname),
0), ', "type":"', tbls.TABLE_TYPE, '",', '"engine":"",', '"collation":"",',
- '"comment":"', COALESCE(dsc.description, ''), '"}'
+ '"comment":"', COALESCE(replace(replace(dsc.description, '"', '\\"'), '\\x', '\\\\x'), ''),
+ '"}'
)),
',') AS tbls_metadata
FROM information_schema.tables tbls