fix(be): schedule migration

This commit is contained in:
Denis Gukov 2021-09-06 17:55:26 +05:00
parent 0b5998274d
commit ebbea98248
4 changed files with 15 additions and 9 deletions

View File

@ -25,7 +25,7 @@ var tablesShouldBeTruncated = [...]string {
"project__inventory", "project__inventory",
"project__repository", "project__repository",
"project__template", "project__template",
"project__template_schedule", "project__schedule",
"project__user", "project__user",
"user", "user",
} }

View File

@ -1,3 +1,9 @@
alter table project__template_schedule rename to project__schedule; drop table project__template_schedule;
alter table `project__schedule` add `id` integer primary key autoincrement;
alter table `project__schedule` add `project_id` int not null references project(`id`); create table `project__schedule`
(
`id` integer primary key autoincrement,
`template_id` int references project__template (`id`) on delete cascade,
`project_id` int not null references project (`id`) on delete cascade,
`cron_format` varchar(255) not null
);

View File

@ -53,13 +53,13 @@ func (d *SqlDb) DeleteSchedule(projectID int, scheduleID int) error {
} }
func (d *SqlDb) GetSchedules() (schedules []db.Schedule, err error) { func (d *SqlDb) GetSchedules() (schedules []db.Schedule, err error) {
_, err = d.selectAll(&schedules, "select * from project__template_schedule where cron_format != ''") _, err = d.selectAll(&schedules, "select * from project__schedule where cron_format != ''")
return return
} }
func (d *SqlDb) GetTemplateSchedules(projectID int, templateID int) (schedules []db.Schedule, err error) { func (d *SqlDb) GetTemplateSchedules(projectID int, templateID int) (schedules []db.Schedule, err error) {
_, err = d.selectAll(&schedules, _, err = d.selectAll(&schedules,
"select * from project__template_schedule where project_id=? and template_id=?", "select * from project__schedule where project_id=? and template_id=?",
projectID, projectID,
templateID) templateID)
return return

View File

@ -55,20 +55,20 @@ func (d *SqlDb) UpdateTemplate(template db.Template) error {
// //
//if template.CronFormat == "" { //if template.CronFormat == "" {
// _, err = d.exec( // _, err = d.exec(
// "delete from project__template_schedule where project_id =? and template_id=?", // "delete from project__schedule where project_id =? and template_id=?",
// template.ProjectID, // template.ProjectID,
// template.ID) // template.ID)
//} else { //} else {
// _, err = d.GetTemplateSchedules(template.ProjectID, template.ID) // _, err = d.GetTemplateSchedules(template.ProjectID, template.ID)
// if err == nil { // if err == nil {
// _, err = d.exec( // _, err = d.exec(
// "update project__template_schedule set cron_format=? where project_id =? and template_id=?", // "update project__schedule set cron_format=? where project_id =? and template_id=?",
// template.CronFormat, // template.CronFormat,
// template.ProjectID, // template.ProjectID,
// template.ID) // template.ID)
// } else if err == db.ErrNotFound { // } else if err == db.ErrNotFound {
// _, err = d.exec( // _, err = d.exec(
// "insert into project__template_schedule (template_id, cron_format) values (?, ?)", // "insert into project__schedule (template_id, cron_format) values (?, ?)",
// template.ID, // template.ID,
// template.CronFormat) // template.CronFormat)
// } // }