Git Product home page Git Product logo

pgversion's Introduction

PostGIS Versioning - pgVersion 3.4.0

Dr. Horst Duester, 2023, [email protected]

  1. Administration
  2. PgVersion plugin functionality
  3. Implementation as a PgVersion plugin in QGIS
  4. Practical tips:

1. Administration

This section is about installing and administer the database in preparation for working with PGVersion.

1.1 Installation of the database

For example, assume that the database is named historization and is installed by the default administrator postgres on the server with the IP address 192.168.2.10 shall be.

![CreateDatabase_en](docs/help/image_en/CreateDatabase_en.png) Figure 1: Create a new database with PgAdmin3.

createdb -U postgres -h 192.168.2.10 historization

1.1.1 Login roles

For testing, two login roles (user1 and user2) are created for the database. This can be done either via the administration tool PgAdmin3. For simplicity, username and password are the same.

Or run under Linux in bash.

createuser -U postgres -h 192.168.2.10 -S -D -R -e user1 -W createuser -U postgres -h 192.168.2.10 -S -D -R -e user2 -W

1.1.2 Authentication to the database

The configuration file for authentication pg_hba.conf must be adapted to the requirements of the user environment. Entries are added for valid IP address ranges and for authentication.

Further information can be found in the help of the PostgreSQL project: https://www.postgresql.org/docs/9.6/static/auth-pg-hba-conf.html

1.1.3 Configuration of the database

Now the adjustment PostgeSQL configuration file postgresql.conf is done. There are a variety of settings here. However, only the parameters port and listen_addresses are necessary for the beginning. These grant database access over the network. Therefore we change the following entry:

listen_addresses = '*' port = 5432

All other parameters we leave at this point as they are.

1.1.4 Enable the PostGIS extension for the database

In order to use spatial functionality in PostgreSQL, the database must be supplemented with the PostGIS extensions. This can either take place via the administration tool PgAdmin3 or run under Linux in bash.

![InstallPostGISExtension_en](image_en/InstallPostGISExtension_en.png) Figure 2: Install PostGIS extension.

Extension to GIS functions after login to the database with the command: psql -U postgres -h 192.168.2.10 historization

historization=# CREATE EXTENSION postgis;

1.2 Installation of the QGIS plugin PgVersion

PgVersion is available as a plugin over the QGIS plugin repository it can be easily installed via the QGIS Plugin Manager.

After installation, it is in the working directory of the user.

under Linux:
/home/<user>/.local/share/QGIS/QGIS3/profiles/default/python/plugins/pgversion/

under Windows:
C:\Users\<user>\AppData\Roaming\QGIS\QGIS3\profiles\default\python/plugins/pgversion/

1.3 Installation of PgVersion

The extension of the database with the pgvs functions of PgVersion is usually started from a computer on which the corresponding QGIS plugin "pgversion" is installed. There is the possibility to install it via the command line or the plugin.

1.3.1 Installation via the command line

Change to the docs directory of the plugin.

under Linux:
/home/<user>/.local/share/QGIS/QGIS3/profiles/default/python/plugins/pgversion/docs/

under Windows:
C:\Users<user>\AppData\Roaming\QGIS\QGIS3\profiles\default\python/plugins/pgversion/docs/

Run the following command from the command line psql -U postgres -d historization -h 192.168.2.10 -f create_pgversion_schema.sql

This creates a new schema versions in the historization database in which the new pgvs functions are stored.

The functions can basically also be executed directly on the database. This means that PgVersion can also be used without QGIS or the QGIS plugin.

Furthermore, a new group role versions is created. This already contains a number of rights so that login roles that are members of the group role versions can work with PgVersion.

1.3.2 Installation with the QGIS plugin

The other option is to perform the installation of the pgvs functions in QGIS via the loaded plugin. If you have imported some layers into the new database and want to start the history of the first layer, click on the icon. Then comes the message.

![Install_pgvs_en](image_en/Install_pgvs_en.png) Figure 4: pgvs is not installed.

Now click on the Install pgvs icon to install the versioning. Then a success message should appear.

![Install_pgvs_success_en](image_en/Install_pgvs_success_en.png) Figure 5: The installation of pgvs was successful.

1.3.3 Rights management

Before starting to version the first layers, a few DEFAULT PRIVILEGES should be added. For this, e.g. again PgAdmin3, the QGIS DB Manager or the command line are used. Depending on requirements, the rights can be adjusted - here is an example:

Roles user1 and user2 become members of the group role versions GRANT versions TO user1; GRANT versions TO user2;

Allow default access to future tables ALTER DEFAULT PRIVILEGES IN SCHEMA public, versions GRANT ALL ON TABLES TO versions;

Default rights to functions in schema versions ALTER DEFAULT PRIVILEGES IN SCHEMA versions, public GRANT EXECUTE ON FUNCTIONS TO versions;

