Skip to content

Commit

Permalink
[FEATURE] Add role logging for PostGIS versioning.
Browse files Browse the repository at this point in the history
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 31ab103
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Expand Up @@ -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>
Expand Down Expand Up @@ -183,6 +200,7 @@
<tabstop>editPkey</tabstop>
<tabstop>editStart</tabstop>
<tabstop>editEnd</tabstop>
<tabstop>editUser</tabstop>
<tabstop>txtSql</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
Expand Down
Expand Up @@ -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()

Expand Down Expand Up @@ -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()]

Expand Down Expand Up @@ -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);" % (
Expand Down Expand Up @@ -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;
Expand All @@ -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

Expand Down

0 comments on commit 31ab103

Please sign in to comment.