-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
22827 - Add sql-versioning library and versioning switching logic #3024
Conversation
|
GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
---|---|---|---|---|---|
9442085 | Triggered | Generic Password | 685ee7a | python/common/sql-versioning/tests/docker-compose.yml | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
6ecd529
to
3d154e6
Compare
@@ -20,7 +20,6 @@ | |||
class CorpType(db.Model): # pylint: disable=too-many-instance-attributes | |||
"""This class manages the corp type.""" | |||
|
|||
__versioned__ = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does corp_type
have version table? I don't find it so I remove its old versioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# make_versioned(user_cls=None, plugins=[FlaskPlugin()]) | ||
make_versioned(user_cls=None) | ||
|
||
class Transaction(db.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce custom Transaction
model to solve FK related issues between filings
and transaction
tables when we completely remove old versioning and only new versioning exists. Put it in db.py file for now to avoid the import issue when starting up the flask app.
I make old and new versionings use this custom model to make sure there's no conflicts when both of them exist in the code, though they have their own transaction model. And the removal of old versioning will be clean in the future and the core logic of new versioning won't be touched then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if I need to split this into multiple files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine as one file I think
if not _is_session_modified(session): | ||
print('\033[31mThere is no modified object in this session.\033[0m') | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is updated after the experimental code to make sure that no new transaction entry will be created if the versioned object is not "actually" modified..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test postgres db container will be started automatically during testing.
"db-versioning": { | ||
"legal-api": false, | ||
"emailer": false, | ||
"filer": false, | ||
"entity-bn": false, | ||
"digital-credentials": false, | ||
"dissolutions-job": false, | ||
"furnishings-job": false, | ||
"emailer-reminder-job": false, | ||
"future-effective-job": false, | ||
"update-colin-filings-job": false, | ||
"update-legal-filings-job": false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have this flag setup for each environment in LD already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, and the related setup_versioning()
function is commented out so there's no impact. But I'll set them up now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. The flag is off for all env.
Current on
value:
{
"legal-api": false,
"emailer": false,
"filer": false,
"entity-bn": false,
"digital-credentials": false,
"dissolutions-job": false,
"furnishings-job": false,
"emailer-reminder-job": false,
"future-effective-job": false,
"update-colin-filings-job": false,
"update-legal-filings-job": false
}
Current off
value:
{}
# TODO: enable versioning switching | ||
# it should be called before data model initialzed, otherwise, old versioning doesn't work properly | ||
# setup_versioning() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this will be uncommented as a part of the work in #22942 right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can see, looks great!
I may have missed something as the work here is kind of brand new to myself. I'm up to speed now though after going through this PR.
# the following operations should not result in new versioned records for native sqlalchemy session | ||
session.add(user) | ||
session.commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, very thorough to test this scenario too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are great!
Will be a great starting point to verify the versioning library and also if we ever need to add other tests.
I don't believe we have any CI for this and I think that's fine for now.
But can you provide a screenshot of the test results when you run things locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI the test results at local env, and REAME.md has the setup instructions for this work so that anyone can play around it and test it easily. (think I had better update the application name to align with the one in sbc-connect-common repo later).
# git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api | ||
git+https://github.com/chenhongjing/lear.git@22827-sql-versioning#egg=legal_api&subdirectory=legal-api | ||
git+https://github.com/chenhongjing/lear.git@22827-sql-versioning#egg=sql-versioning&subdirectory=python/common/sql-versioning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when we are ready to merge, what do all the queue service requirements files look like?
Will it just be a reference to git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a new dependency - sql-versioning (reference: failed CI), so it will be
git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api
git+https://github.com/bcgov/lear.git#egg=sql-versioning&subdirectory=python/common/sql-versioning
Great work! Will approve once some of the comments I've added have been addressed. Also, think you'll need to rebase as there are some conflicts with |
Signed-off-by: chenhongjing <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving with assumption following will be addressed:
- conflict with
main
- dependencies in
requirements.txt
files will be updated as appropriate
Signed-off-by: chenhongjing <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
Signed-off-by: Hongjing Chen <[email protected]>
2c69570
to
beb7aec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Lots of learning for me going through this
Signed-off-by: Hongjing Chen <[email protected]>
Quality Gate passedIssues Measures |
Issue #: /bcgov/entity#22827
Description of changes:
versioning_manager
andTransaction
modelversioning_manager
uses across componentsNote that
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the lear license (Apache 2.0).