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: README.md
+32-21
Original file line number
Diff line number
Diff line change
@@ -6,23 +6,29 @@
6
6
7
7
A relational database schema visualizer built with React and [ReactFlow](https://github.com/wbkd/react-flow).
8
8
9
-
Originally built for [the SQL Habit course](https://www.sqlhabit.com/), it's now available for everyone. Enjoy :heart:
9
+
Originally built for [the SQL Habit course](https://www.sqlhabit.com/), it's available for everyone. Enjoy :heart:
10
10
11
11
[:mag: How to visualize your schema](https://github.com/sqlhabit/sql_schema_visualizer#how-to-visualize-your-schema) | [:microscope: How it works](https://github.com/sqlhabit/sql_schema_visualizer#under-the-hood) | [:handshake: Contributing](https://github.com/sqlhabit/sql_schema_visualizer#contributing)
12
12
13
13
</div>
14
14
15
15
## Features
16
16
17
-
:dash:**Easy to start**: you can import your schema in 1.5 minutes.
17
+
:dash:**Easy to start**: you can import your schema(s) in 1.5 minutes.
18
18
<br>
19
19
:checkered_flag:**Easy to finish**: you only need to configure edges and table positions.
20
20
<br>
21
21
:wrench:**Customizable**: add table/column descriptions and schema colors.
22
22
<br>
23
23
:rocket:**Make it yours**: you get the whole React app, so you can change everything.
24
24
25
-
## How to visualize your schema
25
+
## How to visualize your schema(s)
26
+
27
+
Schema Visualizer can visualize multiple schemas – each schema will have its own URL.
28
+
29
+
A schema configuration lives in its own folder and contains a bunch of simple JSON files.
Schema Visualizer is a React app. Here's how to install dependencies:
43
+
Install dependencies:
38
44
39
45
```bash
40
46
npm run install
41
-
42
-
npm run start
43
47
```
44
48
45
-
:computer: Now Schema Visualizer is running on your 9292 port: [http://localhost:9292](http://localhost:9292).
46
-
47
49
:bulb: You might need to install [nvm](https://github.com/nvm-sh/nvm#installing-and-updating) as well to make sure you're not using an old Node version.
48
50
49
51
### Step 2. Reset schema configuration
50
52
51
-
At this point, you should see the default schema in your browser. Let's reset all schema config files:
53
+
By default, Schema Visualizer contains [SQL Habit's](https://www.sqlhabit.com) dataset schemas. Let's delete all of them first:
52
54
53
55
```bash
54
56
npm run reset
55
57
```
56
58
57
-
After running this command, you should see an empty grid in your browser.
58
-
59
59
### Step 3. Export your schema into a CSV file
60
60
61
-
Pick a query that works for your database. Save the output of this query to the `schema.csv` file in the root folder (next to [the `schema.csv.template` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/schema.csv.template)).
61
+
A schema config consists of tables and edges. We can import table structures with an SQL query.
62
+
63
+
Pick a query that works for your database and save the output to a CSV file like `my_schema.csv`. Put it to the root folder (next to [the `schema.csv.template` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/schema.csv.template)).
62
64
63
65
#### Postgres / Redshift
64
66
@@ -99,17 +101,26 @@ WHERE
99
101
100
102
### Step 4. Import schema
101
103
104
+
Now we can import tables. The argument of the `npm run import` is your CSV file name:
105
+
106
+
102
107
```bash
103
-
npm run import
108
+
npm run import my_schema
104
109
```
105
110
106
-
Now you should see tables from your schema scattered in your browser.
111
+
You should see table JSON files added to the `src/config/my_schema/tables` folder.
112
+
113
+
Let's spin up a dev server and see our tables in the browser (they should be available on the [http://localhost:9292/](http://localhost:9292/)):
114
+
115
+
```bash
116
+
npm run start
117
+
```
107
118
108
119
### Step 5. Configure your schema
109
120
110
121
#### A. Set primary keys
111
122
112
-
To show a :key: icon next to the column name, add the `key` param to a column definition. Here's an example from [the `users` table](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/tables/users.json):
123
+
To show a :key: icon next to the column name, add the `key` param to a column definition. Here's an example from [the `users` table](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/databases/bindle/tables/users.json):
113
124
114
125
```json
115
126
{
@@ -122,7 +133,7 @@ To show a :key: icon next to the column name, add the `key` param to a column de
122
133
123
134
#### B. Add edges
124
135
125
-
Define edges in [the `src/config/edges.json` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/edges.json):
136
+
Define edges in [the `src/config/edges.json` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/databases/bindle/edges.json):
126
137
127
138
Here's an example for **has one** relation:
128
139
@@ -150,7 +161,7 @@ and **has many** relation:
150
161
151
162
#### C. Add schema colors
152
163
153
-
You can set custom header colors for tables that belongs to the same schema in [the `src/config/schemaColors.json` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/schemaColors.json). Here's an example:
164
+
You can set custom header colors for tables that belongs to the same schema in [the `schemaColors.json` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/databases/bindle/schemaColors.json). Here's an example:
154
165
155
166
```json
156
167
{
@@ -165,7 +176,7 @@ You can set custom header colors for tables that belongs to the same schema in [
165
176
166
177
#### D. Add table positions
167
178
168
-
Table positions are defined in the [`src/config/tablePositions.json` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/tablePositions.json):
179
+
Table positions are defined in the [`tablePositions.json` file](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/databases/bindle/tablePositions.json):
169
180
170
181
```json
171
182
{
@@ -183,21 +194,21 @@ Table positions are defined in the [`src/config/tablePositions.json` file](https
183
194
}
184
195
```
185
196
186
-
After you import a schema, every table will have a default position set in the [`src/config/tablePositions.json`](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/tablePositions.json) file.
197
+
After you import a schema, every table will have a default position set in the [`tablePositions.json`](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/databases/bindle/tablePositions.json) file.
187
198
188
199
There's no need to update them manually. Instead:
189
200
190
201
1. Open Schema Visualizer at [http://localhost:9292](http://localhost:9292).
191
202
2. Drag table nodes around to find a perfect arrangement.
192
203
3. **CTRL** + **P**. It copies node positions JSON to your clipboard.
193
-
4. Paste (**CMD** + **V**) JSON with positions to the [`src/config/tablePositions.json`](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/tablePositions.json) file.
204
+
4. Paste (**CMD** + **V**) JSON with positions to the [`tablePositions.json`](https://github.com/sqlhabit/sql_schema_visualizer/blob/main/src/config/databases/bindle/tablePositions.json) file.
194
205
5. PROFIT :beers:
195
206
196
207
#### E. Add table and column descriptions
197
208
198
209
Table and column descriptions are visible if you press `CMD` key and hover over a table or column name.
199
210
200
-
Add custom copy to the `"description"` keys [in table config files](https://github.com/sqlhabit/sql_schema_visualizer/tree/main/src/config/tables). Here's an example:
211
+
Add custom copy to the `"description"` keys [in table config files](https://github.com/sqlhabit/sql_schema_visualizer/tree/main/src/config/databases/bindle/tables). Here's an example:
0 commit comments