Default rights to sequences in schemas versions and public ALTER DEFAULT PRIVILEGES IN SCHEMA versions, public GRANT USAGE, SELECT ON SEQUENCES TO versions;

If a table has already been versioned before, corresponding rights can also be given later. The rights specified here can be adjusted as needed.

Allow access to existing tables GRANT ALL ON ALL TABLES IN SCHEMA public, versions TO versions;

Give rights to all sequences in scheme public and versions GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA versions, public TO versions;

Give rights to all functions in schemas publich and versions GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA versions, public TO versions;

2. Functionality of the PgVersion plugin

After the database historization with the schema versions and the users user1 and user2 has been created, you can use the pgvs functions be used on the PgVersion Pugin.

After installing and activating the plugin, the functionality can be accessed via icons in the toolbar of QGIS:

![PgVersion_Toolbar_en.png](image_en/PgVersion_Toolbar_en.png) Figure 7: PgVersion toolbar.

Furthermore there is the menu entry "Database" → "PG Version":

![PgVersion_Integration_en](image_en/PgVersion_Integration_en.png) Figure 7: PG Version integration in QGIS Menu.

2.1 Included database functions

The schema versions created at initialization contains all the information needed to manage the versioned tables. Be careful not to make any changes in the versions schema. This is reserved for the pgvs functions alone.

Incidentally, you also have the option to install the pgvs environment in the template1 database of the PostgreSQL server. In this case, any newly created database will automatically contain the pgvs environment.

2.1.1 pgvsinit

The pgvsinit() function initializes the versioning environment for a single layer. The init command is:

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

The initialization works in 3 steps:

  • A view with the name <table_name>_version is created. This has the same structure as the original table.
  • It will create some rules and triggers for the new view.
  • It will be a meta-table record versions.version_tables added.

Any future changes you make will be reflected on the view <table_name>_version instead of. If you want to change the geometry or attribute value of a versioned PostGIS layer, you can do so in the same way you edit a real table.

After the changes have been saved for the layer, they will be visible - but only for you. For this they are stored in a temporary state, as a memory layer. To make the changes visible to the rest of the world, you must commit your changes to the database.

It is not possible to change the structure of the underlying table. If you want to do this, you must delete the versioning system from the table, as described later. Then you can make your changes. Then you have to initialize the versioning system for the table again.

2.1.2 pgvscommit

After a while, when your changes are complete, you must commit them to the Master PostGIS table. This will make your changes available to other users.

The commit command is:

select * from versions.psvscommit('<schema>.<table_name>', '<_log-message_>');

Sometimes it happens that two or more users are working on the same table object. In this case, the pgvscommit () function lists the conflicting records. The conflict objects are not stored in the database. In this case, please contact the other user in the error message to discuss which change should be applied to the database.

2.1.3 pgvsmerge

In order to solve conflicts the command serves:

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

2.1.4 pgvsdrop

To remove the versioning for a specific table, use the command: select * from versions.pgvsdrop('<table_name>');

This removes all versioning entries from the PostGIS table. You can only delete the versioning of a table if all changes are committed by all users.

You do not have to worry about that, because the command pgvsdrop('<table_name>'); only removes the versioning system. Of course, the Master PostGIS table with all former changes (committs) still exists.

2.1.5 pgvsrevert

The pgvsrevert function offers the possibility to remove all not yet committed changes and to return your data to the HEAD revision. The revision number of the HEAD revision is returned.

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

2.1.6 pgvsrevision

The pgvsrevision function returns the installed revision of pgvs.

select * from versions.pgvsrevision();

2.1.7 pgvslogview

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

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

2.1.8 pgvsrollback

The pgvsrollback function returns a revision to the HEAD revision:

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

This feature works reliably from the pgvs db version 1.8.4 and the QGIS plugin version 2.0.2. If there are previous revisions of a layer, they are not ready for rollback.

3. Implementation as PgVersion plugin in QGIS

To make it easier to work with the pgvs functions, they are implemented as QGIS Plugin PgVersion for QGIS 3.x and PostGIS 2.x. The available functionality includes the following steps:

3.1 Connection to the database

Start QGIS and create a connection to the database historization via "Add PostGIS Layer". Now load a layer you want to provide for versioning, e.g. from the public schema, into your QGIS project.

3.2 Layer provided with the versioning system Layer_versioned_System_Icon_en

This option starts the versioning for a PostGIS layer. You have to do this once for each layer to be integrated into the versioning. Select the layer in the layer window and click on the icon "Prepare the layer for versioning" and the versioning system will be initialized for it.

![Version_Environment_en](image_en/Version_Environment_en.png) Figure 8: Create the version environment.

After confirming this step, another window opens, confirming the initialization and informing you to adjust the user rights for the view if required and the layer for further editing via the functionality of the QGIS pgversion plugin "Loading the versioned layer" to load.

