From 67d2cb2061a4c57a5cba1c95ecebe74f3cccb3ec Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 26 Jul 2022 17:53:24 +0200 Subject: [PATCH] chore(schema): add exports#job_status Same behavior as Archive On destroy tous les exports existants qui n'ont pas cette notion de status. --- app/models/export.rb | 2 +- .../20220726151017_add_job_status_to_exports.rb | 7 +++++++ db/schema.rb | 4 ++-- .../deployment/20220726154500_truncate_exports.rake | 13 +++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20220726151017_add_job_status_to_exports.rb create mode 100644 lib/tasks/deployment/20220726154500_truncate_exports.rake diff --git a/app/models/export.rb b/app/models/export.rb index 95c0d57cc..990fa2f42 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -4,7 +4,7 @@ # # id :bigint not null, primary key # format :string not null -# job_status :string +# job_status :string default("pending"), not null # key :text not null # procedure_presentation_snapshot :jsonb # statut :string default("tous") diff --git a/db/migrate/20220726151017_add_job_status_to_exports.rb b/db/migrate/20220726151017_add_job_status_to_exports.rb new file mode 100644 index 000000000..b3ed31062 --- /dev/null +++ b/db/migrate/20220726151017_add_job_status_to_exports.rb @@ -0,0 +1,7 @@ +class AddJobStatusToExports < ActiveRecord::Migration[6.1] + def change + safety_assured do + add_column :exports, :job_status, :string, null: false, default: "pending" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 601109809..c0aae0e42 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_07_18_093034) do +ActiveRecord::Schema.define(version: 2022_07_26_151017) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -431,7 +431,7 @@ ActiveRecord::Schema.define(version: 2022_07_18_093034) do create_table "exports", force: :cascade do |t| t.datetime "created_at", null: false t.string "format", null: false - t.string "job_status" + t.string "job_status", default: "pending", null: false t.text "key", null: false t.bigint "procedure_presentation_id" t.jsonb "procedure_presentation_snapshot" diff --git a/lib/tasks/deployment/20220726154500_truncate_exports.rake b/lib/tasks/deployment/20220726154500_truncate_exports.rake new file mode 100644 index 000000000..ed480237a --- /dev/null +++ b/lib/tasks/deployment/20220726154500_truncate_exports.rake @@ -0,0 +1,13 @@ +namespace :after_party do + desc 'Deployment task: truncate_exports' + task truncate_exports: :environment do + puts "Running deploy task 'truncate_exports'" + + Export.in_batches.destroy_all + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord + .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp + end +end