Getting Started
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.Quick Start Workflow
- Export - Click
Export Schema→Multi-File (ZIP)in Bytebase database detail page - Extract - Unzip the downloaded file to your Git repository
- Verify - Check the exported structure follows the multi-file format
- Commit - Add files to Git and push to your repository
- Make Changes - Edit the SDL files to modify your schema
- Deploy - Commit changes to trigger deployment via GitOps
How to Export Schema
- Navigate to Database Detail Page - Go to your database in Bytebase
- Click “Export Schema” Button - Find it in the action buttons at the top
- Choose Export Format:
- Multi-File (ZIP) - Recommended for GitOps workflow
- Downloads organized schema as a ZIP file
- Each object in its own file (e.g.,
schemas/public/tables/users.sql) - Ready to extract and commit to Git
- Single File - All objects in one SQL file
- Useful for quick review or legacy workflows
- Requires manual splitting if you want multi-file format
- Multi-File (ZIP) - Recommended for GitOps workflow
What Gets Exported
The multi-file export automatically includes:- Tables - With inline indexes, comments, and owned sequences
- Views - Regular views with their definitions
- Materialized Views - With their indexes and refresh settings
- Functions & Procedures - User-defined functions and stored procedures
- Sequences - Independent sequences consolidated per schema
- Comments - All object and column comments
File Organization
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.Directory Structure
Organization Rules
- One object per file - Each table, view, function, etc. has its own file
- Schema-based grouping - Objects are organized under their schema directory
- Type-based subdirectories - Within each schema, objects are grouped by type (
tables/,views/, etc.) - Sequences consolidated - Independent sequences are grouped in a single
sequences.sqlfile per schema - Related objects bundled - Table files include their indexes, comments, and owned sequences
File Naming
Files are named after the database object they define:- Tables:
schemas/{schema}/tables/{table_name}.sql - Views:
schemas/{schema}/views/{view_name}.sql - Materialized Views:
schemas/{schema}/materialized_views/{materialized_view_name}.sql - Functions:
schemas/{schema}/functions/{function_name}.sql - Procedures:
schemas/{schema}/procedures/{procedure_name}.sql - Sequences:
schemas/{schema}/sequences.sql(consolidated)
Example: Table File Content
A table file includes the table definition and all related objects:Example: Materialized View File Content
Materialized view files include the view definition and its indexes:SDL Syntax Requirements
SDL enforces strict conventions to ensure maintainability:1. Schema Qualification Required
All objects must include schema prefix:2. Table-Level Constraints
PRIMARY KEY, UNIQUE, FOREIGN KEY, and CHECK constraints must be defined at table level with explicit names:NOT NULLDEFAULTGENERATED ALWAYS ASSERIAL/BIGSERIAL
3. Named Constraints
All table constraints require explicit names:- Primary keys:
{table}_pkey - Unique constraints:
{table}_{column}_key - Foreign keys:
fk_{table}_{referenced_table} - Check constraints:
check_{description}or{table}_{column}_check
4. Foreign Key References
Foreign keys must use fully qualified table names:5. Named Indexes
All indexes must have explicit names:Supported Statements
SDL files support these PostgreSQL statements:CREATE TABLECREATE INDEX/CREATE UNIQUE INDEXCREATE VIEWCREATE SEQUENCECREATE FUNCTIONALTER SEQUENCE ... OWNED BY(for serial columns)
ALTER TABLE,DROP(Bytebase generates these)INSERT,UPDATE,DELETE(use migration-based workflow)- Transaction control (
BEGIN,COMMIT)
Complete Multi-File SDL Example
schemas/public/tables/users.sql
schemas/public/tables/user_profiles.sql
schemas/public/views/active_users.sql
schemas/public/functions/get_user_count.sql
schemas/public/sequences.sql
Next Steps
SQL Review CI
Set up SDL validation in your CI/CD pipeline
Release
Deploy your SDL changes to databases

