mirror of
https://github.com/chartdb/chartdb.git
synced 2025-12-19 18:40:43 -06:00
fix: use flag for custom types (#951)
This commit is contained in:
@@ -9,7 +9,10 @@ import { exportPostgreSQL } from './export-per-type/postgresql';
|
||||
import { exportSQLite } from './export-per-type/sqlite';
|
||||
import { exportMySQL } from './export-per-type/mysql';
|
||||
import { escapeSQLComment } from './export-per-type/common';
|
||||
import { databaseTypesWithCommentSupport } from '@/lib/domain/database-capabilities';
|
||||
import {
|
||||
databaseTypesWithCommentSupport,
|
||||
supportsCustomTypes,
|
||||
} from '@/lib/domain/database-capabilities';
|
||||
|
||||
// Function to format default values with proper quoting
|
||||
const formatDefaultValue = (value: string): string => {
|
||||
@@ -198,10 +201,7 @@ export const exportBaseSQL = ({
|
||||
// or if we rely on the DBML generator to create Enums separately (as currently done)
|
||||
// For now, let's assume PostgreSQL-style for demonstration if isDBMLFlow is false.
|
||||
// If isDBMLFlow is true, we let TableDBML.tsx handle Enum syntax directly.
|
||||
if (
|
||||
targetDatabaseType === DatabaseType.POSTGRESQL &&
|
||||
!isDBMLFlow
|
||||
) {
|
||||
if (supportsCustomTypes(targetDatabaseType) && !isDBMLFlow) {
|
||||
const enumValues = customType.values
|
||||
.map((v) => `'${v.replace(/'/g, "''")}'`)
|
||||
.join(', ');
|
||||
@@ -214,10 +214,7 @@ export const exportBaseSQL = ({
|
||||
) {
|
||||
// For PostgreSQL, generate CREATE TYPE ... AS (...)
|
||||
// This is crucial for composite types to be recognized by the DBML importer
|
||||
if (
|
||||
targetDatabaseType === DatabaseType.POSTGRESQL ||
|
||||
isDBMLFlow
|
||||
) {
|
||||
if (supportsCustomTypes(targetDatabaseType) || isDBMLFlow) {
|
||||
// Assume other DBs might not support this or DBML flow needs it
|
||||
const compositeFields = customType.fields
|
||||
.map((f) => `${f.field} ${simplifyDataType(f.type)}`)
|
||||
@@ -232,13 +229,12 @@ export const exportBaseSQL = ({
|
||||
(ct.kind === 'enum' &&
|
||||
ct.values &&
|
||||
ct.values.length > 0 &&
|
||||
targetDatabaseType === DatabaseType.POSTGRESQL &&
|
||||
supportsCustomTypes(targetDatabaseType) &&
|
||||
!isDBMLFlow) ||
|
||||
(ct.kind === 'composite' &&
|
||||
ct.fields &&
|
||||
ct.fields.length > 0 &&
|
||||
(targetDatabaseType === DatabaseType.POSTGRESQL ||
|
||||
isDBMLFlow))
|
||||
(supportsCustomTypes(targetDatabaseType) || isDBMLFlow))
|
||||
)
|
||||
) {
|
||||
sqlScript += '\n';
|
||||
@@ -298,7 +294,7 @@ export const exportBaseSQL = ({
|
||||
|
||||
if (
|
||||
customEnumType &&
|
||||
targetDatabaseType === DatabaseType.POSTGRESQL &&
|
||||
supportsCustomTypes(targetDatabaseType) &&
|
||||
!isDBMLFlow
|
||||
) {
|
||||
typeName = customEnumType.schema
|
||||
|
||||
@@ -10,6 +10,7 @@ import { defaultTableColor } from '@/lib/colors';
|
||||
import { DatabaseType } from '@/lib/domain/database-type';
|
||||
import type { DBCustomType } from '@/lib/domain/db-custom-type';
|
||||
import { DBCustomTypeKind } from '@/lib/domain/db-custom-type';
|
||||
import { supportsCustomTypes } from '@/lib/domain/database-capabilities';
|
||||
|
||||
// Common interfaces for SQL entities
|
||||
export interface SQLColumn {
|
||||
@@ -663,7 +664,7 @@ export function convertToChartDBDiagram(
|
||||
// Ensure integer types are preserved
|
||||
mappedType = { id: 'integer', name: 'integer' };
|
||||
} else if (
|
||||
sourceDatabaseType === DatabaseType.POSTGRESQL &&
|
||||
supportsCustomTypes(sourceDatabaseType) &&
|
||||
parserResult.enums &&
|
||||
parserResult.enums.some(
|
||||
(e) => e.name.toLowerCase() === column.type.toLowerCase()
|
||||
|
||||
@@ -459,64 +459,12 @@ export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
|
||||
)}
|
||||
>
|
||||
<span className="block truncate">
|
||||
{
|
||||
// fieldDiffChangedType ? (
|
||||
// <>
|
||||
// <span className="line-through">
|
||||
// {
|
||||
// fieldDiffChangedType.old.name.split(
|
||||
// ' '
|
||||
// )[0]
|
||||
// }
|
||||
// </span>{' '}
|
||||
// {
|
||||
// fieldDiffChangedType.new.name.split(
|
||||
// ' '
|
||||
// )[0]
|
||||
// }
|
||||
// </>
|
||||
// ) :
|
||||
isFieldAttributeChanged ||
|
||||
fieldDiffChangedType ? (
|
||||
<>
|
||||
<span className="line-through">
|
||||
{
|
||||
(
|
||||
fieldDiffChangedType?.old
|
||||
?.name ??
|
||||
field.type.name
|
||||
).split(' ')[0]
|
||||
}
|
||||
{showFieldAttributes
|
||||
? generateDBFieldSuffix(
|
||||
{
|
||||
...field,
|
||||
...{
|
||||
precision:
|
||||
fieldDiffChangedPrecision?.old ??
|
||||
field.precision,
|
||||
scale:
|
||||
fieldDiffChangedScale?.old ??
|
||||
field.scale,
|
||||
characterMaximumLength:
|
||||
fieldDiffChangedCharacterMaximumLength?.old ??
|
||||
field.characterMaximumLength,
|
||||
isArray:
|
||||
fieldDiffChangedIsArray?.old ??
|
||||
field.isArray,
|
||||
},
|
||||
},
|
||||
{
|
||||
databaseType,
|
||||
}
|
||||
)
|
||||
: field.isArray
|
||||
? '[]'
|
||||
: ''}
|
||||
</span>{' '}
|
||||
{isFieldAttributeChanged || fieldDiffChangedType ? (
|
||||
<>
|
||||
<span className="line-through">
|
||||
{
|
||||
(
|
||||
fieldDiffChangedType?.new
|
||||
fieldDiffChangedType?.old
|
||||
?.name ?? field.type.name
|
||||
).split(' ')[0]
|
||||
}
|
||||
@@ -526,16 +474,16 @@ export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
|
||||
...field,
|
||||
...{
|
||||
precision:
|
||||
fieldDiffChangedPrecision?.new ??
|
||||
fieldDiffChangedPrecision?.old ??
|
||||
field.precision,
|
||||
scale:
|
||||
fieldDiffChangedScale?.new ??
|
||||
fieldDiffChangedScale?.old ??
|
||||
field.scale,
|
||||
characterMaximumLength:
|
||||
fieldDiffChangedCharacterMaximumLength?.new ??
|
||||
fieldDiffChangedCharacterMaximumLength?.old ??
|
||||
field.characterMaximumLength,
|
||||
isArray:
|
||||
fieldDiffChangedIsArray?.new ??
|
||||
fieldDiffChangedIsArray?.old ??
|
||||
field.isArray,
|
||||
},
|
||||
},
|
||||
@@ -543,23 +491,55 @@ export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
|
||||
databaseType,
|
||||
}
|
||||
)
|
||||
: (fieldDiffChangedIsArray?.new ??
|
||||
field.isArray)
|
||||
? '[]'
|
||||
: ''}
|
||||
</>
|
||||
) : (
|
||||
`${field.type.name.split(' ')[0]}${
|
||||
showFieldAttributes
|
||||
? generateDBFieldSuffix(field, {
|
||||
databaseType,
|
||||
})
|
||||
: field.isArray
|
||||
? '[]'
|
||||
: ''
|
||||
}`
|
||||
)
|
||||
}
|
||||
: ''}
|
||||
</span>{' '}
|
||||
{
|
||||
(
|
||||
fieldDiffChangedType?.new?.name ??
|
||||
field.type.name
|
||||
).split(' ')[0]
|
||||
}
|
||||
{showFieldAttributes
|
||||
? generateDBFieldSuffix(
|
||||
{
|
||||
...field,
|
||||
...{
|
||||
precision:
|
||||
fieldDiffChangedPrecision?.new ??
|
||||
field.precision,
|
||||
scale:
|
||||
fieldDiffChangedScale?.new ??
|
||||
field.scale,
|
||||
characterMaximumLength:
|
||||
fieldDiffChangedCharacterMaximumLength?.new ??
|
||||
field.characterMaximumLength,
|
||||
isArray:
|
||||
fieldDiffChangedIsArray?.new ??
|
||||
field.isArray,
|
||||
},
|
||||
},
|
||||
{
|
||||
databaseType,
|
||||
}
|
||||
)
|
||||
: (fieldDiffChangedIsArray?.new ??
|
||||
field.isArray)
|
||||
? '[]'
|
||||
: ''}
|
||||
</>
|
||||
) : (
|
||||
`${field.type.name.split(' ')[0]}${
|
||||
showFieldAttributes
|
||||
? generateDBFieldSuffix(field, {
|
||||
databaseType,
|
||||
})
|
||||
: field.isArray
|
||||
? '[]'
|
||||
: ''
|
||||
}`
|
||||
)}
|
||||
{fieldDiffChangedNullable ? (
|
||||
fieldDiffChangedNullable.new ? (
|
||||
<span className="font-semibold">?</span>
|
||||
|
||||
@@ -27,7 +27,7 @@ import ChartDBLogo from '@/assets/logo-light.png';
|
||||
import ChartDBDarkLogo from '@/assets/logo-dark.png';
|
||||
import { useTheme } from '@/hooks/use-theme';
|
||||
import { useChartDB } from '@/hooks/use-chartdb';
|
||||
import { DatabaseType } from '@/lib/domain/database-type';
|
||||
import { supportsCustomTypes } from '@/lib/domain/database-capabilities';
|
||||
import { useDialog } from '@/hooks/use-dialog';
|
||||
import { Separator } from '@/components/separator/separator';
|
||||
|
||||
@@ -110,7 +110,7 @@ export const EditorSidebar: React.FC<EditorSidebarProps> = () => {
|
||||
},
|
||||
active: selectedSidebarSection === 'areas',
|
||||
},
|
||||
...(databaseType === DatabaseType.POSTGRESQL
|
||||
...(supportsCustomTypes(databaseType)
|
||||
? [
|
||||
{
|
||||
title: t('editor_sidebar.custom_types'),
|
||||
|
||||
@@ -15,7 +15,7 @@ import { useChartDB } from '@/hooks/use-chartdb';
|
||||
import { useBreakpoint } from '@/hooks/use-breakpoint';
|
||||
import { AreasSection } from './areas-section/areas-section';
|
||||
import { CustomTypesSection } from './custom-types-section/custom-types-section';
|
||||
import { DatabaseType } from '@/lib/domain/database-type';
|
||||
import { supportsCustomTypes } from '@/lib/domain/database-capabilities';
|
||||
import { DBMLSection } from './dbml-section/dbml-section';
|
||||
import { RefsSection } from './refs-section/refs-section';
|
||||
|
||||
@@ -54,7 +54,7 @@ export const SidePanel: React.FC<SidePanelProps> = () => {
|
||||
<SelectItem value="areas">
|
||||
{t('side_panel.areas_section.areas')}
|
||||
</SelectItem>
|
||||
{databaseType === DatabaseType.POSTGRESQL ? (
|
||||
{supportsCustomTypes(databaseType) ? (
|
||||
<SelectItem value="customTypes">
|
||||
{t(
|
||||
'side_panel.custom_types_section.custom_types'
|
||||
|
||||
Reference in New Issue
Block a user