From a817a4d2df571c50020249cf1643f46d222785db Mon Sep 17 00:00:00 2001 From: PeculiarE <75625011+PeculiarE@users.noreply.github.com> Date: Fri, 10 Jun 2022 09:20:15 +0100 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20status=20columns?= =?UTF-8?q?=20to=20maps=20and=20users=20tables=20(#1753)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 🤖 add status columns to maps and users tables * style: 💄 remove extra indentation --- app/controllers/maps_controller.rb | 1 + ...220608115906_add_status_to_users_and_maps.rb | 17 +++++++++++++++++ db/schema.rb | 4 +++- test/controllers/maps_controller_test.rb | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220608115906_add_status_to_users_and_maps.rb diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index f7f7c5f3..6de81021 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -66,6 +66,7 @@ class MapsController < ApplicationController def archive if logged_in? && current_user.can_delete?(@map) @map.archived = true + @map.status = 0 if @map.save flash[:notice] = 'Archived map.' else diff --git a/db/migrate/20220608115906_add_status_to_users_and_maps.rb b/db/migrate/20220608115906_add_status_to_users_and_maps.rb new file mode 100644 index 00000000..9b45cc6f --- /dev/null +++ b/db/migrate/20220608115906_add_status_to_users_and_maps.rb @@ -0,0 +1,17 @@ +class AddStatusToUsersAndMaps < ActiveRecord::Migration[5.2] + class Map < ApplicationRecord + end + + def up + add_column :users, :status, :integer, :default => 1 + add_column :maps, :status, :integer, :default => 1 + + Map.reset_column_information + Map.where(archived: true).update(status: 0) + end + + def down + remove_column :users, :status + remove_column :maps, :status + end +end diff --git a/db/schema.rb b/db/schema.rb index 30846792..a4221b0b 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: 2019_12_19_051509) do +ActiveRecord::Schema.define(version: 2022_06_08_115906) do create_table "annotations", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.integer "map_id" @@ -77,6 +77,7 @@ ActiveRecord::Schema.define(version: 2019_12_19_051509) do t.boolean "anon_annotatable", default: false t.string "slug" t.boolean "display_welcome", default: true + t.integer "status", default: 1 t.index ["author"], name: "index_maps_on_author" t.index ["slug"], name: "index_maps_on_slug", unique: true t.index ["user_id"], name: "index_maps_on_user_id" @@ -122,6 +123,7 @@ ActiveRecord::Schema.define(version: 2019_12_19_051509) do t.datetime "updated_at" t.string "remember_token", limit: 40 t.datetime "remember_token_expires_at" + t.integer "status", default: 1 t.index ["login"], name: "index_users_on_login", unique: true end diff --git a/test/controllers/maps_controller_test.rb b/test/controllers/maps_controller_test.rb index 0da745fe..acd640ec 100644 --- a/test/controllers/maps_controller_test.rb +++ b/test/controllers/maps_controller_test.rb @@ -191,6 +191,7 @@ class MapsControllerTest < ActionController::TestCase assert_redirected_to '/' assert @map.archived + assert_equal 0, @map.status end test 'should not archive map without enough permissions' do @@ -200,6 +201,7 @@ class MapsControllerTest < ActionController::TestCase assert_redirected_to '/' assert_not @map.archived + assert_equal 1, @map.status end test 'should update map' do