![Initialisation_success_en](image_en/Initialisation_success_en.png) Figure 9: The initialization was successful!

Confirm this message by clicking OK. The layer is now removed from the layer window. The rights described in Chapter 1 have been assigned to the newly versioned layer as DEFAULT PRIVILEGES via the group role versions.

To work with the versioned layer you have to load it again via the plugin tools. Depending on the rights, each user can version tables. However, we recommend leaving this to the administration of the database.

3.3 Loading the versioned layer Loading_versioned_Layer_Icon_en

Now you can load the corresponding view with the icon "Load the versioned layer".

![Versioned_system_en](image_en/Versioned_system_en.png) Figure 10: PostGIS versioning system.

Choose your database connection. You will then see the connected users and can select the versioned layer from a list, load it into QGIS and start editing. If a versioned layer is already loaded in QGIS, you will be notified accordingly.

3.4 Commit changes Commit_Changes_Icon_en.png

When you have finished editing, you can commit your changes to the database. Save the changes first. The layer is then supplemented in the layer window with a (modified) note.

Now click on the icon "Transfer changes". If no conflicts between your changes and another user's changes have been detected for the edited objects, a dialog opens in which you must enter a log message.

![Description_of_modification_en](image_en/Description_of_modification_en.png) Figure 11: Change description.

If you do not enter a message, the last commit message below will be used. It is therefore not possible to commit without a commit message. Confirm this dialog with OK. With the icon "Show Logs" you can see the log information of the last commits.

In the event that another user has changed one or more objects that you have also edited, a new window will open, showing the conflicts with the other changes and giving you the option of choosing one version or the other.

![Changes_user01_en](image_en/Changes_user01_en.png) Figure 12: Adjustments User 1. ![Canges_user02_en](image_en/Canges_user02_en.png) Figure 13: Adjustments User 2.

To mark the conflict variants of the users of an object from the table below the map, select the line and thus the object variant of a user. This is then highlighted in blue.

![Candidates_Conflicts_en](image_en/Candidates_Conflicts_en.png) Figure 14: Candidate list in case of conflict.

You have two options for resolving conflicts.

  • You can process the "conflict" candidates one after the other and decide individually which candidate should be accepted.
  • You choose to accept all commits of a user.

3.5 Reset to the HEAD revision Head_Revision_Resetting_Icon_en

If you want to remove a saved but not yet committed change, it means that you need to move the view back to the HEAD revision, which is the version you checked out at the beginning of the work.

In this case, any changes that have been made so far will be removed. To use this feature, select the appropriate layer and click the "Reset to HEAD Revision" icon.

3.6 Show differences Show_Changes_Icon_en

![Differents_in_Database_HEAD_en](image_en/Differents_in_Database_HEAD_en.png) Figure 15: Difference local adaptation and HEAD of the database.

If you want to compare a saved, but not yet made change with the current HEAD revision in the database, you can do this with the icon "Differences to HEAD Revision" - see also chapter 3.7.

A difference layer is created for the selected map section, which shows you with a green line which geometries have been added and with a red line which geometries have been removed. The difference layers are memory layers and can be easily deleted from the layer window when you no longer need them.

If you want to compare the changes in the attribute table, you can also do so by clicking the object with the QGIS Query Objects tool and Top to Bottom mode. Then the query results display the attributes for visual comparison.

3.7 Show logs Show_Logs_Icon_en

The Logview dialog gives you the opportunity to get an overview of the changes of a single layer. You will also be able to return to a specific revision or marker. The rollback is then loaded into QGIS and displayed.

![Show_Revision_Logs_en](image_en/Show_Revision_Logs_en.png) Figure 16: Show and display revision logs.

Possible approaches are:

  • You select a revision and then click on the "Check out selected revision" button to display it in QGIS.
  • If you want to compare a saved but not yet committed change with the current HEAD revision in the database - see also chapter 3.6, you can do this with the icon "Differences to HEAD Revision".
  • You select a revision and then click the "Reset to the selected revision" button to make it the current version (HEAD). Previously created revisions are retained.
  • You select a revision and click the right mouse button to mark the revision and save it as a "tag". In the picture as example "Completion phase 1 on 28.3.2017". These can now be selected, checked out and viewed in QGIS.
![Set_Tags_en](image_en/Set_Tags_en.png) Figure 17: Set tags.

3.8 Delete selected objects directly in the database Delete_Icon_en

This functionality allows objects of a versioned layer previously selected in QGIS to be deleted directly on the database. QGIS 'own function for deleting selected objects turned out to be very slow, so this functionality was additionally integrated at this point. However, it can only be used if the user has the appropriate rights in the database.

![Delete_in_DB_en](image_en/Delete_in_DB_en.png) Figure 18: Delete directly in the database.

3.9 Delete versioning of the level Delete_Icon_en

Like the direct deletion in the database, this functionality is not directly accessible from the toolbar. Deleting the versioning of a layer does not delete the layer itself.

