|
1 | | -# Pum |
| 1 | +** - PostgreSQL Upgrades Manager (PUM)** |
2 | 2 |
|
3 | | -Pum stands for "Postgres Upgrades Manager". It is a Database migration management tool very similar to flyway-db or Liquibase, based on metadata tables. |
| 3 | +PUM is a robust database migration management tool designed to streamline the process of managing PostgreSQL database upgrades. Inspired by tools like FlywayDB and Liquibase, PUM leverages metadata tables to ensure seamless database versioning and migration. |
4 | 4 |
|
| 5 | +### Key Features |
5 | 6 |
|
6 | | -## Features |
7 | | -Pum is python program that can be used via command line or directly from another python program. |
| 7 | +- **Command-line and Python Integration**: Use PUM as a standalone CLI tool or integrate it into your Python projects. |
| 8 | +- **Database Versioning**: Automatically manage database versioning with metadata tables. |
| 9 | +- **Database Comparison**: Compare two databases to identify differences in tables, columns, constraints, and more. |
| 10 | +- **Backup and Restore**: Create and restore database backups with ease. |
| 11 | +- **Changelog Management**: Apply and track SQL delta files for database upgrades. |
8 | 12 |
|
9 | | -Pum permits the followings operations on Postgres databases: |
| 13 | +### Why PUM? |
10 | 14 |
|
11 | | -- check the differences between two databases |
12 | | -- create a backup (dump file) of a database |
13 | | -- restore a database from a backup |
14 | | -- upgrade a database applying delta files |
| 15 | +Managing database migrations in a Version Control System (VCS) can be challenging, especially for production databases. PUM simplifies this process by embedding version metadata directly into the database, enabling efficient tracking and application of migrations. |
15 | 16 |
|
16 | | -and some other useful operations. |
| 17 | +### Getting Started |
17 | 18 |
|
18 | | -## General purpose and workflow |
| 19 | +1. **Install PUM**: |
| 20 | + ```sh |
| 21 | + pip install pum |
| 22 | + ``` |
| 23 | + Ensure you have Python 3 and PostgreSQL utilities (`pg_restore` and `pg_dump`) installed. |
19 | 24 |
|
20 | | -Good practices regarding database versioning and migration are not so easy to handle in a VCS (Version Control System). Initial development is easy, using pure Git, and sometimes some meta SQL generation scripts. But when it comes to maintaining databases already in production, good practices differ a lot since SQL patches can't be handled the same way as Git diffs. |
| 25 | +2. **Baseline Your Database**: |
| 26 | + Use the `baseline` command to initialize metadata in your database. |
21 | 27 |
|
22 | | -We recommend reading some of those great articles to get a clearer view on what could, and should (or not) be done: |
| 28 | +3. **Apply Migrations**: |
| 29 | + Use the `upgrade` command to apply SQL delta files and keep your database up-to-date. |
23 | 30 |
|
24 | | -- https://blog.codinghorror.com/get-your-database-under-version-control/ |
25 | | -- http://petereisentraut.blogspot.fr/2012/05/my-anti-take-on-database-schema-version.html |
| 31 | +### Best Practices |
26 | 32 |
|
27 | | -The worklow involves having version metadata written INSIDE the database and using that to check current state, old migrations, new migrations to apply, etc.. |
| 33 | +- **Separate Schemas**: Isolate data and business logic (e.g., views, triggers) into distinct schemas for easier upgrades. |
| 34 | +- **Read More**: Explore articles like [Get Your Database Under Version Control](https://blog.codinghorror.com/get-your-database-under-version-control/) for insights into database versioning. |
28 | 35 |
|
29 | | -The first thing to do is use the "baseline" command to create metadata in your database, and then you are good to go. |
| 36 | +### Learn More |
30 | 37 |
|
31 | | -## Installation |
| 38 | +- [Command Line Usage](#command-line) |
| 39 | +- [Delta Files](#delta-files) |
| 40 | +- [Configuration](#config-file) |
32 | 41 |
|
33 | | -### System-wide |
| 42 | +PUM was developed to address challenges in the [TEKSI](https://github.com/TESKI) project, an open-source GIS for network management based on [QGIS](http://qgis.org/fr/site/). |
34 | 43 |
|
35 | | -This is the easiest way to install pum for every user on a system |
36 | | - |
37 | | -```sh |
38 | | -sudo pip3 install pum |
39 | | -``` |
40 | | - |
41 | | -### Local user |
42 | | - |
43 | | -Alternatively, to install pum to a virtual environment without requiring sudo access |
44 | | - |
45 | | -```sh |
46 | | -mkdir -p ~/.venv |
47 | | -virtualenv -p python3 ~/.venv/pum |
48 | | -source ~/.venv/pum/bin/activate |
49 | | -pip install pum |
50 | | -``` |
51 | | - |
52 | | -Whenever you use pum you will need to activate the virtual environment prior to using pum |
53 | | - |
54 | | - |
55 | | -```sh |
56 | | -source ~/.venv/pum/bin/activate |
57 | | -``` |
58 | | - |
59 | | -### Dependencies |
60 | | - |
61 | | -Pum depends on python3 and postgresql (specifically `pg_restore` and `pg_dump`). Make sure to read the [config file section](#config-file) below if you're on Windows. |
62 | | - |
63 | | -## History |
64 | | - |
65 | | -Pum has been developed to solve issues encountered in the [QWAT](https://github.com/qwat) and [QGEP](https://github.com/QGEP/QGEP) project, which are open source Geographic Information System for network management based on [QGIS](http://qgis.org/fr/site/). |
66 | | -QWAT already developed a dedicated migration tool, allowing to both work on the data model using git AND use delta file for migrations. QGEP needed something also so the group decided to make a more generic tool, yet a simple one to handle that. |
67 | 44 |
|
68 | 45 | ## Command line |
69 | 46 |
|
|
0 commit comments