Skip to content
Permalink
Browse files

[FEATURE] Add role logging for PostGIS versioning.

Add new column in PostGIS versioning plugin SQL.
Add SQL logic for functions and triggers.
Add new QLineEdit for column name.
  • Loading branch information
merkato committed May 29, 2017
1 parent 12ed31b commit 31ab10322e5e083b26421740c6ee1290a799ffad
@@ -136,6 +136,23 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>User role</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="editUser">
<property name="text">
<string>time_end</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -183,6 +200,7 @@
<tabstop>editPkey</tabstop>
<tabstop>editStart</tabstop>
<tabstop>editEnd</tabstop>
<tabstop>editUser</tabstop>
<tabstop>txtSql</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
@@ -61,6 +61,7 @@ def __init__(self, item, parent=None):
self.editPkey.textChanged.connect(self.updateSql)
self.editStart.textChanged.connect(self.updateSql)
self.editEnd.textChanged.connect(self.updateSql)
self.editUser.textChanged.connect(self.updateSql)

self.updateSql()

@@ -114,6 +115,7 @@ def updateSql(self):
self.colPkey = self.db.connector.quoteId(self.editPkey.text())
self.colStart = self.db.connector.quoteId(self.editStart.text())
self.colEnd = self.db.connector.quoteId(self.editEnd.text())
self.colUser = self.db.connector.quoteId(self.editUser.text())

self.columns = [self.db.connector.quoteId(x.name) for x in self.table.fields()]

@@ -173,8 +175,8 @@ def showHelp(self):
QMessageBox.information(self, "Help", helpText)

def sql_alterTable(self):
return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp, ADD %s timestamp;" % (
self.schematable, self.colPkey, self.colStart, self.colEnd)
return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp, ADD %s timestamp, ADD %s varchar;" % (
self.schematable, self.colPkey, self.colStart, self.colEnd, self.colUser)

def sql_setPkey(self):
return u"ALTER TABLE %s DROP CONSTRAINT %s, ADD PRIMARY KEY (%s);" % (
@@ -209,6 +211,7 @@ def sql_functions(self):
IF NEW.%(end)s IS NULL THEN
INSERT INTO %(schematable)s (%(cols)s, %(start)s, %(end)s) VALUES (%(oldcols)s, OLD.%(start)s, current_timestamp);
NEW.%(start)s = current_timestamp;
NEW.%(user)s = current_user;
END IF;
RETURN NEW;
END;
@@ -222,12 +225,13 @@ def sql_functions(self):
if NEW.%(start)s IS NULL then
NEW.%(start)s = now();
NEW.%(end)s = null;
NEW.%(user)s = current_user;
end if;
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';""" % {'view': self.view, 'schematable': self.schematable, 'cols': cols, 'oldcols': old_cols,
'start': self.colStart, 'end': self.colEnd, 'func_at_time': self.func_at_time,
'start': self.colStart, 'end': self.colEnd, 'user': self.colUser, 'func_at_time': self.func_at_time,
'func_update': self.func_update, 'func_insert': self.func_insert}
return sql

0 comments on commit 31ab103

Please sign in to comment.
You can’t perform that action at this time.