It is "only" about the versioning environment of the layer. This is necessary the moment you want to change the model of the layers, e.g. add a new attribute column or no longer want to use versioning for the layer.

Activate the corresponding layer and click on "Delete layer versioning" in the menu.

4. Tips for the practice

At this point, practical tips to get started in working with the plugin to be facilitated. We assume that the corresponding layers are already historicized.

4.1 Basic settings in QGIS

  • Under Settings → Options → Data sources, set the following:
    • Attribute Table Behavior = Show Visible Objects of the Map
    • Attribute table row cache = ~ 200000 (depending on the maximum number of objects in your layers)
  • In the Settings → Options → Appearance menu, set the following:
    • Uncheck "Normally, all new layers are displayed"
    • Activate "Use presentation cache"
    • Check "Draw parallel layers with many CPU cores" and specify a maximum number of cores to use.
  • In the menu, select Settings → Options → Digitization:
    • Check "Show Snap Options Dialog in a Dock Window". After a one-time QGIS reboot, you can then set the capture mode in the dock window and also specify whether topological functionality should be used when digitizing.

4.2 Historization of a layer with bigint data type of the ID column

For some data, the ID column is created in the attribute table as a "bigint" or "integer64" data type. When importing these layers to PostGIS, the data type is not automatically converted to "bigserial". However, this is necessary for the versioning, where the column by default acts as a "Primary-Key" column. Therefore, after the import and before the versioning, the conversion from the bigint to the bigserial data type must be done manually, see example for the layer bauleitplanung_nds.

First, the following value is determined for the existing data record for the column id:

SELECT MAX(id)+1 FROM "bauleitplanung_nds";

The result (for example: 44151) is then used to create a sequence and assign it to the id column so that it is converted into the serial data type. The following additional steps are necessary for this:

CREATE SEQUENCE bauleitplanung_nds_id_seq start with 44151 owned by "bauleitplanung_nds"."id";

ALTER TABLE bauleitplanung_nds ALTER COLUMN id SET DEFAULT nextval('bauleitplanung_nds_id_seq');

ALTER SEQUENCE bauleitplanung_nds_id_seq OWNED BY "bauleitplanung_nds"."id";

The PgVersion plugin checks when initializing a new layer whether the PrimaryKey data type is "serial" or "bigserial". If this is not the case, the process is aborted with an error.

![DB_mistake_en](image_en/DB_mistake_en.png) Figure 19: Error with missing serial data type.

4.3 Customize existing object geometries of a layer

  • Load the historized layer grenzen_bkg via the pgversion plugin and the WMS service WebAtlasde via the tool Add WMS layer.
  • Activate the edit mode of the layer borders_bkg, zoom in on an area and flatten the vertices of a line.
  • Save the change in QGIS. The modified layer now gets the addition (modified). The change has not yet been returned to the historization.
  • Take a look at the difference between the two versions by clicking the PgVersion Show Differences tool. You can now see in red which line area is removed and in green which line area has been added.
  • Select the pgversion tool "Pass change" and enter a change description in the Commit window, e.g. "Line course adjusted". Then click OK". The addition (modified) disappears again.
  • You can understand this first change by clicking on the "Show Logs" PgVersion tool.

4.4 Customize existing attributes of a layer

  • Load the historized layer grenzen_bkg via the PgVersion plugin.
  • Activate the editing mode of the layer borders_bkg, open the layer's attribute table and write something in the column "notice".
  • Save the change in QGIS. The modified layer now gets the addition (modified). The change has not yet been returned to the historization.
  • Take a look at the difference between the two versions by clicking the PgVersion Show Differences tool. If you then select both versions and compare them using a query in the Layer Selection mode, you can understand the changes.
  • Next, select the PgVersion "Submit Change" tool and enter a change description in the Commit window, e.g. Note entry in column. Then click OK". The addition (modified) disappears again.
  • You can understand this change by clicking on the "Show Logs" PgVersion tool.

4.5 Add a new object to a layer

  • Load the historized layer grenzen_bkg via the PgVersion plugin.
  • Activate the editing mode of the layer borders_bkg, zoom into an area and add a new borderline anywhere.
  • Save the change in QGIS. The modified layer now gets the addition (modified). The change has not yet been returned to the historization.
  • Take a look at the difference between the two versions by clicking the PgVersion Show Differences tool. If you then select both versions and compare them using a query in the Layer Selection mode, you can understand the changes.
  • Next, select the PgVersion "Submit Change" tool and enter a change description in the Commit window, e.g. "Added new border". Then click OK". The addition (modified) disappears again.
  • You can understand this change by clicking on the "Show Logs" PgVersion tool.

