From a183c23e25189dae0280304c1c6e6e8ccb7bdc5f Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Wed, 7 Jun 2023 16:49:08 +0200 Subject: [PATCH] Fix truncate call on mysql and provide step 4 migrations for mysql --- internal/repository/job.go | 6 ++++++ .../repository/migrations/mysql/04_alter-table-job.down.sql | 5 +++++ .../repository/migrations/mysql/04_alter-table-job.up.sql | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 internal/repository/migrations/mysql/04_alter-table-job.down.sql create mode 100644 internal/repository/migrations/mysql/04_alter-table-job.up.sql diff --git a/internal/repository/job.go b/internal/repository/job.go index 1e88c43..d470556 100644 --- a/internal/repository/job.go +++ b/internal/repository/job.go @@ -126,6 +126,9 @@ func (r *JobRepository) Flush() error { return err } case "mysql": + if _, err = r.DB.Exec(`SET FOREIGN_KEY_CHECKS = 0`); err != nil { + return err + } if _, err = r.DB.Exec(`TRUNCATE TABLE jobtag`); err != nil { return err } @@ -135,6 +138,9 @@ func (r *JobRepository) Flush() error { if _, err = r.DB.Exec(`TRUNCATE TABLE job`); err != nil { return err } + if _, err = r.DB.Exec(`SET FOREIGN_KEY_CHECKS = 1`); err != nil { + return err + } } return nil diff --git a/internal/repository/migrations/mysql/04_alter-table-job.down.sql b/internal/repository/migrations/mysql/04_alter-table-job.down.sql new file mode 100644 index 0000000..ebc7454 --- /dev/null +++ b/internal/repository/migrations/mysql/04_alter-table-job.down.sql @@ -0,0 +1,5 @@ +ALTER TABLE job + MODIFY `partition` VARCHAR(255) NOT NULL, + MODIFY array_job_id BIGINT NOT NULL, + MODIFY num_hwthreads INT NOT NULL, + MODIFY num_acc INT NOT NULL; diff --git a/internal/repository/migrations/mysql/04_alter-table-job.up.sql b/internal/repository/migrations/mysql/04_alter-table-job.up.sql new file mode 100644 index 0000000..9fe7620 --- /dev/null +++ b/internal/repository/migrations/mysql/04_alter-table-job.up.sql @@ -0,0 +1,5 @@ +ALTER TABLE job + MODIFY `partition` VARCHAR(255), + MODIFY array_job_id BIGINT, + MODIFY num_hwthreads INT, + MODIFY num_acc INT;