schema_guard

Crates.ioschema_guard
lib.rsschema_guard
version1.6.1
sourcesrc
created_at2024-03-24 18:03:11.066812
updated_at2024-03-24 18:03:11.066812
descriptionSchema Guard: Relation Database (Schema) Management tool
homepagehttps://github.com/vkrinitsyn/schema_guard
repositoryhttps://github.com/vkrinitsyn/schema_guard
max_upload_size
id1184605
size79,139
(vkrinitsyn)

documentation

https://www.dbinvent.com/rdbm/guide/getting-started#declarative

README

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(), &mut db)?;

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)

Commit count: 3

cargo fmt