4.6 Delete objects in a layer

  • Deleting objects in a layer Load the historicized layer windenergie via the pgversion plugin.
  • Activate the edit mode of the layer windenergie, zoom to the area in the middle of the North Sea, mark it and then delete. You have two options:
    • They can remove the surface via the QGIS tool "Delete Selected".
    • You can use the PgVersion tool "Delete directly in the database".The latter is always the better option when dealing with large amounts of data. Otherwise, this can take a long time with the QGIS tool.
  • Save the change in QGIS. The modified layer now gets the addition (modified). The change has not yet been returned to the historization.
  • Now click on the PgVersion tool "Reset to Head Revision". As a result, your changes are lost, they are discarded.

4.7 Discard recent changes

  • Load the historized layer grenzen_bkg via the PgVersion plugin.
  • Activate the editing mode of the layer borders_bkg, zoom in on an area and move the vertices of a line.
  • Save the change in QGIS. The modified layer now gets the addition (modified). The change is not yet returned to the versioning.
  • Select the PgVersion "Submit Change" tool and enter a change description in the Commit window, e.g. "Area deleted". Then click OK". The addition (modified) disappears again.
  • You can understand this first change by clicking on the "Show Logs" PgVersion tool.

4.8 Go back to a previous revision of a layer

  • Load the historized layer grenzen_bkg via the PgVersion plugin.
  • Click the PgVersion Show Logs tool, and then select a revision to which you want to reset the layer.
  • Now click on the button "Reset to the selected revision". The previous steps are still historicized. However, you have reset the state of the layer to the status of the selected revision.

4.9 Remove a layer from versioning

  • Download the historicized polygon layer navigation via the PgVersion plugin.
  • Select the layer and go to the menu Database → PgVersion.
  • There you can remove the layer from the versioning with the tool "Delete Versioning of the Layer".
  • Please remember, this step is irrevocable!

4.10 Resolve a conflict while editing

  • Load the historized polygon layer navigation via the PgVersion plugin.
  • Select the layer, make a change to a polygon, and save it locally without committing it.
  • Now load the historized polygon layer navigation via the PgVersion plugin as another user. Make a change to the same polygon and commit it back to the versioning.
  • Then switch back to the 1 user and try to commit your change as well.
  • A window will now open, allowing you to solve the conflict together with the other user.

4.11 Update with copy / paste on the QGIS screen

  • Download the versioned record rail_version
  • Download the continuation Entwurf_LROP_2014_Schiene.shp
  • Bring both layers into edit mode and then copy / paste the versioned dataset with the geometries and attributes from the continuation.

4.12 NULL values of the primary-key column not allowed

QGIS recognizes the presence of a Primary-Key column during editing and does not allow it to be saved without entering a value.

![NULL_Value_in_PrimaryKey_en](image_en/NULL_Value_in_PrimaryKey_en.png) Figure 20: Saving a value with a primary key NULL.

There are 2 ways to handle it.

  • You can always enter any value. This will be overwritten when passing the changes to the versioning.
  • Once after the initial versioning of a layer, you define this in the Layer properties menu → Attribute form for the "ID" column in the Set control element type area, that this will become a hiding place. Then save the style as default in the database, so that it is always used automatically for each user.
![Save_Style_in_DB_en](image_en/Save_Style_in_DB_en.png) Figure 21: Save the style in the database.

pgversion's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pgversion's Issues

install error

Below error message prompted when installed on QGIS 3.4

ImportError: PyQt4 classes cannot be imported in QGIS 3.x. Use PyQt5.QtCore or the version independent qgis.PyQt.QtCore import instead.

Plugin don't work

Hi everyone I installed the plugin in QGIS and it appeared in the DB Manager, at a certain point it disappeared and if I try to use it from the gui in the toolbar it gives me the following error

AttributeError: 'NoneType' object has no attribute 'exists'
Traceback (most recent call last):
File "C:\Users/gianl/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\pgversion\pgVersion.py", line 289, in doInit
if not self.tools.check_PGVS_revision(myDb):
File "C:\Users/gianl/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\pgversion\pgVersionTools.py", line 447, in check_PGVS_revision
if not myDb.exists('table', 'versions.version_tables'):
AttributeError: 'NoneType' object has no attribute 'exists'

Python version: 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
QGIS version: 3.28.7-Firenze Firenze, fedae0eb52

