@dbml/cli 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/__test__/db2dbml/mssql/dbml-error.log +337 -0
  2. package/__test__/db2dbml/mssql/out-files/schema.dbml +219 -0
  3. package/__test__/db2dbml/mysql/dbml-error.log +230 -0
  4. package/__test__/db2dbml/mysql/out-files/schema.dbml +188 -0
  5. package/__test__/db2dbml/postgres/dbml-error.log +63 -0
  6. package/__test__/db2dbml/postgres/out-files/schema.dbml +184 -0
  7. package/__test__/dbml2sql/filename --mysql --out-file/dbml-error.log +0 -0
  8. package/__test__/dbml2sql/filename --mysql --out-file/out-files/schema.sql +65 -0
  9. package/__test__/dbml2sql/filename --mysql stdout/dbml-error.log +0 -0
  10. package/__test__/dbml2sql/filename --oracle --out-file/dbml-error.log +0 -0
  11. package/__test__/dbml2sql/filename --oracle --out-file/out-files/schema.sql +61 -0
  12. package/__test__/dbml2sql/filename --oracle stdout/dbml-error.log +0 -0
  13. package/__test__/dbml2sql/filename --out-file/dbml-error.log +0 -0
  14. package/__test__/dbml2sql/filename --out-file/out-files/schema.sql +77 -0
  15. package/__test__/dbml2sql/filename --postgres --out-file/dbml-error.log +0 -0
  16. package/__test__/dbml2sql/filename --postgres --out-file/out-files/schema.sql +77 -0
  17. package/__test__/dbml2sql/filename --postgres stdout/dbml-error.log +0 -0
  18. package/__test__/dbml2sql/filename stdout/dbml-error.log +0 -0
  19. package/__test__/dbml2sql/filenames --mysql --out-file/dbml-error.log +0 -0
  20. package/__test__/dbml2sql/filenames --mysql --out-file/out-files/schema.sql +172 -0
  21. package/__test__/dbml2sql/filenames --mysql stdout/dbml-error.log +0 -0
  22. package/__test__/dbml2sql/filenames --oracle --out-file/dbml-error.log +0 -0
  23. package/__test__/dbml2sql/filenames --oracle --out-file/out-files/schema.sql +172 -0
  24. package/__test__/dbml2sql/filenames --oracle stdout/dbml-error.log +0 -0
  25. package/__test__/dbml2sql/filenames --out-file/dbml-error.log +0 -0
  26. package/__test__/dbml2sql/filenames --out-file/out-files/schema.sql +172 -0
  27. package/__test__/dbml2sql/filenames --postgres --out-file/dbml-error.log +0 -0
  28. package/__test__/dbml2sql/filenames --postgres --out-file/out-files/schema.sql +172 -0
  29. package/__test__/dbml2sql/filenames --postgres stdout/dbml-error.log +0 -0
  30. package/__test__/dbml2sql/filenames stdout/dbml-error.log +0 -0
  31. package/__test__/dbml2sql/multiple_schema_mssql/dbml-error.log +0 -0
  32. package/__test__/dbml2sql/multiple_schema_mssql/out-files/multiple_schema.out.sql +62 -0
  33. package/__test__/dbml2sql/multiple_schema_mysql/dbml-error.log +0 -0
  34. package/__test__/dbml2sql/multiple_schema_mysql/out-files/multiple_schema.out.sql +50 -0
  35. package/__test__/dbml2sql/multiple_schema_oracle/dbml-error.log +0 -0
  36. package/__test__/dbml2sql/multiple_schema_oracle/out-files/multiple_schema.out.sql +88 -0
  37. package/__test__/dbml2sql/multiple_schema_pg/dbml-error.log +0 -0
  38. package/__test__/dbml2sql/multiple_schema_pg/out-files/multiple_schema.out.sql +67 -0
  39. package/__test__/dbml2sql/syntax-error/dbml-error.log +345 -0
  40. package/__test__/sql2dbml/filename --mssql --out-file/dbml-error.log +0 -0
  41. package/__test__/sql2dbml/filename --mssql --out-file/out-files/schema.dbml +25 -0
  42. package/__test__/sql2dbml/filename --mysql --out-file/dbml-error.log +0 -0
  43. package/__test__/sql2dbml/filename --mysql --out-file/out-files/schema.dbml +74 -0
  44. package/__test__/sql2dbml/filename --mysql stdout/dbml-error.log +0 -0
  45. package/__test__/sql2dbml/filename --out-file/dbml-error.log +0 -0
  46. package/__test__/sql2dbml/filename --out-file/out-files/schema.dbml +74 -0
  47. package/__test__/sql2dbml/filename --postgres --out-file/dbml-error.log +0 -0
  48. package/__test__/sql2dbml/filename --postgres --out-file/out-files/schema.dbml +74 -0
  49. package/__test__/sql2dbml/filename --postgres stdout/dbml-error.log +0 -0
  50. package/__test__/sql2dbml/filename --snowflake stdout/dbml-error.log +0 -0
  51. package/__test__/sql2dbml/filename stdout/dbml-error.log +0 -0
  52. package/__test__/sql2dbml/filenames --mysql --out-file/dbml-error.log +0 -0
  53. package/__test__/sql2dbml/filenames --mysql --out-file/out-files/schema.dbml +170 -0
  54. package/__test__/sql2dbml/filenames --mysql stdout/dbml-error.log +0 -0
  55. package/__test__/sql2dbml/filenames --out-file/dbml-error.log +0 -0
  56. package/__test__/sql2dbml/filenames --out-file/out-files/schema.dbml +170 -0
  57. package/__test__/sql2dbml/filenames --postgres --out-file/dbml-error.log +0 -0
  58. package/__test__/sql2dbml/filenames --postgres --out-file/out-files/schema.dbml +170 -0
  59. package/__test__/sql2dbml/filenames --postgres stdout/dbml-error.log +0 -0
  60. package/__test__/sql2dbml/filenames stdout/dbml-error.log +0 -0
  61. package/__test__/sql2dbml/multiple_schema_mssql/dbml-error.log +0 -0
  62. package/__test__/sql2dbml/multiple_schema_mssql/expect-out-files/multiple_schema.out.dbml +8 -8
  63. package/__test__/sql2dbml/multiple_schema_mssql/out-files/multiple_schema.out.dbml +58 -0
  64. package/__test__/sql2dbml/multiple_schema_mysql/dbml-error.log +0 -0
  65. package/__test__/sql2dbml/multiple_schema_mysql/out-files/multiple_schema.out.dbml +136 -0
  66. package/__test__/sql2dbml/multiple_schema_pg/dbml-error.log +0 -0
  67. package/__test__/sql2dbml/multiple_schema_pg/out-files/multiple_schema.out.dbml +101 -0
  68. package/__test__/sql2dbml/syntax-error/dbml-error.log +342 -0
  69. package/__test__/sql2dbml/syntax-error-duplicate-endpoints --mssql/dbml-error.log +342 -0
  70. package/__test__/sql2dbml/syntax-error-duplicate-endpoints --mysql/dbml-error.log +339 -0
  71. package/dbml-error.log +0 -0
  72. package/package.json +4 -4
