#database-schema #postgresql #table #column #sql #reference #trigger

schema_guard_tokio

Schema Guard: Relation (Postgres) DataBase (Schema) Management tool with BB8 and Tokio support

2 stable releases

1.8.2 Jun 9, 2024
1.8.1 May 11, 2024

#1020 in Database interfaces

Download history 143/week @ 2024-05-11 9/week @ 2024-05-18 4/week @ 2024-05-25 1/week @ 2024-06-01 174/week @ 2024-06-08 18/week @ 2024-06-15 1/week @ 2024-06-22

194 downloads per month

MIT license

77KB
1.5K SLoC

SchemaGuard

Merging YAML defined schema and data into PostgreSQL database

Create a file:

database:
  - schema:
    schemaName: test_schema
    owner: postgres
    tables:
      - table:
          tableName: test_table
          description: The new table
          constraint: -- some SQL as table constraint
          sql: -- some SQL suffix on table create
          columns:
            - column:
                name: id
                type: serial
                defaultValue:
                constraint:
                  primaryKey: true
                  nullable: false
                  foreignKey:
                    references: --fk_table
                    sql: -- some SQL suffix on new FK create, like- on delete no action on update no action
                description:
                sql: -- some SQL suffix on new column create
            - column:
                name: test
                type: varchar(250)
          triggers:
            - trigger:
                name: uniq_name_of_trigger
                event: before update
                when: for each row
                proc:

One line of code:

    let _ = schema_guard::migrate1(schema_guard::load_schema_from_file("file.yaml").unwrap(), "postgresql://")?;

Will create or upgrade existing Postgres database schema with desired tables without extra table creation.

[!NOTE] Not recommended to integrate schema migrate into application for production use as such violate security concern and best practices.

Please consider to use full-featured SchemaGuard (free for personal use)

Dependencies

~16–30MB
~483K SLoC