Python Path:
C:/PROGRA1/QGIS321.7/apps/qgis-ltr/./python
C:/Users/gianl/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/gianl/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/PROGRA1/QGIS321.7/apps/qgis-ltr/./python/plugins
C:\PROGRA1\QGIS321.7\apps\grass\grass82\etc\python
C:\Users\gianl\Documents
C:\Program Files\QGIS 3.28.7\bin\python39.zip
C:\PROGRA1\QGIS321.7\apps\Python39\DLLs
C:\PROGRA1\QGIS321.7\apps\Python39\lib
C:\Program Files\QGIS 3.28.7\bin
C:\PROGRA1\QGIS321.7\apps\Python39
C:\PROGRA1\QGIS321.7\apps\Python39\lib\site-packages
C:\PROGRA1\QGIS321.7\apps\Python39\lib\site-packages\win32
C:\PROGRA1\QGIS321.7\apps\Python39\lib\site-packages\win32\lib
C:\PROGRA1\QGIS321.7\apps\Python39\lib\site-packages\Pythonwin
C:/Users/gianl/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:\Users\gianl\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\HCMGIS/forms
C:\Users\gianl\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\milstd2525\extlibs
.
C:\Users\gianl\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\SentinelHub\external\oauthlib-3.1.0-py2.py3-none-any.whl
C:\Users\gianl\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\SentinelHub\external\requests_oauthlib-1.3.0-py2.py3-none-any.whl
C:/Users/gianl/Work/Parabellum/ACUGIS/developer/geo/contemporary

Any ideas?

pgvsinit type error

On the way to make some tests with pgversion (master), the following error occured, but no on all layers:


DB-Error

ERREUR: l'opérateur n'existe pas : text + integer
LINE 5: ... MAXVALUE 9223372036854775807 START '||testRec.max+1||' CACH...

In english, that would be translated as "operator does not exist: text + integer" what indicates a type issue.

@hdus : should I fix that with an explicit cast ?

Error in pgvslogview()

I get an error when I click on "show logs" in the QGIS Plugin:

Python error console in QGIS:

 line 597, in doLogView
              for i in range(len(result["PROJECT"])):
             TypeError: 'NoneType' object is not subscriptable

So the result object is None. The result object is generated by executing following statement:

 sql = "select * from versions.pgvslogview('" + mySchema + "." + myTable.replace(
                '_version', '') + "') order by revision desc"
            result,  error = myDb.read(sql)

In the python console in QGIS I get following message:

invalid input syntax for type timestamp: "initial commit revision 0"
CONTEXT:  PL/pgSQL function versions.pgvslogview(character varying) line 37 at FOR over EXECUTE statement

So apparently the error is throwing by executing the function pgvslogview() in the following section:

 for logs IN  EXECUTE logViewQry
    LOOP

      return next logs;    
    end loop;   

What am I doing wrong or is something misconfigured?

Error on edit conflict

Hi, I'm new to pgVersion and am testing it for suitability for a project. Apologies if I've configured something wrong, but I've followed the steps several times, including the bigint handling, and when trying to create a conflict between 2 users (to test how this is handled), keep getting:
File "C:/Users/test/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\pgversion\pgVersion.py", line 409, in doCommit confRecords = self.tools.confRecords(theLayer) File "C:/Users/test/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\pgversion\pgVersionTools.py", line 263, in confRecords if check["COUNT"][0] is not 0: TypeError: 'NoneType' object is not subscriptable

I've tested on several versions of QGIS 3 and a few version of PostGRES + PostGIS.

All other functionality seems to be working, just not this section of code for conflict handling.

Error on schema creation

Error when running create_pgversion_schema

