dbml icon indicating copy to clipboard operation
dbml copied to clipboard

Multiple database schemas not supported

Open haily-tripla opened this issue 6 years ago • 6 comments

Hi, I have multiple schemas within the same database which I would like to model. However, the schema name portion will be stripped when I generate the dbml and cause errors due to the same table name

Sample create table script

CREATE  TABLE database1.test_table
(
  datetime_field DATETIME,
);

CREATE  TABLE database2.test_table
(
  datetime_field DATETIME,
);

Error: ERROR: You have a syntax error at "test_db.ddl" line 1 column 1. Table "test_table" existed

Will you support multiple database schemas in the future

haily-tripla avatar Sep 16 '20 07:09 haily-tripla

Yes, we will support multiple schemas in the future. For now, you should wrap the table name with backticks (`), and it works fine

CREATE  TABLE `database1.test_table`
(
  datetime_field DATETIME,
);

CREATE  TABLE `database2.test_table`
(
  datetime_field DATETIME,
);

khanh-tran-quoc avatar Sep 17 '20 04:09 khanh-tran-quoc

In this case also the "import from sql" should be improved. All my tables and views have schemas. MS SQL Server.

After removing many parts which the importer doesn't like (for example all calculated columns) it was imported. But in this form:

Table "repo"."spt_values" {
  "name" nvarchar(35)
  "number" int [not null]
  "type" nchar(3) [not null]
  "low" int
  "high" int
  "status" int
}

Table "repo"."GeneratorUsp" {
  "id" int [not null, increment]
  "usp_schema" nvarchar(128) [not null]
  "usp_name" nvarchar(128) [not null]
  "has_logging" tinyint [not null]
  "usp_Description" nvarchar(4000)

Indexes {
  id [pk]
  (usp_schema, usp_name) [unique, name: "UK_GeneratorUsp_Schema_Name"]
}
}

And this is an syntax error, because schemas are not yet supported.

aisbergde avatar Feb 25 '21 00:02 aisbergde

@khanh-tran-quoc 's workaround with backticks is not supported in v2.3.0

test.sql

create table `schema1.table`
(
	ID INTEGER
);
╰─ sql2dbml -V
2.3.0
╰─ sql2dbml test.sql 
  ERROR: You have a syntax error at "test.sql" line 1 column 14. Expected "IF" or valid table name but "`" found.

Wrapping the schema and table name in double-quotes does work, but you must wrap them as a single string (not two strings separated by .):

create table "schema1.table"
(
	ID INTEGER
);
╰─ sql2dbml test.sql
Table "schema1.table" {
  "ID" INTEGER
}

sleighter avatar May 04 '21 14:05 sleighter

@khanh-tran-quoc How is the support for multiple schemas going? I can see it on the roadmap for DBML, be interested to hear how it is progressing or if I can help at all?

cartogreaves avatar Feb 09 '22 11:02 cartogreaves

@RJHCarto We're working on it. We believe the related PR will appear in the next couple of weeks.

TeaNguyen avatar Feb 09 '22 18:02 TeaNguyen

Supported in https://github.com/holistics/dbml/pull/240

NQPhuc avatar Mar 08 '22 12:03 NQPhuc