Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ jobs:
--health-timeout 5s
--health-retries 10

oracle:
image: gvenzl/oracle-free:23.9-faststart

# Provide passwords and other environment variables to container
env:
ORACLE_RANDOM_PASSWORD: 'true'
APP_USER: dbml_test
APP_USER_PASSWORD: test

# Forward Oracle port
ports:
- 1521:1521

# Provide healthcheck script options for startup
options: >-
--health-cmd healthcheck.sh
--health-interval 10s
--health-timeout 5s
--health-retries 10

steps:
- uses: actions/checkout@v3
- name: Import DDL to Postgres
Expand All @@ -69,6 +89,17 @@ jobs:
- name: Import DDL to MSSQL
run: |
sqlcmd -S localhost -U sa -P dbml.123.123 -d master -i packages/dbml-cli/__test__/db2dbml/mssql/schema.sql
# This step will install `sqlplus` command
- name: Setup Oracle Instant Client
uses: iamazeem/setup-oracle-instant-client-action@v2
- name: Import DDL to Oracle
run: |
sqlplus -s dbml_test/test@localhost:1521/FREEPDB1 schema.sql
working-directory: packages/dbml-cli/__test__/db2dbml/oracle/
- name: Generate SQLite database from schema
run: |
sqlite3 schema.db < schema.sql
working-directory: packages/dbml-cli/__test__/db2dbml/sqlite/
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Table "TEST"."category" {
"cat_id" NUMBER [pk, not null, increment]
"cat_name" NVARCHAR2(100) [not null]
"super_cat_id" NUMBER
"created_date" TIMESTAMP(6) [default: `current_timestamp`]
Note: 'Category is stored as tree like structure'
}

Table "TEST"."product" {
"product_id" NUMBER [pk, not null, increment]
"product_name" NVARCHAR2(510) [not null]
"current_price" FLOAT [not null]
"cat_id" NUMBER [not null]
"is_sold" NUMBER(1)
"created_date" TIMESTAMP(6) [default: `current_timestamp`]
"is_allow_all" NUMBER(1)
}

Table "TEST"."user" {
"user_id" NUMBER [pk, not null, increment]
"username" VARCHAR2(40) [unique, not null]
"password" VARCHAR2(255) [not null]
"email" NVARCHAR2(80) [unique, not null]
"role" NUMBER [default: 0]
"created_date" TIMESTAMP(6) [default: `current_timestamp`]
}

Table "TEST"."wishlist" {
"user_id" NUMBER [pk, not null]
"product_id" NUMBER [pk, not null]
}

Ref "FK_CATEGORY_SUPER":"TEST"."category"."cat_id" < "TEST"."category"."super_cat_id"

Ref "FK_PRODUCT_CATEGORY":"TEST"."category"."cat_id" < "TEST"."product"."cat_id"

Ref "FK_WISHLIST_PRODUCT":"TEST"."product"."product_id" < "TEST"."wishlist"."product_id"

Ref "FK_WISHLIST_USER":"TEST"."user"."user_id" < "TEST"."wishlist"."user_id"
8 changes: 8 additions & 0 deletions packages/dbml-cli/__test__/db2dbml/oracle/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"args": [
"oracle",
"dbml_test/test@localhost:1521/FREEPDB1",
"-o",
"./out-files/schema.dbml"
]
}
45 changes: 45 additions & 0 deletions packages/dbml-cli/__test__/db2dbml/oracle/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
CREATE TABLE "user" (
"user_id" int GENERATED AS IDENTITY PRIMARY KEY,
"username" varchar2(40) UNIQUE NOT NULL,
"password" varchar2(255) NOT NULL,
"email" nvarchar2(40) UNIQUE NOT NULL,
"role" integer DEFAULT 0,
"created_date" timestamp DEFAULT current_timestamp
);

CREATE TABLE "category" (
"cat_id" int GENERATED AS IDENTITY PRIMARY KEY,
"cat_name" nvarchar2(50) NOT NULL,
"super_cat_id" int,
"created_date" timestamp DEFAULT current_timestamp
);

CREATE TABLE "product" (
"product_id" int GENERATED AS IDENTITY PRIMARY KEY,
"product_name" nvarchar2(255) NOT NULL,
"current_price" float NOT NULL,
"cat_id" int NOT NULL,
"is_sold" number(1),
"created_date" timestamp DEFAULT current_timestamp,
"is_allow_all" number(1)
);

CREATE TABLE "wishlist" (
"user_id" int NOT NULL,
"product_id" int NOT NULL,
PRIMARY KEY ("user_id", "product_id")
);

CREATE INDEX "FULLTEXT_INDEX_CATEGORY" ON "category" ("cat_name");

CREATE INDEX "FULLTEXT_INDEX_PRODUCT" ON "product" ("product_name");

COMMENT ON TABLE "category" IS 'Category is stored as tree like structure';

ALTER TABLE "category" ADD CONSTRAINT "FK_CATEGORY_SUPER" FOREIGN KEY ("super_cat_id") REFERENCES "category" ("cat_id");

ALTER TABLE "product" ADD CONSTRAINT "FK_PRODUCT_CATEGORY" FOREIGN KEY ("cat_id") REFERENCES "category" ("cat_id");