psql:create_pgversion_schema.sql:1858: ERROR:  syntax error at or near "CREATE"
LINE 3: CREATE FUNCTION versions.pgvsmakebranch (IN in_table charact...
        ^
psql:create_pgversion_schema.sql:1860: ERROR:  function versions.pgvsmakebranch(character varying, character varying) does not exist

Looks like a missing semicolon on line 1814

When enabled, every layer pops up a credentials dialog for every layer

If I enable this plugin, ever lay for every project on opening pops up first an "Enter Credentials" dialog and then for each and every layer, even ones that are SHP or GeoJSON files on disk, an error dialog about "no database connection established". That error dialog happens regardless of whether or not I enter any credentials. (See attachments for images.)

After project load on doing edit operations on any layer, the error dialog also appears, on roughly about 3 our of 5 times but not in a seemingly predictable manner. It will happen on every edit one session, then every other edit next session, then only once on a third session, and then back to every edit in a fourth session.

image

image

QGIS-Authentification credentials asked multiple times when using the plugin

Hello!
I come back on issue #3, because we see the same behavior and there was no solution provided in the ticket. We use the plugin version 3.1.1 installed via the qgis plugin mechanism.
We use normaly authentification with master password in QGIS and several database connections. So no question for credentials should occur. When opening a project with the running pgversion plugin for every layer an authentification dialog appears, multiple times for the same database and/or layer.
We see this behavior since QGIS-Version 3.6/8 and on several openSuse and Ubuntu distributions.

"ERROR: query string argument of EXECUTE is null" when the table is empty

If i try to initialize the versioning on an empty table the following error occurs:

`
select * from versions.pgvsinit('ne_1808.testtable');

ERROR: query string argument of EXECUTE is null
CONTEXT: PL/pgSQL function versions.pgvsinit(character varying) line 147 at EXECUTE
SQL state: 22004`

When i create content in QGIS, the initialization work as expected.
Question: Is this the intended behavior? For me, it would make more sense when a table can be versioned before content is put in, but i may be wrong with this. If this is intended, maybe a more readable message would be useful, especialliy in the QGIS-Plugin, which is often used by people with no database-knowledge.

best regards
Uwe Seher

Error Message

So this might not be an issue that is within your scope for this product but maybe you can tell me what the error means...
So I used this on a simple postgis layer with no issues. PostgreSQL 9.6 PostGIS2.3.2 so I decided to try an use it on a larger more complicated database, well to me anyway. The database has main tables and many views with triggers and rules all defined. If you want to build an exact replica of this database just download giswater and create a sample database using the drainage model.
Anyway when I try to version layers in this database I get.
image
Anyway if you can help great, if not I understand; great tool even if it doesn't work with this database, I have many other layers to use it on.
Tyler

Fails to initialize

I click on "Prepare Layer for Versioning",
then I say OK to:
"Do you want to create the version environment for the table test.heritageinterest?"
I get a (error) dialog box with the Initialisation error below (-----------------------).
From what I can see the view, "versions.test_heritageinterest_version_log" is not being created beforehand.
I am running PostgreSQL 15. Here is the result of SELECT postgis_full_version();
"POSTGIS=""3.3.2 3.3.2"" [EXTENSION] PGSQL=""150"" GEOS=""3.11.1-CAPI-1.17.1"" PROJ=""7.2.1"" LIBXML=""2.9.9"" LIBJSON=""0.12"" LIBPROTOBUF=""1.2.1"" WAGYU=""0.5.0 (Internal)"""

Initialisation of table test.heritageinterest failed!

Error:
column v2.id does not exist
LINE 6: ... versions.test_heritageinterest_version_log v2 ON v2.id=v1.i...
^
QUERY: create or replace view test.heritageinterest_version_time as
SELECT row_number() OVER () AS rownum,
to_timestamp(v1.systime/1000)::timestamp without time zone as start_time,
to_timestamp(v2.systime/1000)::timestamp without time zone as end_time ,v1.wkb_geometry,v1.objectid,v1.name,v1.address,v1.email,v1.shape_leng,v1.shape_area,v1.chair,v1.phone,v1.contact,v1.contemail,v1.contphone
FROM versions.test_heritageinterest_version_log v1
LEFT JOIN versions.test_heritageinterest_version_log v2 ON v2.id=v1.id AND v2.action='delete'
WHERE v1.action='insert'
CONTEXT: PL/pgSQL function versions.pgvsinit(character varying) line 214 at EXECUTE

ModuleNotFoundError 'pgversion.dbtools.dbtools'

Hello!
After installation of QGIS plugin from repository I get an error
ModuleNotFoundError: No module named 'pgversion.dbtools.dbtools'
And the plugin doesn't load. What can be the reason?
I am using QGIS 3.4.13

Step to git

Hi, I think this is a great project, and would be very useful to implement this others git features:

  • Remove commit merged in master (I think this is the most important feature in the list, thinking in the already implemented functions)
  • Branches
  • Save current state, not just in memory
  • Branches/State per user

What do you think?

Thx.

Error while upgrading from 1.8.1

I have a previus version installed (1.8.1). When I try to upgrade the following message appears:

The Plugin expects pgvs revision 2.1.8 but DB-functions of revision 1.8.1 are installed. 
Please contact your DB-administrator to upgrade the DB-functions from the file:

C:/Users/andres.pino/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\pgversion/docs/upgrade_pgversion_schema-2.8.1.sql

If you have appropriate DB permissions you can update the DB directly with click on DB-Update.

image

But "upgrade_pgversion_schema-2.8.1.sql" file doesn't exist in docs folder.

No id sequence for view after versioning

Am i missing something?
After successful preparing a layer for versioning, there is no nextval(id_seq) for the (with "load versioned layer" button in qgis plugin) imported view (

_version).

Postgres 9.6.11, qgis 3.22.7, pgversion plugin 3.1.3

ERROR: Role »versions« already exists / FEHLER: Rolle »versions« existiert bereits

The newest version of the qgis plugin seems to have a problem in "create_pgversion_schema.sql". It's correct in github. Tested with qgis 3.22.7 and pgversion 3.1.3

CREATE ROLE versions WITH
INHERIT
ENCRYPTED PASSWORD '********';

appears two times in the plugin. In github the second is commented out. Same is for create table. There are maybe more typos.
I copied the version from github and it runs properly.

(i had more problems when tables are added, the plugin raises python errors, maybe unrelated, seems to have something to do with credentials, not sure)

Error loading plugin in QGIS master

After loading the plugin from plugin manager:

Couldn't load plugin 'pgversion' due to an error when calling its classFactory() method 

ValueError: PyCapsule_GetPointer called with incorrect name 
Traceback (most recent call last):
  File "/home/ale/dev/QGIS/build-local-qt5152-release_gdal3/output/python/qgis/utils.py", line 335, in _startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "/home/ale/.local/share/QGIS/QGIS3/profiles/default/python/plugins/pgversion/__init__.py", line 23, in classFactory
    from .pgVersion import PgVersion
  File "/home/ale/dev/QGIS/build-local-qt5152-release_gdal3/output/python/qgis/utils.py", line 798, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/ale/.local/share/QGIS/QGIS3/profiles/default/python/plugins/pgversion/pgVersion.py", line 30, in 
    from .forms.help import HelpDialog
  File "/home/ale/dev/QGIS/build-local-qt5152-release_gdal3/output/python/qgis/utils.py", line 798, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/ale/.local/share/QGIS/QGIS3/profiles/default/python/plugins/pgversion/forms/help.py", line 28, in 
    FORM_CLASS, _ = uic.loadUiType(os.path.join(
  File "/home/ale/dev/QGIS/build-local-qt5152-release_gdal3/output/python/qgis/PyQt/uic/__init__.py", line 36, in __loadUiType
    return __PyQtLoadUiType(*args, **kwargs)
  File "/home/ale/local5_15_2_release_gdal3/lib/python3/dist-packages/PyQt5/uic/__init__.py", line 204, in loadUiType
    exec(code_string.getvalue(), ui_globals)
  File "", line 21, in 
  File "/home/ale/dev/QGIS/build-local-qt5152-release_gdal3/output/python/qgis/utils.py", line 798, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ValueError: PyCapsule_GetPointer called with incorrect name


Python version: 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0] 
QGIS version: 3.17.0-Master Master, 52e8c5bf2e 

"9999-01-01 00:00:00" - Problem with date in Initialisation

Hello !
Thanks for your work on this useful plugin !!
I have a problem when I try to initialise the versioning for a layer (prepare layer for versioning) :

Error:
syntax error at or near "9999"
LINE 5: '9999-01-01 00:00:00'::timestamp ...
^
QUERY: 'create or replace view '||versionView||'_time as
SELECT row_number() OVER () AS rownum,
to_timestamp(v1.systime/1000)::TIMESTAMP WITHOUT TIME ZONE as start_time,
CASE WHEN v2.systime IS NULL THEN
'9999-01-01 00:00:00'::timestamp WITHOUT TIME ZONE
else
to_timestamp(v2.systime/1000)::TIMESTAMP WITHOUT TIME ZONE
END as end_time,
v1.*
FROM '||versionLogTable||' v1
LEFT JOIN '||versionLogTable||' v2 ON v2.'||myPkey||'=v1.'||myPkey||' AND v2.action=''delete'' and v1.revision <> v2.revision
WHERE (v1.action=''insert'' or v1.action = ''update'') and v1.commit = True'
CONTEXT: PL/pgSQL function versions.pgvsinit(character varying) line 214 at EXECUTE

I am using QGIS 3.28 on Windows 10 with the latest version of PostgreSQL alongside with PostGIS. I am a bit lost on how I can resolve this issue. Did someone went through that or has a solution ?
Tell me if you need any more info
Thanks !

Swapped User and Log-Message in LogView

QGIS 3.10
PgVersion 3.1.0
Postgres 10.10

Currently the user entries are in the column "Log-Message" and the log-message entries in the column "User":

image

Looks like swapping the keys "PROJECT" and "LOGMSG" in line 600+601 and 633+634 in pgVersion.py solves the issue.

If layer URI's aren't usable by plugin, plugin has laggy errors

In my project, the plugin is unable to create a connection based on the URI's of the layers in the legend. (I don't know why yet, when I do I will make a ticket.)

When the Plugin can't create the connection, it can be very bad for the user, because every click on a legend layer results in a plugin error. Since the plugin error involves trying and failing to run a query, it is also a laggy error. The behavior could be more safe in this state.

I made a pull request with a suggested fix.

Error when trying to prepare a Layer for versioning or load versioned layers

When i try to prepare a layer in QQIS or when i try to load a versioned Layer i get the following errormessage;

Traceback (most recent call last):
  File "/home/useher/.qgis2/python/plugins/pgversion/forms/Ui_pgLoadVersion.py", line 123, in on_cmbServer_currentIndexChanged
    self.initDB(p0)
  File "/home/useher/.qgis2/python/plugins/pgversion/forms/Ui_pgLoadVersion.py", line 79, in initDB
    if not self.tools.check_PGVS_revision(myDb):
  File "/home/useher/.qgis2/python/plugins/pgversion/pgVersionTools.py", line 427, in check_PGVS_revision
    db_major_revision = result["PGVSREVISION"][0].split('.')[1]
IndexError: list index out of range

When i prepare it in postgres with the same user and load the Layer via dbmanagerthe other functions work.

The version is 2.1.35, pg-version is 9.6.x, QGIS is 2.18.16

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.