#postgresql #migration #sql #schema #declarative #alter #ast

bin+lib declare_schema

CLI / Library for Postgres schema migrations

10 releases

0.0.10 Nov 22, 2024
0.0.9 Oct 28, 2024
0.0.4 Aug 3, 2024
0.0.1 Jul 9, 2024

#1978 in Database interfaces

Download history 250/week @ 2024-09-25 386/week @ 2024-10-02 90/week @ 2024-10-09 400/week @ 2024-10-16 744/week @ 2024-10-23 305/week @ 2024-10-30 183/week @ 2024-11-06 221/week @ 2024-11-13 277/week @ 2024-11-20 192/week @ 2024-11-27 126/week @ 2024-12-04 85/week @ 2024-12-11 95/week @ 2024-12-18 108/week @ 2024-12-25 213/week @ 2025-01-01 190/week @ 2025-01-08

609 downloads per month

Apache-2.0

67KB
1.5K SLoC

declare-schema

Experiments with Rust declarative schemas

Use sqlparser-rs for SQL -> AST, then diff ASTs to generate ALTER ASTs, then output SQL.

WARNING: Alpha software, you will likely lose data with this library.

Goal

In application

Include database schema management in to Rust applications without the need for migration steps.

As a CLI

Provide a CLI tool that can generate diffs of schemas and the required ALTER statements for review to detect schema drift.

Easy development experience

When embedded in an application or with a CLI tool keep an easy SQL -> DB flow that is clear to developers with an easy to modify schema.

Current State

Limitations

CREATE EXTENSION - Can be created by name only. Cannot be DROPed.

CONSTRAINT - Cannot be changed, create a new one then drop the old one.

CREATE INDEX - Indexes cannot be ALTERed. To avoid errors in change detection/halting

  • Specify the schema name for the table when creating the index
  • Specify the method for USING that matches defaults:

example: CREATE INDEX idx_id on public.test USING BTREE (id DESC)

Dependencies

~17–34MB
~491K SLoC