-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add strict SQL mode to allow d2-cloner to stop execution on error during cloning process #136
base: development
Are you sure you want to change the base?
Conversation
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.
In-line comments:
src/d2_docker/cli.py
Outdated
@@ -80,6 +80,9 @@ def main(): | |||
args = parser.parse_args() | |||
utils.logger.setLevel(args.log_level.upper()) | |||
|
|||
|
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.
extra blank line
src/d2_docker/cli.py
Outdated
@@ -80,6 +80,9 @@ def main(): | |||
args = parser.parse_args() | |||
utils.logger.setLevel(args.log_level.upper()) | |||
|
|||
|
|||
if getattr(args, "strict_sql", False) and not args.run_sql: | |||
parser.error("--strict-sql requires --run-sql to be set") |
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 cannot do args checking of some specific command (start) in the main cli.
The check should be done in the "run" function of start.py.
src/d2_docker/commands/start.py
Outdated
@@ -102,7 +108,8 @@ def start(args): | |||
bind_ip=args.bind_ip, | |||
core_image=core_image, | |||
load_from_data=override_containers, | |||
post_sql_dir=args.run_sql, | |||
post_sql_dir=post_sql_dir, | |||
post_strict_sql_dir=post_strict_sql_dir, |
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.
Instead of passing a new sql_dir
param, we could pass the boolean flag so the script knows if the mode is "strict" or not. This would greatly simplify dhis2-core-start.sh (and support all kind of files, not only sql)
I have added a parameter (dependent on run-sql) and a folder to execute strict SQL scripts on database startup.
When this parameter is used and an SQL statement fails, execution stops immediately, displaying an error message.
This allows d2-cloner to detect the failure and halt the cloning process.
The goal is to ensure that if an SQL script fails during cloning, the instance does not go online with an incomplete execution.
We want to guarantee that either all SQL scripts run successfully or the process stops entirely to ensure that all mandatory rules are correctly applied.
Execution stops at the first error to prevent longer SQL operations from running unnecessarily, making it easier to identify and debug the issue.
I initially attempted to stop the instance and return an error status that d2-cloner could catch, but I couldn't achieve this.
Instead, I opted for logging an error message that d2-cloner can detect to handle the situation accordingly.
Issue:
https://app.clickup.com/t/8697kr4wf
To test you need do a d2-docker start with --run-sql and --strict-sql parameters.