-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(be): migration 2.8.26 for postgres
- Loading branch information
Showing
12 changed files
with
110 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package migrations | ||
package bolt | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package sql | ||
|
||
import ( | ||
"github.com/go-gorp/gorp/v3" | ||
"strings" | ||
) | ||
|
||
type Migration_2_8_26 struct { | ||
DB *SqlDb | ||
} | ||
|
||
func (m Migration_2_8_26) Apply(tx *gorp.Transaction) error { | ||
rows, err := tx.Query(m.DB.PrepareQuery("SELECT id, git_url FROM project__repository")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
repoUrls := make(map[string]string) | ||
|
||
for rows.Next() { | ||
var id, url string | ||
|
||
err3 := rows.Scan(&id, &url) | ||
if err3 != nil { | ||
continue | ||
} | ||
|
||
repoUrls[id] = url | ||
} | ||
|
||
err = rows.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for id, url := range repoUrls { | ||
branch := "master" | ||
parts := strings.Split(url, "#") | ||
if len(parts) > 1 { | ||
url, branch = parts[0], parts[1] | ||
} | ||
q := m.DB.PrepareQuery("UPDATE project__repository " + | ||
"SET git_url = ?, git_branch = ? " + | ||
"WHERE id = ?") | ||
_, err = tx.Exec(q, url, branch, id) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
delete | ||
from project__schedule | ||
where template_id is null; | ||
|
||
delete | ||
from project__schedule | ||
where (select count(*) from project__template where project__template.id = project__schedule.template_id) = 0; | ||
|
||
delete | ||
from project__schedule | ||
where (select count(*) from project where project.id = project__schedule.project_id) = 0; | ||
|
||
update project__schedule | ||
set repository_id = null | ||
where repository_id is not null | ||
and (select count(*) from project__repository where project__repository.id = project__schedule.repository_id) = 0; | ||
|
||
alter table `project__schedule` | ||
rename to `project__schedule_backup_8436583`; | ||
|
||
create table project__schedule | ||
( | ||
id integer primary key autoincrement, | ||
template_id int not null, | ||
project_id int not null, | ||
cron_format varchar(255) not null, | ||
repository_id int null, | ||
last_commit_hash varchar(40) null, | ||
|
||
foreign key (`template_id`) references project__template(`id`) on delete cascade, | ||
foreign key (`project_id`) references project(`id`) on delete cascade, | ||
foreign key (`repository_id`) references project__repository(`id`) | ||
); | ||
|
||
insert into project__schedule | ||
select * | ||
from project__schedule_backup_8436583; | ||
|
||
drop table project__schedule_backup_8436583; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters