DASSL / ClassDB

An open-source system to let students experiment with relational data
https://dassl.github.io/ClassDB/
Other
7 stars 2 forks source link

Add disconnection logging #235

Closed wildtayne closed 6 years ago

wildtayne commented 6 years ago

This PR adds disconnection logging, as well as logging of SessionID and ApplicationName. It also updates some core objects that are broken by changes to ClassDB.ConnectionActivity

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 in addFrequentViewsReco.sql will be broken after merging this PR. I accidentally added the views fixes to this branch, so I guess they will live here.

Closes: #163, #206

smurthys commented 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:

addHelpersCore.sql:

addUserMgmtCore.sql:

smurthys commented 6 years ago

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:

addFrequentViewsReco.sql:

I 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.

wildtayne commented 6 years ago

Thanks for the great feedback @smurthys. I agree with and will implement most of these changes. Some thoughts:

wildtayne commented 6 years ago

Sidenote: it looks like I may need toerge dev into this locally to correct the diff - it still shows changes for #214 as well

smurthys commented 6 years ago

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:

wildtayne commented 6 years ago

I 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.

wildtayne commented 6 years ago

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

addFrequentViews.sql

smurthys commented 6 years ago

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:

I 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 ...
smurthys commented 6 years ago

I have the following observations in addConnectionActivityLoggingReco.sql:

wildtayne commented 6 years ago

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).

smurthys commented 6 years ago

Hmm. I didn't think about dependencies. I am thinking about it now and will comment again in a few minutes.

smurthys commented 6 years ago

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.

wildtayne commented 6 years ago

Thanks for the changes @smurthys. I think think this makes each possible version of ClassDB.ConnectionActivity as close as possible.

smurthys commented 6 years ago

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. 🤓

wildtayne commented 6 years ago

Thanks for the catch @afig , I added the client_min_messages supression