Install

From crates.io

bash cargo install pgfine

From repository

bash git clone https://gitlab.com/mrsk/pgfine cargo install --path ./pgfine

Create new project

bash export PGFINE_CONNECTION_STRING="..." export PGFINE_ADMIN_CONNECTION_STRING="..." export PGFINE_DIR="./pgfine" - Run pgfine init - Modify newly created ./pgfine/create/*.sql and ./pgfine/drop/*.sql scripts if needed.

Environment variables

Connection strings: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING

Create a database

bash source env-local-db-0.sh pgfine migrate

Making changes to database

Table constraints should be stored along with tables. You will have a problem if constraints form circular dependencies.

Rollbacks

Database objects

Database objects are: - tables - views - indexes - constraints - functions - ...

Each database object has coresponding create/alter script in pgfine project directory (see bellow for details). Filenames should consist of schema name and object name and .sql extension (example: ./pgfine/tables/public.some_table_0.sql).

Database object scripts are executed when pgfine attempts to create or alter database object; except for tables - pgfine won't attempt to alter or drop tables, these changes have to be implemented using migration scripts.

Sometimes object needs to be dropped and created instead of updating it in place (one such case is when argument is removed from function definition). Drop script is generated using object id.

Tables

Example ./pgfine/tables/public.table0.sql: ```sql create table table0 ( id bigserial primary key );

-- create indexes -- create constraints -- create rules -- create triggers

```

Views

Example ./pgfine/views/public.view0.sql: ```sql -- it is recommended to include "or replace", otherwise it will be dropped and created again each time changes are made. create or replace view view0 as select t0.id from table0 t0 join table1 t1 on t1.id = t0.id

-- create indexes maybe ```

Commands

pgfine init [./pgfine]

pgfine create

pgfine migrate

pgfine drop --no-joke

Structure

Files

pgfine_objects table

Contains a list of managed pgfine objects and their hashes.

pgfine_migrations table

Contains a list of executed migrations. Selecting the max value should reveal the current state of database.

Assumptions

Plan for 1.0.0

Post 1.0.0 plan