Skip to content

PostGIS Versioning System pgvs - Base System and QGIS Client

License

Notifications You must be signed in to change notification settings

vwmaus/pgversion

 
 

Repository files navigation

<TITLE>PostGIS Versioning - pgVersion 2.1</TITLE>

PostGIS Versioning - pgVersion 2.1

Dr. Horst Duester, 2017, horst.duester@sourcepole.ch

1. Change log

2. TODO

  • Branches
  • Merging of branches

3. Prerequisits

3.1. Ubuntu

You have to install Qt4SQL and the Qt4SQL PostgreSQL driver with:

$ sudo apt-get install libqt4-sql libqt4-sql-psql python-qt4-sql

4. Introduction

Versioning of Postgis-Layers will become essential, when more than one person edits the same layer concurrently. To manage concurrencing editing of a single Postgis Layer the pgVersion management system supports your work. The idea is to create a versioning system for editing PostGIS-Layers similar to source code versioning systems like CVS or Subversion. A french tutorial was created by Nicolas Rochard.

5. Download:

Download create_pgversion_schema.sql

6. Functions

To create the new pgvs functions you should run the SQL-Script:

psql -d <databasename> -U <username> -h <hostname> \
     -f <Path to>/createFunctions.sql

After running this command, a new schema is created:

versions

and some new functions have been created in the schema versions:

pgvsinit()
pgvscommit()
pgvsmerge()
pgvsdrop()
pgvsrevert()
pgvsrevision()
pgvslogview()
pgvsrollback()

This schema contains all information which are neccessary to manage the versioned tables. I highly advise that you should not make any changes in the schema versions. Now your database is ready for versioning. You also have the option to install the pgvs environment in the template1 database. In this case every new created database will automatically contain the pgvs environment.

6.1. pgvsinit

The pgvsinit() function initializes the versioning environment for a single geometry layer.

The init command:

select * from versions.pgvsinit('<schema>.<tablename>');

The initialisation process works in 3 steps:

  • creating a view with the name <tablename>_version. This view has the same structure as the origional table.
  • creating of some rules and triggers for the new view
  • add a record to the meta table versions.version_tables

All future editings have to be done on the view <tablename>_version. If you want to change the geometry or an attribute value of a versioned PostGIS-Layer you can do this in the same way like you would edit a real table. After saving of changes on the Layer, you will see all changes you made. But your changes are only visible for you, they are saved in a temporary state. To make your changes available for the rest of the world, you have to commit your changes to the database.

It is not possible to change the structure of the underlaying table. If you want to do this, you have to drop the versioning system from the table like described later. Than you can make your changes. As the last step you have to initialize the versioning system for the table again.

6.2. pgvscommit

When you finish your editings after a while, you have to commit your editings to the main PostGIS-Layer table. In this way you make your editings available for the rest of the world.

The commit command:

select * from versions.psvscommit('<schema>.<tablename>','<log-message>';

Sometimes it happens, that two or more different users edit the same table record. In this case pgvscommit() lists the conflicting records. The conflicting objects are not saved to the database. Please contact the user mentioned in the error message to discuss, which change should be committed to the database.

6.3. pgvsmerge

To solve conflicts user the command:

select * from versions.pgvsmerge('<schema>.<tablename>',<record-id>,'<username>');

6.4. pgvsdrop

To remove the versioning system from a specific table, you can use the command:

select * from versions.pgvsdrop('<tablename>');

Than all versioning stuff will be removed from the PostGIS-Layer table. You only can drop versioning from a table when all changes of all users are committed. Don't worry, the command pgvsdrop('<tablename>'); only removes the versioning system. The main PostGIS-Layer table with all former committs still exists of course!

6.5. pgvsrevert

The pgvsrevert function gives you the option to remove all your uncommitted editings and set back your data to the HEAD revision. The revision number of the HEAD revision will be returned.

select * from versions.pgvsrevert('<tablename>');

6.6. pgvsrevision

The pgvsrevision function returns the installed revison of pgvs:

select * from versions.pgvsrevision();

6.7. pgvslogview

The pgvslogview function returns all logs of a specific versioned table:

select * from versions.pgpslogview('<tablename>');

6.8. pgvsrollback

The pgvsrollback function will push a revision into HEAD revision:

select * from versions.pgvsrollback('<tablename>',revision integer);

This function will work reliable since pgvs db-version 1.8.4 and QGIS-Plugin version 2.0.2. All prior created revisions of the layer are not ready to rollback.

7. QGIS Plugin

To make your life easier, the pgversion plugin for QGIS supports you by the use of pgvs.

7.1. Prepare layer for versioning

With this option you start the versioning for a PostGIS layer. You have to do this once for every layer versioning should be available. Select the layer and the versioning system will be available for this layer. After this step you have to remove the layer from QGIS. To work with the versioned layer you have to do the next step.

7.2. Load versioned layer

Now you can select the versioned layer from your database. In fact the corresponding layer view is loaded. Select your QGIS-PostGIS-Connection. You also will see the connected user. Than select the versioned layer from the list. The layer will be loaded to the QGIS Mapcanvas and you can start with editing.

7.3. Commit changes

When you have finished your editings you can commit your changes to the database. When no conflicts between your editings and editings of an other user have been detected you get a dialog to enter a log message. After a successful commit you will see this message.

In the case that a different editor has changed one or more objects you edited as well, a new window will appear to support the merging of concurrent objects.

The conflicting objects are shown up in red with and labled with the corresponding username.

To hightlight the object of a single record from the table below the map, click a row and the corresponding object will be hightlighted in blue color.

Now you can select the object to commit from the select box.

Click to complete merging for this single object.

7.4. Revert to head revision

Sometimes you like to remove your non committed changes. That means that you can set your view back to the HEAD revision. In this case all of your editings will be removed. To revert your editings activate the corresponding layer in the legend and select the menue "Revert to head revision"

7.5. Logview

The Logview Dialog gives you the option to get an overview over the changes of a single layer. You also are able rollback to a specific release. The rollback will be loaded to QGIS. As the result you will lose all possible changes you made before. If you want to keep this changes, you have to commit them. After the loading of the rollback your layer will be named as modified. That means only you can see this rollback. If you like to make it persistent, you have to commit it.

7.6. Drop versioning from layer

Drop versioning from layer does not drop the main layer itself. It only drops the versioning environment of the layer. This is necessary in the case you changed the model of the main table or you don't want to use the versioning environment in the future. To drop versioning from layer activate the corresponding layer in the legend and select "Drop versioning from layer" in the menue.

7.7. Help

You will get this help.

8. License

LICENSING INFORMATION:

pgvs Postgres-Functions and PgVersion QGIS Plugin is copyright (C) 2010 Dr. Horst Duester / Sourcepole AG, Zurich

horst.duester@sourcepole.ch

QGIS-Plugin icons is copyright (C) 2010 Robert Szczepanek

robert@szczepanek.pl

Licensed under the terms of GNU GPL 2

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

About

PostGIS Versioning System pgvs - Base System and QGIS Client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 76.1%
  • QML 23.9%