@@ -0,0 +1,184 @@
1
+ Enum "dbml_test"."enum_type1" {
2
+ "value1"
3
+ "value2"
4
+ }
5
+
6
+ Enum "dbml_test"."enum_type3" {
7
+ "value4"
8
+ "value5"
9
+ }
10
+
11
+ Table "dbml_test"."table1" {
12
+ "id" int4 [pk, not null, increment]
13
+ "status" dbml_test.enum_type1
14
+ }
15
+
16
+ Table "dbml_test"."table3" {
17
+ "id" int4 [pk, not null, increment]
18
+ "status" dbml_test.enum_type3
19
+ }
20
+
21
+ Enum "enum_type1" {
22
+ "value1"
23
+ "value2"
24
+ }
25
+
26
+ Enum "enum_type2" {
27
+ "value1"
28
+ "value3"
29
+ }
30
+
31
+ Enum "gender_type" {
32
+ "Male"
33
+ "Female"
34
+ "Other"
35
+ }
36
+
37
+ Table "users" {
38
+ "user_id" int4 [pk, not null, increment]
39
+ "username" varchar(50) [unique, not null]
40
+ "email" varchar(100) [unique, not null, check: `(email)::text ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}$'::text`]
41
+ "password_hash" varchar(255) [not null]
42
+ "first_name" varchar(50)
43
+ "last_name" varchar(50)
44
+ "full_name" varchar(100)
45
+ "date_of_birth" date [check: `date_of_birth <= (CURRENT_DATE - '13 years'::interval)`]
46
+ "created_at" timestamptz [default: `CURRENT_TIMESTAMP`]
47
+ "last_login" timestamptz
48
+ "is_active" bool [default: true]
49
+
50
+ Indexes {
51
+ full_name [type: btree, name: "User Name"]
52
+ email [type: btree, name: "idx_users_email"]
53
+ (is_active, `lower((full_name)::text)`) [type: btree, name: "users_is_active_lower_idx"]
54
+ }
55
+ }
56
+
57
+ Table "products" {
58
+ "product_id" int4 [pk, not null, increment]
59
+ "name" varchar(100) [not null]
60
+ "description" text
61
+ "price" numeric(10,2) [not null, check: `price > (0)::numeric`]
62
+ "stock_quantity" int4 [not null, check: `stock_quantity >= 0`, default: 0]
63
+ "category" varchar(50)
64
+ "created_at" timestamptz [default: `CURRENT_TIMESTAMP`]
65
+ "updated_at" timestamptz [default: `CURRENT_TIMESTAMP`]
66
+ "is_available" bool [default: true]
67
+
68
+ Checks {
69
+ `created_at <= updated_at` [name: 'chk_created_at']
70
+ }
71
+
72
+ Indexes {
73
+ category [type: btree, name: "idx_products_category"]
74
+ }
75
+ }
76
+
77
+ Table "orders" {
78
+ "order_id" int4 [pk, not null, increment]
79
+ "user_id" int4 [not null]
80
+ "order_date" timestamptz [default: `CURRENT_TIMESTAMP`]
81
+ "total_amount" numeric(12,2) [not null, check: `total_amount > (0)::numeric`]
82
+ "status" varchar(20) [check: `(status)::text = ANY ((ARRAY['pending'::character varying, 'processing'::character varying, 'shipped'::character varying, 'delivered'::character varying, 'cancelled'::character varying])::text[])`, default: 'pending']
83
+ "shipping_address" text [not null]
84
+ "billing_address" text [not null]
85
+
86
+ Indexes {
87
+ (user_id, order_date) [type: btree, name: "idx_orders_user_date"]
88
+ }
89
+ }
90
+
91
+ Table "order_items" {
92
+ "order_item_id" int4 [pk, not null, increment]
93
+ "order_id" int4 [not null]
94
+ "product_id" int4 [not null]
95
+ "quantity" int4 [not null, check: `quantity > 0`]
96
+ "unit_price" numeric(10,2) [not null, check: `unit_price > (0)::numeric`]
97
+
98
+ Indexes {
99
+ (order_id, product_id) [type: btree, name: "uq_order_product"]
100
+ (order_id, product_id) [type: btree, name: "idx_order_items_order_product"]
101
+ }
102
+ }
103
+
104
+ Table "all_string_types" {
105
+ "text_col" text [default: 'default_text']
106
+ "varchar_col" varchar(100) [default: 'default_varchar']
107
+ "char_col" bpchar(10) [default: 'default_char']
108
+ "character_varying_col" varchar(50) [default: 'default_character_varying']
109
+ "character_col" bpchar(5) [default: 'default_character']
110
+ "name_col" name [default: 'default_name']
111
+ "bpchar_col" bpchar(15) [default: 'default_bpchar']
112
+ "text_array_col" "text[]" [default: `ARRAY['default_text1', 'default_text2']`]
113
+ "json_col" json [default: `{"default_key": "default_value"}`]
114
+ "jsonb_col" jsonb [default: `{"default_key": "default_value"}`]
115
+ }
116
+
117
+ Table "all_default_values" {
118
+ "id" int4 [pk, not null, increment]
119
+ "boolean_col" bool [default: true]
120
+ "integer_col" int4 [default: 42]
121
+ "numeric_col" numeric(10,2) [default: 99.99]
122
+ "date_col" date [default: `CURRENT_DATE`]
123
+ "date_col_specific" date [default: '2024-01-01']
124
+ "timestamp_col" timestamp [default: `CURRENT_TIMESTAMP`]
125
+ "timestamp_col_specific" timestamp [default: '2024-01-01 12:00:00']
126
+ "date_plus_7_days" date [default: `(CURRENT_DATE + '7 days'::interval)`]
127
+ "date_minus_30_days" date [default: `(CURRENT_DATE - '30 days'::interval)`]
128
+ "timestamp_plus_1_hour" timestamp [default: `(CURRENT_TIMESTAMP + '01:00:00'::interval)`]
129
+ "timestamp_minus_15_minutes" timestamp [default: `(CURRENT_TIMESTAMP - '00:15:00'::interval)`]
130
+ }
131
+
132
+ Table "user_define_data_types" {
133
+ "id" int4 [pk, not null, increment]
134
+ "name" varchar(50)
135
+ "gender" gender_type
136
+ "age" int4range
137
+ "height" float8 [check: `height > (0)::double precision`]
138
+ "weight" float8 [check: `weight > (0)::double precision`]
139
+ }
140
+
141
+ Table "table_with_comments" {
142
+ "id" int4 [pk, not null, increment, note: 'Unique identifier for each item.']
143
+ "name" varchar(100) [note: '''Item\'s name.''']
144
+ "description" text [note: '''Item\'s description''']
145
+ "created_at" timestamptz [default: `CURRENT_TIMESTAMP`, note: 'Timestamp when the item was created.']
146
+ Note: '''This table stores information about various items. Such as: \'id\', \'name\', \'description\''''
147
+ }
148
+
149
+ Table "authors" {
150
+ "authorid" int4 [not null, increment]
151
+ "nationalityid" int4 [not null]
152
+ "authorname" varchar(100)
153
+ "birthyear" int4
154
+
155
+ Indexes {
156
+ (authorid, nationalityid) [type: btree, name: "authors_pkey"]
157
+ }
158
+ }
159
+
160
+ Table "books" {
161
+ "bookid" int4 [pk, not null, increment]
162
+ "authorid" int4
163
+ "nationalityid" int4
164
+ "isbn" varchar(20) [unique]
165
+ "title" varchar(200)
166
+ }
167
+
168
+ Table "table1" {
169
+ "id" int4 [pk, not null, increment]
170
+ "status" enum_type1
171
+ }
172
+
173
+ Table "table2" {
174
+ "id" int4 [pk, not null, increment]
175
+ "status" enum_type2
176
+ }
177
+
178
+ Ref "fk_authornationality":"authors".("authorid", "nationalityid") < "books".("authorid", "nationalityid") [delete: cascade]
179
+
180
+ Ref "fk_order":"orders"."order_id" < "order_items"."order_id" [delete: cascade]
181
+
182
+ Ref "fk_product":"products"."product_id" < "order_items"."product_id" [delete: cascade]
183
+
184
+ Ref "fk_user":"users"."user_id" < "orders"."user_id" [delete: cascade]
@@ -0,0 +1,65 @@
1
+ -- SQL dump generated using DBML (dbml.dbdiagram.io)
2
+ -- Database: MySQL
3
+ -- Generated at: 2025-10-28T05:18:29.035Z
4
+
5
+ CREATE TABLE `orders` (
6
+ `id` int PRIMARY KEY AUTO_INCREMENT,
7
+ `user_id` int UNIQUE NOT NULL,
8
+ `status` ENUM ('created', 'running', 'done', 'failure'),
9
+ `created_at` varchar(255)
10
+ );
11
+
12
+ CREATE TABLE `order_items` (
13
+ `order_id` int,
14
+ `product_id` int,
15
+ `quantity` int DEFAULT 1
16
+ );
17
+
18
+ CREATE TABLE `products` (
19
+ `id` int PRIMARY KEY,
20
+ `name` varchar(255),
21
+ `merchant_id` int NOT NULL,
22
+ `price` int,
23
+ `status` ENUM ('Out of Stock', 'In Stock'),
24
+ `created_at` datetime DEFAULT (now())
25
+ );
26
+
27
+ CREATE TABLE `users` (
28
+ `id` int PRIMARY KEY,
29
+ `full_name` varchar(255),
30
+ `email` varchar(255) UNIQUE,
31
+ `gender` varchar(255),
32
+ `date_of_birth` varchar(255),
33
+ `created_at` varchar(255),
34
+ `country_code` int
35
+ );
36
+
37
+ CREATE TABLE `merchants` (
38
+ `id` int PRIMARY KEY,
39
+ `merchant_name` varchar(255),
40
+ `country_code` int,
41
+ `created_at` varchar(255),
42
+ `admin_id` int
43
+ );
44
+
45
+ CREATE TABLE `countries` (
46
+ `code` int PRIMARY KEY,
47
+ `name` varchar(255),
48
+ `continent_name` varchar(255)
49
+ );
50
+
51
+ CREATE INDEX `product_status` ON `products` (`merchant_id`, `status`);
52
+
53
+ CREATE UNIQUE INDEX `products_index_1` ON `products` (`id`) USING HASH;
54
+
55
+ ALTER TABLE `order_items` ADD FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`);
56
+
57
+ ALTER TABLE `order_items` ADD FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);
58
+
59
+ ALTER TABLE `users` ADD FOREIGN KEY (`country_code`) REFERENCES `countries` (`code`);
60
+
61
+ ALTER TABLE `merchants` ADD FOREIGN KEY (`country_code`) REFERENCES `countries` (`code`);
62
+
63
+ ALTER TABLE `products` ADD FOREIGN KEY (`merchant_id`) REFERENCES `merchants` (`id`);
64
+
65
+ ALTER TABLE `merchants` ADD FOREIGN KEY (`admin_id`) REFERENCES `users` (`id`);
@@ -0,0 +1,61 @@
1
+ -- SQL dump generated using DBML (dbml.dbdiagram.io)
2
+ -- Database: Oracle
3
+ -- Generated at: 2025-10-28T05:18:30.595Z
4
+
5
+ CREATE TABLE "orders" (
6
+ "id" int GENERATED AS IDENTITY PRIMARY KEY,
7
+ "user_id" int UNIQUE NOT NULL,
8
+ "status" nvarchar2(255) NOT NULL CHECK ("status" IN ('created', 'running', 'done', 'failure'))
9
+ );
10
+
11
+ CREATE TABLE "order_items" (
12
+ "order_id" int,
13
+ "product_id" int,
14
+ "quantity" int DEFAULT 1
15
+ );
16
+
17
+ CREATE TABLE "products" (
18
+ "id" int PRIMARY KEY,
19
+ "name" nvarchar2(255),
20
+ "merchant_id" int NOT NULL,
21
+ "price" int,
22
+ "status" nvarchar2(255) NOT NULL CHECK ("status" IN ('Out of Stock', 'In Stock')),
23
+ "created_at" timestamp DEFAULT current_timestamp
24
+ );
25
+
26
+ CREATE TABLE "users" (
27
+ "id" int PRIMARY KEY,
28
+ "full_name" nvarchar2(255),
29
+ "email" nvarchar2(255) UNIQUE,
30
+ "gender" nvarchar2(255),
31
+ "date_of_birth" date,
32
+ "created_at" timestamp,
33
+ "country_code" int
34
+ );
35
+
36
+ CREATE TABLE "merchants" (
37
+ "id" int PRIMARY KEY,
38
+ "merchant_name" nvarchar2(255),
39
+ "country_code" int,
40
+ "created_at" timestamp,
41
+ "admin_id" int
42
+ );
43
+
44
+ CREATE TABLE "countries" (
45
+ "code" int PRIMARY KEY,
46
+ "name" nvarchar2(255)
47
+ );
48
+
49
+ CREATE INDEX "product_status" ON "products" ("merchant_id", "status");
50
+
51
+ ALTER TABLE "order_items" ADD FOREIGN KEY ("order_id") REFERENCES "orders" ("id");
52
+
53
+ ALTER TABLE "order_items" ADD FOREIGN KEY ("product_id") REFERENCES "products" ("id");
54
+
55
+ ALTER TABLE "users" ADD FOREIGN KEY ("country_code") REFERENCES "countries" ("code");
56
+
57
+ ALTER TABLE "merchants" ADD FOREIGN KEY ("country_code") REFERENCES "countries" ("code");
58
+
59
+ ALTER TABLE "products" ADD FOREIGN KEY ("merchant_id") REFERENCES "merchants" ("id");
60
+
61
+ ALTER TABLE "merchants" ADD FOREIGN KEY ("admin_id") REFERENCES "users" ("id");
@@ -0,0 +1,77 @@
1
+ -- SQL dump generated using DBML (dbml.dbdiagram.io)
2
+ -- Database: PostgreSQL
3
+ -- Generated at: 2025-10-28T05:18:32.123Z
4
+
5
+ CREATE TYPE "orders_status" AS ENUM (
6
+ 'created',
7
+ 'running',
8
+ 'done',
9
+ 'failure'
10
+ );
11
+
12
+ CREATE TYPE "product status" AS ENUM (
13
+ 'Out of Stock',
14
+ 'In Stock'
15
+ );
16
+
17
+ CREATE TABLE "orders" (
18
+ "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
19
+ "user_id" int UNIQUE NOT NULL,
20
+ "status" orders_status,
21
+ "created_at" varchar
22
+ );
23
+
24
+ CREATE TABLE "order_items" (
25
+ "order_id" int,
26
+ "product_id" int,
27
+ "quantity" int DEFAULT 1
28
+ );
29
+
30
+ CREATE TABLE "products" (
31
+ "id" int PRIMARY KEY,
32
+ "name" varchar,
33
+ "merchant_id" int NOT NULL,
34
+ "price" int,
35
+ "status" "product status",
36
+ "created_at" datetime DEFAULT (now())
37
+ );
38
+
39
+ CREATE TABLE "users" (
40
+ "id" int PRIMARY KEY,
41
+ "full_name" varchar,
42
+ "email" varchar UNIQUE,
43
+ "gender" varchar,
44
+ "date_of_birth" varchar,
45
+ "created_at" varchar,
46
+ "country_code" int
47
+ );
48
+
49
+ CREATE TABLE "merchants" (
50
+ "id" int PRIMARY KEY,
51
+ "merchant_name" varchar,
52
+ "country_code" int,
53
+ "created_at" varchar,
54
+ "admin_id" int
55
+ );
56
+
57
+ CREATE TABLE "countries" (
58
+ "code" int PRIMARY KEY,
59
+ "name" varchar,
60
+ "continent_name" varchar
61
+ );
62
+
63
+ CREATE INDEX "product_status" ON "products" ("merchant_id", "status");
64
+
65
+ CREATE UNIQUE INDEX ON "products" USING HASH ("id");
66
+
67
+ ALTER TABLE "order_items" ADD FOREIGN KEY ("order_id") REFERENCES "orders" ("id");
68
+
69
+ ALTER TABLE "order_items" ADD FOREIGN KEY ("product_id") REFERENCES "products" ("id");
70
+
71
+ ALTER TABLE "users" ADD FOREIGN KEY ("country_code") REFERENCES "countries" ("code");
72
+
73
+ ALTER TABLE "merchants" ADD FOREIGN KEY ("country_code") REFERENCES "countries" ("code");
74
+
75
+ ALTER TABLE "products" ADD FOREIGN KEY ("merchant_id") REFERENCES "merchants" ("id");
76
+
77
+ ALTER TABLE "merchants" ADD FOREIGN KEY ("admin_id") REFERENCES "users" ("id");
@@ -0,0 +1,77 @@
1
+ -- SQL dump generated using DBML (dbml.dbdiagram.io)
2
+ -- Database: PostgreSQL
3
+ -- Generated at: 2025-10-28T05:18:32.896Z
4
+
5
+ CREATE TYPE "orders_status" AS ENUM (
6
+ 'created',
7
+ 'running',
8
+ 'done',
9
+ 'failure'
10
+ );
11
+
12
+ CREATE TYPE "product status" AS ENUM (
13
+ 'Out of Stock',
14
+ 'In Stock'
15
+ );
16
+
17
+ CREATE TABLE "orders" (
18
+ "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
19
+ "user_id" int UNIQUE NOT NULL,
20
+ "status" orders_status,
21
+ "created_at" varchar
22
+ );
23
+
24
+ CREATE TABLE "order_items" (
25
+ "order_id" int,
26
+ "product_id" int,
27
+ "quantity" int DEFAULT 1
28
+ );
29
+
30
+ CREATE TABLE "products" (
31
+ "id" int PRIMARY KEY,
32
+ "name" varchar,
33
+ "merchant_id" int NOT NULL,
34
+ "price" int,
35
+ "status" "product status",
36
+ "created_at" datetime DEFAULT (now())
37
+ );
38
+
39
+ CREATE TABLE "users" (
40
+ "id" int PRIMARY KEY,
41
+ "full_name" varchar,
42
+ "email" varchar UNIQUE,
43
+ "gender" varchar,
44
+ "date_of_birth" varchar,
45
+ "created_at" varchar,
46
+ "country_code" int
47
+ );
48
+
49
+ CREATE TABLE "merchants" (
50
+ "id" int PRIMARY KEY,
51
+ "merchant_name" varchar,
52
+ "country_code" int,
53
+ "created_at" varchar,
54
+ "admin_id" int
55
+ );
56
+
57
+ CREATE TABLE "countries" (
58
+ "code" int PRIMARY KEY,
59
+ "name" varchar,
60
+ "continent_name" varchar
61
+ );
62
+
63
+ CREATE INDEX "product_status" ON "products" ("merchant_id", "status");
64
+
65
+ CREATE UNIQUE INDEX ON "products" USING HASH ("id");
66
+
67
+ ALTER TABLE "order_items" ADD FOREIGN KEY ("order_id") REFERENCES "orders" ("id");
68
+
69
+ ALTER TABLE "order_items" ADD FOREIGN KEY ("product_id") REFERENCES "products" ("id");
70
+
71
+ ALTER TABLE "users" ADD FOREIGN KEY ("country_code") REFERENCES "countries" ("code");
72
+
73
+ ALTER TABLE "merchants" ADD FOREIGN KEY ("country_code") REFERENCES "countries" ("code");
74
+
75
+ ALTER TABLE "products" ADD FOREIGN KEY ("merchant_id") REFERENCES "merchants" ("id");
76
+
77
+ ALTER TABLE "merchants" ADD FOREIGN KEY ("admin_id") REFERENCES "users" ("id");
@@ -0,0 +1,172 @@
1
+ -- SQL dump generated using DBML (dbml.dbdiagram.io)
2
+ -- Database: MySQL
3
+ -- Generated at: 2025-10-28T05:18:35.252Z
4
+
5
+ CREATE TABLE `staff` (
6
+ `id` int PRIMARY KEY,
7
+ `first_name` varchar(255),
8
+ `last_name` varchar(255),
9
+ `address_id` int,
10
+ `picture` blob,
11
+ `email` varchar(255),
12
+ `store_id` int,
13
+ `active` boolean,
14
+ `user_name` varchar(255),
15
+ `password` varchar(255),
16
+ `last_update` timestamp
17
+ );
18
+
19
+ CREATE TABLE `store` (
20
+ `id` int PRIMARY KEY,
21
+ `manager_staff_id` int,
22
+ `address_id` int,
23
+ `last_update` timestamp
24
+ );
25
+
26
+ CREATE TABLE `payment` (
27
+ `id` int PRIMARY KEY,
28
+ `customer_id` int,
29
+ `staff_id` int,
30
+ `rental_id` int,
31
+ `amount` decimal,
32
+ `payment_date` datetime,
33
+ `last_update` timestamp
34
+ );
35
+
36
+ CREATE TABLE `rental` (
37
+ `id` int PRIMARY KEY,
38
+ `rental_date` datetime,
39
+ `inventory_id` int,
40
+ `customer_id` int,
41
+ `return_date` ddatetime,
42
+ `staff_id` int,
43
+ `last_update` timestamp
44
+ );
45
+
46
+ ALTER TABLE `staff` ADD FOREIGN KEY (`store_id`) REFERENCES `store` (`id`);
47
+
48
+ ALTER TABLE `store` ADD FOREIGN KEY (`manager_staff_id`) REFERENCES `staff` (`id`);
49
+
50
+ ALTER TABLE `payment` ADD FOREIGN KEY (`staff_id`) REFERENCES `staff` (`id`);
51
+
52
+ ALTER TABLE `payment` ADD FOREIGN KEY (`rental_id`) REFERENCES `rental` (`id`);
53
+
54
+ ALTER TABLE `rental` ADD FOREIGN KEY (`staff_id`) REFERENCES `staff` (`id`);
55
+ CREATE TABLE `country` (
56
+ `id` int PRIMARY KEY,
57
+ `country` varchar(255),
58
+ `last_update` timestamp
59
+ );
60
+
61
+ CREATE TABLE `city` (
62
+ `id` int PRIMARY KEY,
63
+ `city` varchar(255),
64
+ `country_id` int,
65
+ `last_update` timestamp
66
+ );
67
+
68
+ CREATE TABLE `address` (
69
+ `id` int PRIMARY KEY,
70
+ `address` varchar(255),
71
+ `address2` varchar(255),
72
+ `district` varchar(255),
73
+ `city_id` int,
74
+ `postal_code` varchar(255),
75
+ `phone` varchar(255),
76
+ `last_update` timestamp
77
+ );
78
+
79
+ CREATE TABLE `customer` (
80
+ `id` int PRIMARY KEY,
81
+ `store_id` int,
82
+ `first_name` varchar(255),
83
+ `last_name` varchar(255),
84
+ `email` varchar(255),
85
+ `address_id` int,
86
+ `active` boolean,
87
+ `create_Date` timestamp,
88
+ `last_update` timestamp
89
+ );
90
+
91
+ CREATE INDEX `customer_index_0` ON `customer` (`id`, `first_name`) USING BTREE;
92
+
93
+ ALTER TABLE `city` ADD FOREIGN KEY (`country_id`) REFERENCES `country` (`id`);
94
+
95
+ ALTER TABLE `address` ADD FOREIGN KEY (`city_id`) REFERENCES `city` (`id`);
96
+
97
+ ALTER TABLE `customer` ADD FOREIGN KEY (`address_id`) REFERENCES `address` (`id`);
98
+ CREATE TABLE `category` (
99
+ `id` int PRIMARY KEY,
100
+ `name` varchar(255),
101
+ `last_update` timestamp
102
+ );
103
+
104
+ CREATE TABLE `film_category` (
105
+ `id` int PRIMARY KEY,
106
+ `category_id` int,
107
+ `last_update` timestamp
108
+ );
109
+
110
+ CREATE TABLE `language` (
111
+ `id` int PRIMARY KEY,
112
+ `name` varchar(255),
113
+ `last_update` timestamp
114
+ );
115
+
116
+ CREATE TABLE `film_text` (
117
+ `id` int PRIMARY KEY,
118
+ `film_id` int,
119
+ `title` varchar(255),
120
+ `description` text
121
+ );
122
+
123
+ CREATE TABLE `actor` (
124
+ `id` int PRIMARY KEY,
125
+ `first_name` varchar(255),
126
+ `last_name` varchar(255),
127
+ `last_update` timestamp
128
+ );
129
+
130
+ CREATE TABLE `film` (
131
+ `id` int PRIMARY KEY,
132
+ `title` varchar(255),
133
+ `description` text,
134
+ `releaase_year` int,
135
+ `language_id` int,
136
+ `original_language_id` int,
137
+ `rental_duration` int,
138
+ `rental_rate` decimal,
139
+ `length` int,
140
+ `replacement_cost` decimal,
141
+ `rating` varchar(255),
142
+ `special_feature` varchar(255),
143
+ `last_update` timestamp
144
+ );
145
+
146
+ CREATE TABLE `film_actor` (
147
+ `id` int PRIMARY KEY,
148
+ `film_id` int,
149
+ `actor_id` int,
150
+ `last_update` timestamp
151
+ );
152
+
153
+ CREATE TABLE `inventory` (
154
+ `id` int PRIMARY KEY,
155
+ `film_id` int,
156
+ `store_id` int,
157
+ `last_update` timestamp
158
+ );
159
+
160
+ ALTER TABLE `film_category` ADD FOREIGN KEY (`category_id`) REFERENCES `category` (`id`);
161
+
162
+ ALTER TABLE `film_text` ADD FOREIGN KEY (`film_id`) REFERENCES `inventory` (`film_id`);
163
+
164
+ ALTER TABLE `film` ADD FOREIGN KEY (`language_id`) REFERENCES `language` (`id`);
165
+
166
+ ALTER TABLE `film` ADD FOREIGN KEY (`original_language_id`) REFERENCES `language` (`id`);
167
+
168
+ ALTER TABLE `film_actor` ADD FOREIGN KEY (`film_id`) REFERENCES `film` (`id`);
169
+
170
+ ALTER TABLE `film_actor` ADD FOREIGN KEY (`actor_id`) REFERENCES `actor` (`id`);
171
+
172
+ ALTER TABLE `inventory` ADD FOREIGN KEY (`film_id`) REFERENCES `film` (`id`);