Skip to content

Commit

Permalink
add size to course schema
Browse files Browse the repository at this point in the history
  • Loading branch information
simonycj committed Jul 30, 2024
1 parent 73afe5d commit 15cb5cf
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 124 deletions.
1 change: 1 addition & 0 deletions pkg/apis/open-hydra-api/course/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type CourseSpec struct {
LastUpdate metav1.Time `json:"lastUpdate"`
Level int `json:"level,omitempty"`
SandboxName string `json:"sandboxName,omitempty"`
Size int64 `json:"size,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (db *Mysql) InitDb() error {
return err
}

_, err = inst.Exec("CREATE TABLE IF NOT EXISTS course ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), description NVARCHAR(255) , created_by NVARCHAR(255) , last_update DATETIME , create_time DATETIME , UNIQUE (name) )")
_, err = inst.Exec("CREATE TABLE IF NOT EXISTS course ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), description NVARCHAR(255) , created_by NVARCHAR(255) , last_update DATETIME , create_time DATETIME , file_size BIGINT , UNIQUE (name) )")
if err != nil {
return err
}
Expand All @@ -257,7 +257,7 @@ func (db *Mysql) CreateCourse(course *xCourseV1.Course) error {
}
course.Spec.LastUpdate = metaV1.Now()
course.CreationTimestamp = metaV1.Now()
result, err := ins.Exec("INSERT INTO course (name, description, created_by, create_time, last_update) VALUES (?, ?, ?, ?, ?)", course.Name, course.Spec.Description, course.Spec.CreatedBy, course.CreationTimestamp.Time, course.Spec.LastUpdate.Time)
result, err := ins.Exec("INSERT INTO course (name, description, created_by, create_time, last_update, file_size) VALUES (?, ?, ?, ?, ?, ?)", course.Name, course.Spec.Description, course.Spec.CreatedBy, course.CreationTimestamp.Time, course.Spec.LastUpdate.Time, course.Spec.Size)
if err != nil {
slog.Error(fmt.Sprintf("Failed to crate course %s into database", course.Name), err)
return err
Expand Down
Loading

0 comments on commit 15cb5cf

Please sign in to comment.