fix(dbml-editor): dealing with dbml editor for non-generic db-type (#624)

* fix(dbml-editor): dealing with dbml editor for non-generic db-type

* small change

* Handle ENUM type when exporting as varchar

---------

Co-authored-by: Guy Ben-Aharon <baguy3@gmail.com>
This commit is contained in:
Jonathan Fishner
2025-03-17 19:40:12 +02:00
committed by GitHub
parent 3faa39e787
commit 14de30b7aa
2 changed files with 34 additions and 4 deletions

View File

@@ -6,14 +6,17 @@ import type { DataType } from '../data-types/data-types';
import { generateCacheKey, getFromCache, setInCache } from './export-sql-cache';
import { exportMSSQL } from './export-per-type/mssql';
export const exportBaseSQL = (diagram: Diagram): string => {
export const exportBaseSQL = (
diagram: Diagram,
isDBMLFlow: boolean = false
): string => {
const { tables, relationships } = diagram;
if (!tables || tables.length === 0) {
return '';
}
if (diagram.databaseType === DatabaseType.SQL_SERVER) {
if (!isDBMLFlow && diagram.databaseType === DatabaseType.SQL_SERVER) {
return exportMSSQL(diagram);
}
@@ -72,6 +75,11 @@ export const exportBaseSQL = (diagram: Diagram): string => {
table.fields.forEach((field, index) => {
let typeName = field.type.name;
// Handle ENUM type
if (typeName.toLowerCase() === 'enum') {
typeName = 'varchar';
}
// Temp fix for 'array' to be text[]
if (typeName.toLowerCase() === 'array') {
typeName = 'text[]';