You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/create-diagram.md
+80-45Lines changed: 80 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,4 @@
1
-
import ThemedImage from '../src/components/ThemedImage';
2
-
import Flex from '../src/components/Flex';
1
+
import ThemedImage from '../src/components/ThemedImage'; import Flex from '../src/components/Flex'; import FAQ from '../src/components/FAQ';
3
2
4
3
# Create a diagram
5
4
@@ -18,75 +17,111 @@ To begin, go to the [online editor](https://www.drawdb.app/editor). If a previou
18
17
/>
19
18
</Flex>
20
19
21
-
###Pick a database
20
+
## Pick a database
22
21
23
-
You can create custom or generic diagrams. Generic diagrams can be imported from or exported to any of the supported SQL flavors(MySQL, PostgreSQL, MariaDB, SQLite, MSSQL), however, they support a fewer number of types. On the other hand, custom diagrams support all the types in the given SQL flavor.
22
+
You can create database-specific or generic diagrams.
To create relationships and define foreign keys start, click and hold the blue dot of the foreign key and drag and drop it on the primary column. Creating relationships follows the `start_col REFERENCES end_col` logic, so the column you start dragging from will become a foreign key.
If multiple primary keys are defined a composite primary key will be generated in the SQL output.
60
+
61
+
:::
62
+
63
+
:::info
64
+
65
+
The check constraint will be injected into the SQL output as is.
66
+
67
+
:::
68
+
69
+
## Create relationships
70
+
71
+
To create relationships and define foreign keys, click and hold the blue dot on the foreign key column, then drag and drop it onto the primary column. This action follows the logic of `start_col REFERENCES end_col`, where the column you drag from will be designated as the foreign key, linking it to the primary key in the destination column.
72
+
73
+
<ThemedImage lightImageSrc={require("./img/light/create-relationship.gif").default} darkImageSrc={require("./img/dark/create-relationship.gif").default} alt="Create a relationship" />
52
74
53
-
<Flex>
54
-
<div>
55
75
E.g. in the image above, since `posts.user_id` is the foreign key we start dragging from `user_id` to `users.id`.
56
76
57
-
If at some point you realize that the keys are flipped you can swap them from the `Relationships` tab. Open the relationship you'd like to edit, click on the more button next to the primary and forign columns, and then swap.
If at some point you realize that the keys are flipped you can swap them from the `Relationships` tab. Open the relationship you'd like to edit, click on the more button (three dots) next to the primary and forign columns, and then swap.
78
+
79
+
You can define the following fields for a relationship:
80
+
81
+
- Name
82
+
- Cardinality
83
+
- One to One
84
+
- One to Many
85
+
- Many to One
86
+
- On Delete Action
87
+
- On Update Action
88
+
- No action
89
+
- Restrict
90
+
- Cascade
91
+
- Set null
92
+
- Set default
93
+
94
+
<FAQheader="How can I define Many to Many relationships?">
65
95
66
-
### Organize with subject areas
96
+
In order to model Many to Many relationships you will need to use a join table.
97
+
98
+
A join table is a third table that contains foreign keys to the 2 tables you'd like to connect. Additionally, you can add any other relationship-specific columns to the table. For example:
99
+
100
+
<ThemedImage lightImageSrc={require("./img/light/many-to-many.png").default} darkImageSrc={require("./img/dark/many-to-many.png").default} alt="Pick a database" />
101
+
102
+
</FAQ>
103
+
104
+
## Organize with subject areas
67
105
68
106
You add subject areas from the `Subject Areas` tab in the sidebar or from the toolbar. They logically group the tables in subject areas to make it easier to navigate the diagram; they server a pure visual purpose and do not translate to any SQL logic and are not reflected in the generated scripts.
69
107
70
-
###Add notes
108
+
## Add notes
71
109
72
110
You add notes from the `Notes` tab in the sidebar or from the toolbar. You can use notes to capture any additional comments in the diagram.
73
111
74
-
###Custom Types
112
+
## Custom Types
75
113
76
114
If the diagram type supports custom types there will be an additional `Types` tab in the sidebar. In generic diagrams the following conversions will take place when exporing to SQL.
|**MySQL/MariaDB**| A JSON with the corresponding JSON validation check |
119
+
|**PostgreSQL**| A composite type |
120
+
|**SQLite**| BLOB |
121
+
|**MSSQL**| A type alias to the first field |
85
122
86
123
Upon adding a new type, it will be added to the list of types you can choose from when editing a column.
87
124
88
-
###Define Enums (PostgreSQL)
125
+
## Define Enums (PostgreSQL)
89
126
90
127
If the diagram is for PostgreSQL there will be an additional `Enums` tab in the sidebar where you can define enum values. Upon adding a new enum, it will be added to the list of types you can choose from when editing a column.
0 commit comments