-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(task): Add init taskDB #7572
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,12 @@ import ( | |
| ) | ||
|
|
||
| func Init() { | ||
| InitAgentDB() | ||
| InitTaskDB() | ||
| global.LOG.Info("Migration run successfully") | ||
| } | ||
|
|
||
| func InitAgentDB() { | ||
| m := gormigrate.New(global.DB, gormigrate.DefaultOptions, []*gormigrate.Migration{ | ||
| migrations.AddTable, | ||
| migrations.AddMonitorTable, | ||
|
|
@@ -20,5 +26,14 @@ func Init() { | |
| global.LOG.Error(err) | ||
| panic(err) | ||
| } | ||
| global.LOG.Info("Migration run successfully") | ||
| } | ||
|
|
||
| func InitTaskDB() { | ||
| m := gormigrate.New(global.TaskDB, gormigrate.DefaultOptions, []*gormigrate.Migration{ | ||
| migrations.AddTaskTable, | ||
| }) | ||
| if err := m.Migrate(); err != nil { | ||
| global.LOG.Error(err) | ||
| panic(err) | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above code is from a Go backend application that seems to be related to database management and migration tasks. It appears to define functions Here's my understanding of this code:
To summarize, you shouldn't change or optimize these commented-out codes until there is documentation explaining what each section does within context! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,3 +217,12 @@ var InitPHPExtensions = &gormigrate.Migration{ | |
| return nil | ||
| }, | ||
| } | ||
|
|
||
| var AddTaskTable = &gormigrate.Migration{ | ||
| ID: "20241226-add-task", | ||
| Migrate: func(tx *gorm.DB) error { | ||
| return tx.AutoMigrate( | ||
| &model.Task{}, | ||
| ) | ||
| }, | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following code has various differences between 2021 and 2024:
Potential issues: These changes might cause a mismatch of functionality when compared to the previous versions. The presence or absence (or different implementation details) of certain functions in these migrations can impact how they work. Optimization suggestions could be:
Remember not to include 'AddTaskTable' and other irrelevant comments. |
||
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 code you provided is from an implementation of Docker Container Service. There doesn't seem to be any issues mentioned in the comments about irregularities, potential issues or opportunities for optimization. The usage makes sense based on docker's commands such as
container logswhich are part of standard operations performed by docker containers.However, there could still be some room to improve readability and simplicity through better naming conventions, more descriptive docstrings, etc., especially when dealing with complex use cases.
For example:
Change
-command := exec.Command(commandName, commandArg...) // this can lead to unexpected behaviorto
cmd := &exec.Cmd{ ... }In general it would be beneficial if someone looking at the code has a thorough understanding of how the function works first before diving into detailed optimizations/coding standards adjustments.
Also consider refactoring functions like downloading logs to handle other types of data like images, networks etc., depending upon application requirements: