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
@@ -6,33 +6,145 @@ Create SDL files that define your complete database schema in a declarative form
6
6
7
7
## Getting Started
8
8
9
-
When starting with state-based workflow:
10
-
11
-
1.**Export Current Schema** - In Bytebase database detail page, click `Export Schema` to download your current database schema
12
-
2.**Organize Schema Files** - Edit and organize the exported schema into manageable files
13
-
3.**Commit to Repository** - Add SDL files to version control
14
-
4.**Make Changes** - Update the desired state and commit
9
+
To use state-based workflow, you must start by exporting your database schema. Bytebase provides a built-in export feature that generates SDL files in the multi-file format, ready to commit to your Git repository.
2.**Extract** - Unzip the downloaded file to your Git repository
15
+
3.**Verify** - Check the exported structure follows the [multi-file format](#file-organization)
16
+
4.**Commit** - Add files to Git and push to your repository
17
+
5.**Make Changes** - Edit the SDL files to modify your schema
18
+
6.**Deploy** - Commit changes to trigger deployment via GitOps
19
+
20
+
<Tip>
21
+
The exported ZIP contains a complete, ready-to-use schema structure. You can immediately commit it to Git without any manual organization.
22
+
</Tip>
23
+
24
+
### How to Export Schema
25
+
26
+
1.**Navigate to Database Detail Page** - Go to your database in Bytebase
27
+
2.**Click "Export Schema" Button** - Find it in the action buttons at the top
28
+
3.**Choose Export Format**:
29
+
-**Multi-File (ZIP)** - Recommended for GitOps workflow
30
+
- Downloads organized schema as a ZIP file
31
+
- Each object in its own file (e.g., `schemas/public/tables/users.sql`)
32
+
- Ready to extract and commit to Git
33
+
-**Single File** - All objects in one SQL file
34
+
- Useful for quick review or legacy workflows
35
+
- Requires manual splitting if you want multi-file format
36
+
37
+
### What Gets Exported
38
+
39
+
The multi-file export automatically includes:
40
+
-**Tables** - With inline indexes, comments, and owned sequences
41
+
-**Views** - Regular views with their definitions
42
+
-**Materialized Views** - With their indexes and refresh settings
43
+
-**Functions & Procedures** - User-defined functions and stored procedures
44
+
-**Sequences** - Independent sequences consolidated per schema
45
+
-**Comments** - All object and column comments
15
46
16
47
## File Organization
17
48
18
-
Organize SDL files by schema or module:
49
+
Bytebase uses a **multi-file format** where each database object is stored in a separate file, organized by schema and object type. This structure provides clear organization and makes code reviews easier.
50
+
51
+
### Directory Structure
19
52
20
53
```
21
-
schema/
22
-
├── public.sql # Public schema objects
23
-
├── analytics.sql # Analytics schema
24
-
└── internal.sql # Internal schema
54
+
schemas/
55
+
├── public/
56
+
│ ├── tables/
57
+
│ │ ├── users.sql
58
+
│ │ ├── orders.sql
59
+
│ │ └── products.sql
60
+
│ ├── views/
61
+
│ │ ├── active_users.sql
62
+
│ │ └── order_summary.sql
63
+
│ ├── materialized_views/
64
+
│ │ └── sales_summary.sql
65
+
│ ├── functions/
66
+
│ │ └── get_user_count.sql
67
+
│ ├── procedures/
68
+
│ │ └── update_user_status.sql
69
+
│ └── sequences.sql
70
+
├── analytics/
71
+
│ ├── tables/
72
+
│ │ └── events.sql
73
+
│ └── views/
74
+
│ └── daily_stats.sql
75
+
└── internal/
76
+
└── tables/
77
+
└── audit_logs.sql
25
78
```
26
79
27
-
Or split by object type:
80
+
### Organization Rules
81
+
82
+
-**One object per file** - Each table, view, function, etc. has its own file
83
+
-**Schema-based grouping** - Objects are organized under their schema directory
84
+
-**Type-based subdirectories** - Within each schema, objects are grouped by type (`tables/`, `views/`, etc.)
85
+
-**Sequences consolidated** - Independent sequences are grouped in a single `sequences.sql` file per schema
86
+
-**Related objects bundled** - Table files include their indexes, comments, and owned sequences
87
+
88
+
### File Naming
89
+
90
+
Files are named after the database object they define:
0 commit comments