Multiple database schemas not supported
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
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,
);
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.
@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
}
@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?
@RJHCarto We're working on it. We believe the related PR will appear in the next couple of weeks.
Supported in https://github.com/holistics/dbml/pull/240