Closed wildtayne closed 6 years ago
Thanks @srrollo for getting these changes started. I see that quite a bit of cross-script coordination is needed to add the desired functionality.
Eyeballing, I have the following observations (will arrive in multiple comments).
addClassDBRolesViewsCore.sql
:
ActivityAtUTC
(character case)addHelpersCore.sql
:
isColumnDefined
.SELECT column_name
instead of SELECT *
RETURNS NULL ON NULL INPUT
to the new helper functionaddUserMgmtCore.sql
:
The following table alterations are needed...
NOT NULL
to the new column ActivityType
NULL
, but rows may already existClassDB.IDNameDomain
is the right type for column ApplicationName
session_id
and session_line_num
form PK, and we import only one line for every session with ActivityType
being different. So it seems fields SessionID
and ActivityType
together do form the PK. Is there any chance we import multiple lines? If not, should the import process be limited to just line 1?NULL
for connection entriesCREATE TABLE
with a brief list of changes made from 2.0 to 2.1
Continuing my observations.
I like to reiterate that these changes are really well coordinated. The number of things that need attention are surprisingly few for the nature of the changes. Thanks @srrollo.
addConnectionActivityLoggingReco.sql
:
log_disconnections
in the IN
listimportConnectionLog
returns numConnections
and numDisconnections
in addition to (or instead of) numEntries
addFrequentViewsReco.sql
:
ActivityType
returned by functions and views be the words Connection
and Disconnection
instead of single letters. I think this because these functions and views are meant for end-user consumption and are likely to be used in reports.ActivityType
use the type VARCHAR
(no size) to eliminate the need to break API compatibility if we decide to change the exact value returned in future.VARCHAR(10)
cannot hold the value Disconnection
. I recommend changing the type to VARCHAR
(no size) to future proof.'DDL'
to 'DDL Query'
UNION
query can be just one query over getUserConnectionActivity
, using a CASE
expression in SELECT
getUserActivity
, I believe table DDLActivity
should include session id. See new issue #237I have not reviewed the test scripts. I will review them in the next cycle when hopefully PR #214 will already be merged and we can easily spot the new content.
Thanks for the great feedback @smurthys. I agree with and will implement most of these changes. Some thoughts:
Sidenote: it looks like I may need toerge dev into this locally to correct the diff - it still shows changes for #214 as well
Good point @srrollo about the trouble with making (SessionID, ActivityType)
the PK in table ConnectionActivity
. This issue can be addressed using a partial index to enforce uniqueness only on new rows. The following query should do:
CREATE UNIQUE INDEX IF NOT EXISTS idx_SessionID_ActivityType
ON ClassDB.ConnectionActivity(SessionID,ActivityType)
WHERE SessionID <> '00000000.00000000'
Here is the pseudo-code I recommend to upgrade table ConnectionActivity
from 2.0 to 2.1:
ConnectionActivity
is not empty
ALTER
statements used so far are idempotent)ConnectionActivity
is empty, drop the tableConnectionActivity
if it does not exist as is done so far in this PR. In the CREATE
query make (SessionID, ActivityType)
the PKI have not yet pushed any new changes to this branch, however I think I have successfully merged in external changes. The diff should be correct now.
OK, I've pushed some new commits that improve disconnection logging based on the feedback from @smurthys. I've made all changes pointed out. A summary of changes that deviated a bit:
addUserMgmtCore.sql
ClassDB.ConnectionActivity
ClassDB.ConnectionActivity
exists. I think then checking if it is empty requires a nested IF
. I tried to do:
IF ClassDB.isColumnDefined('ClassDB', 'ConnectionActivity', 'UserName')
AND EXISTS (SELECT * FROM ClassDB.ConnectionActivity)
addFrequentViews.sql
CASE
changing C/D
to Connection/Disconnection
in getUserConnectionActivity()
, since that will cascade to all functions/views that get connection activity.Thanks @srrollo for the revision. These changes add large value to the product's feature and quality.
Here are some observations in addUserMgmtCore.sql
. I will add another comment if I have observations to share in other scripts:
ConnectionActivity
existsCREATE OR REPLACE TABLE
. Our goals should be:
SessionID
that is meant to patch existing rows, but ends up permitting an INSERT
that omits value for SessionID
, which in turn goes unnoticed due to the partial indexI suggest the following code structure to meet the aforementioned goals. A downside with this approach is that dropping an empty table and re-creating it gives the table a new oid, but that is not an issue because this is an installation script: not a patch script. Also, thus far, our assumption is that all relevant scripts will be (re)run in any installation, and that is possible due to the idempotent nature of our scripts.
IF table exists THEN
IF table empty THEN
DROP TABLE
ELSE
upgrade 2.0 to 2.1-- a temp function already created
END IF
END IF
CREATE OR REPLACE TABLE...
ALTER ownership
REVOKE from public
GRANT SELECT ...
I have the following observations in addConnectionActivityLoggingReco.sql
:
Returns
and just say #of connections imported for the log date
disconnections
Thanks for the feedback on the upgrade code. I've updated it to reflect the suggested layout. The one change I had to make was dropping the user views ClassDB.Student, ClassDB.Instructor, etc.
because they all depend on ClassDB.ConnectionActivity
. This is OK if the user is running one of the addAll
scripts, but I suppose could cause an issue if running addUserMgmtCore.sql
on its own.
I've added a WARNING
about dropping the user views, however I'm not sure if this is sufficient, since it gets buried when running an install all script (especially addAllToDB.psql
).
Hmm. I didn't think about dependencies. I am thinking about it now and will comment again in a few minutes.
Thanks again to @srrollo for mentioning the cascading effect of dropping ConnectionActivity
during upgrade.
I have thought about this issue and feel this is a good opportunity to learn and practice dealing with likely upgrade issues. Because I caused a bit of extra effort for @srrollo, I took the responsibility to change the upgrade to make it provide the best result for the schema/data that exists when the script is run.
I just pushed the following changes. I have verified these changes produce the desired result with this branch:
Please review.
Thanks for the changes @smurthys. I think think this makes each possible version of ClassDB.ConnectionActivity
as close as possible.
Just pushed spelling corrections and some minor edits to comments in addUserMgmtCore.sql
.
BTW, this is the first time I used ALTER TABLE ... ADD PRIMARY KEY
. It is really neat how a unique index just becomes a PK. Watching the before and after changes in pgAdmin is quite satisfying. 🤓
Thanks for the catch @afig , I added the client_min_messages supression
This PR adds disconnection logging, as well as logging of
SessionID
andApplicationName
. It also updates some core objects that are broken by changes toClassDB.ConnectionActivity
ClassDB.importConnectionLog()
adds rows withActivityType
D
for disconnectionsClassDB.ConnectionActivity
has had attributes added to hold the new log informationClassDB.ConnectionActivity
has been addedClassDB.User
has been updated for compatibility with updatedClassDB.ConnectionActivity
(but it does not display any new info)ClassDB.isColumnDefined()
is added, because there is no way to conditionally rename a column (need to check if it exists first)addFrequentViewsReco.sql
have been updated to work with disconnection logginggetActivity
functions and views return rows related to disconnection logging. Activity summaries currently don't return any info related to disconnections because they draw fromClassDB.User
which does not expose this information.This PR should not be reviewed yet; I am uploading it to get some initial feedback on these solutions. Additionally, this PR will show some additional changes until #214 is merged, because it is branched from that.
I would like to get feedback on the new schema for
ClassDB.ConnectionActivity
. When we are happy with it, I will update the conceptual schema and add it to this PR.I plan on updating the activity views in a separate PR. Currently, most views inI accidentally added the views fixes to this branch, so I guess they will live here.addFrequentViewsReco.sql
will be broken after merging this PR.Closes: #163, #206