Skip to main content
Create SDL files that define your complete database schema in a declarative format.

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

  1. Export - Click Export SchemaMulti-File (ZIP) in Bytebase database detail page
  2. Extract - Unzip the downloaded file to your Git repository
  3. Verify - Check the exported structure follows the multi-file format
  4. Commit - Add files to Git and push to your repository
  5. Make Changes - Edit the SDL files to modify your schema
  6. Deploy - Commit changes to trigger deployment via GitOps
The exported ZIP contains a complete, ready-to-use schema structure. You can immediately commit it to Git without any manual organization.

How to Export Schema

  1. Navigate to Database Detail Page - Go to your database in Bytebase
  2. Click “Export Schema” Button - Find it in the action buttons at the top
  3. 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

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.sql file 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:
Allowed at column level:
  • NOT NULL
  • DEFAULT
  • GENERATED ALWAYS AS
  • SERIAL / BIGSERIAL

3. Named Constraints

All table constraints require explicit names:
Naming conventions:
  • 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 TABLE
  • CREATE INDEX / CREATE UNIQUE INDEX
  • CREATE VIEW
  • CREATE SEQUENCE
  • CREATE FUNCTION
  • ALTER SEQUENCE ... OWNED BY (for serial columns)
Not Allowed:
  • 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