ALTER TABLE "wishlist" ADD CONSTRAINT "FK_WISHLIST_PRODUCT" FOREIGN KEY ("product_id") REFERENCES "product" ("product_id");

ALTER TABLE "wishlist" ADD CONSTRAINT "FK_WISHLIST_USER" FOREIGN KEY ("user_id") REFERENCES "user" ("user_id");
1 change: 1 addition & 0 deletions packages/dbml-cli/__test__/db2dbml/oracle/stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
✔ Generated DBML file from database's connection: schema.dbml
108 changes: 108 additions & 0 deletions packages/dbml-cli/__test__/db2dbml/sqlite/expect-out-files/schema.dbml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Table "main"."Customers" {
"customer_id" INTEGER [pk, increment]
"first_name" VARCHAR(50) [not null]
"last_name" VARCHAR(50) [not null]
"gender" STRING
"household_income" INTEGER
"birthdate" DATE [not null]
"phone_number" INTEGER [not null]
"email" VARCHAR(128)
}

Table "main"."Car_Vins" {
"vin" INTEGER [pk, increment]
"model_id" INTEGER [not null]
"option_set_id" INTEGER [not null]
"manufactured_date" DATE [not null]
"manufactured_plant_id" INTEGER [not null]
}

Table "main"."Car_Options" {
"option_set_id" INTEGER [pk, increment]
"model_id" INTEGER
"engine_id" INTEGER [not null]
"transmission_id" INTEGER [not null]
"chassis_id" INTEGER [not null]
"premium_sound_id" INTEGER
"color" VARCHAR(30) [not null]
"option_set_price" INTEGER [not null]
}

Table "main"."Car_Parts" {
"part_id" INTEGER [pk, increment]
"part_name" VARCHAR(100) [not null]
"manufacture_plant_id" INTEGER [not null]
"manufacture_start_date" DATE [not null]
"manufacture_end_date" DATE
"part_recall" INTEGER [default: 0]
}

Table "main"."Brands" {
"brand_id" INTEGER [pk, increment]
"brand_name" VARCHAR(50) [not null]
}

Table "main"."Models" {
"model_id" INTEGER [pk, increment]
"model_name" VARCHAR(50) [not null]
"model_base_price" INTEGER [not null]
"brand_id" INTEGER [not null]
}

Table "main"."Customer_Ownership" {
"customer_id" INTEGER [pk, not null, increment]
"vin" INTEGER [not null]
"purchase_date" DATE [not null]
"purchase_price" INTEGER [not null]
"warantee_expire_date" DATE
"dealer_id" INTEGER [not null]
}

Table "main"."Manufacture_Plant" {
"manufacture_plant_id" INTEGER [pk, increment]
"plant_name" VARCHAR(50) [not null]
"plant_type" "VARCHAR (7)"
"plant_location" VARCHAR(100)
"company_owned" INTEGER
}

Table "main"."Dealers" {
"dealer_id" INTEGER [pk, increment]
"dealer_name" VARCHAR(50) [not null]
"dealer_address" VARCHAR(100)
}

Table "main"."Dealer_Brand" {
"dealer_id" INTEGER [pk, not null, increment]
"brand_id" INTEGER [not null]
}

Ref "fk_Car_Vins_0":"main"."Car_Options"."option_set_id" < "main"."Car_Vins"."option_set_id"

Ref "fk_Car_Vins_1":"main"."Manufacture_Plant"."manufacture_plant_id" < "main"."Car_Vins"."manufactured_plant_id"

Ref "fk_Car_Vins_2":"main"."Models"."model_id" < "main"."Car_Vins"."model_id"

Ref "fk_Car_Options_0":"main"."Car_Parts"."part_id" < "main"."Car_Options"."chassis_id"

Ref "fk_Car_Options_1":"main"."Car_Parts"."part_id" < "main"."Car_Options"."transmission_id"

Ref "fk_Car_Options_2":"main"."Car_Parts"."part_id" < "main"."Car_Options"."premium_sound_id"

Ref "fk_Car_Options_3":"main"."Car_Parts"."part_id" < "main"."Car_Options"."engine_id"

Ref "fk_Car_Options_4":"main"."Models"."model_id" < "main"."Car_Options"."model_id"

Ref "fk_Car_Parts_0":"main"."Manufacture_Plant"."manufacture_plant_id" < "main"."Car_Parts"."manufacture_plant_id"

Ref "fk_Models_0":"main"."Brands"."brand_id" < "main"."Models"."brand_id"

Ref "fk_Customer_Ownership_0":"main"."Dealers"."dealer_id" < "main"."Customer_Ownership"."dealer_id"

Ref "fk_Customer_Ownership_1":"main"."Car_Vins"."vin" < "main"."Customer_Ownership"."vin"

Ref "fk_Customer_Ownership_2":"main"."Customers"."customer_id" < "main"."Customer_Ownership"."customer_id"

Ref "fk_Dealer_Brand_0":"main"."Brands"."brand_id" < "main"."Dealer_Brand"."brand_id"

Ref "fk_Dealer_Brand_1":"main"."Dealers"."dealer_id" < "main"."Dealer_Brand"."dealer_id"
8 changes: 8 additions & 0 deletions packages/dbml-cli/__test__/db2dbml/sqlite/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"args": [
"sqlite",
"schema.db",
"-o",
"./out-files/schema.dbml"
]
}
96 changes: 96 additions & 0 deletions packages/dbml-cli/__test__/db2dbml/sqlite/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
-- src: https://github.com/dtaivpp/car_company_database/blob/master/Create_Tables.sql
Create Table Customers(
customer_id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
gender STRING CHECK(gender = "Male" or gender = "Female"),
household_income INTEGER,
birthdate DATE NOT NULL,
phone_number INTEGER NOT NULL,
email VARCHAR(128)
);

Create Table Car_Vins(
vin INTEGER PRIMARY KEY AUTOINCREMENT,
model_id INTEGER NOT NULL,
option_set_id INTEGER NOT NULL,
manufactured_date DATE NOT NULL,
manufactured_plant_id INTEGER NOT NULL,
FOREIGN KEY (model_id) REFERENCES Models(model_id),
FOREIGN KEY (manufactured_plant_id) REFERENCES Manufacture_Plant(manufacture_plant_id),
FOREIGN KEY (option_set_id) REFERENCES Car_Options(option_set_id)
);

Create Table Car_Options(
option_set_id INTEGER PRIMARY KEY AUTOINCREMENT,
model_id INTEGER NULL,
engine_id INTEGER NOT NULL,
transmission_id INTEGER NOT NULL,
chassis_id INTEGER NOT NULL,
premium_sound_id INTEGER,
color VARCHAR(30) NOT NULL,
option_set_price INTEGER NOT NUll,
FOREIGN KEY (model_id) REFERENCES Models(model_id),
FOREIGN KEY (engine_id) REFERENCES Car_Parts(part_id),
FOREIGN KEY (premium_sound_id) REFERENCES Car_Parts(part_id),
FOREIGN KEY (transmission_id) REFERENCES Car_Parts(part_id),
FOREIGN KEY (chassis_id) REFERENCES Car_Parts(part_id)
);

Create Table Car_Parts(
part_id INTEGER PRIMARY KEY AUTOINCREMENT,
part_name VARCHAR(100) NOT NULL,
manufacture_plant_id INTEGER NOT NULL,
manufacture_start_date DATE NOT NUll,
manufacture_end_date DATE,
part_recall INTEGER DEFAULT 0 CHECK (part_recall = 0 or part_recall = 1),
FOREIGN KEY (manufacture_plant_id) REFERENCES Manufacture_Plant(manufacture_plant_id)
);

Create Table Brands(
brand_id INTEGER PRIMARY KEY AUTOINCREMENT,
brand_name VARCHAR(50) NOT NUll
);

Create Table Models(
model_id INTEGER PRIMARY KEY AUTOINCREMENT,
model_name VARCHAR(50) NOT NULL,
model_base_price INTEGER NOT NULL,
brand_id INTEGER NOT NULL,
FOREIGN KEY (brand_id) REFERENCES Brands(brand_id)
);

Create Table Customer_Ownership(
customer_id INTEGER NOT NULL,
vin INTEGER NOT NULL,
purchase_date DATE NOT NULL,
purchase_price INTEGER NOT NULL,
warantee_expire_date DATE,
dealer_id INTEGER NOT NULL,
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id),
FOREIGN KEY (vin) REFERENCES Car_Vins(vin),
FOREIGN KEY (dealer_id) REFERENCES Dealers(dealer_id)
PRIMARY KEY (customer_id, vin)
);

Create Table Manufacture_Plant(
manufacture_plant_id INTEGER PRIMARY KEY AUTOINCREMENT,
plant_name VARCHAR(50) NOT NULL,
plant_type VARCHAR (7) CHECK (plant_type="Assembly" or plant_type="Parts"),
plant_location VARCHAR(100),
company_owned INTEGER CHECK(company_owned=0 or company_owned=1)
);

Create Table Dealers (
dealer_id INTEGER PRIMARY KEY AUTOINCREMENT,
dealer_name VARCHAR(50) NOT NULL,
dealer_address VARCHAR(100)
);

Create Table Dealer_Brand(
dealer_id INTEGER NOT NULL,
brand_id INTEGER NOT NULL,
FOREIGN KEY (dealer_id) REFERENCES Dealers(dealer_id),
FOREIGN KEY (brand_id) REFERENCES Brands(brand_id),
PRIMARY KEY (dealer_id, brand_id)
);
1 change: 1 addition & 0 deletions packages/dbml-cli/__test__/db2dbml/sqlite/stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
✔ Generated DBML file from database's connection: schema.dbml
2 changes: 1 addition & 1 deletion packages/dbml-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function sql2dbml (args) {

function db2dbml (args) {
program.version(projectInfo.version);

// TODO: Update description to add `oracle` and `sqlite`
const description = `Generate DBML directly from a database
<database-type> your database format (postgres, mysql, mssql, snowflake, bigquery)
<connection-string> your database connection string:
Expand Down
Loading
Loading