From a6c43d5f574bc8f3b47089bb9925d471bd435fb0 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 2 Jan 2023 15:56:54 -0800 Subject: [PATCH] Change limit on Weapons/Summons to boolean --- ...2160350_migrate_weapon_limit_to_boolean.rb | 17 +++++++++++++++++ ...102161028_migrate_limit_value_to_limit2.rb | 19 +++++++++++++++++++ .../20230102154816_change_limit_to_boolean.rb | 6 ++++++ ...0230102161702_remove_limit_from_weapons.rb | 5 +++++ .../20230102161738_rename_limit2_on_weapon.rb | 5 +++++ ...0230102161820_remove_limit_from_summons.rb | 5 +++++ ...20230102161941_rename_limit2_on_summons.rb | 5 +++++ 7 files changed, 62 insertions(+) create mode 100644 db/data/20230102160350_migrate_weapon_limit_to_boolean.rb create mode 100644 db/data/20230102161028_migrate_limit_value_to_limit2.rb create mode 100644 db/migrate/20230102154816_change_limit_to_boolean.rb create mode 100644 db/migrate/20230102161702_remove_limit_from_weapons.rb create mode 100644 db/migrate/20230102161738_rename_limit2_on_weapon.rb create mode 100644 db/migrate/20230102161820_remove_limit_from_summons.rb create mode 100644 db/migrate/20230102161941_rename_limit2_on_summons.rb diff --git a/db/data/20230102160350_migrate_weapon_limit_to_boolean.rb b/db/data/20230102160350_migrate_weapon_limit_to_boolean.rb new file mode 100644 index 0000000..41b359f --- /dev/null +++ b/db/data/20230102160350_migrate_weapon_limit_to_boolean.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class MigrateLimitToBoolean < ActiveRecord::Migration[6.1] + def up + Weapon.all.each do |weapon| + weapon.limit2 = weapon.limit > 0 + end + + Summon.all.each do |summon| + summon.limit2 = summon.limit > 0 + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/data/20230102161028_migrate_limit_value_to_limit2.rb b/db/data/20230102161028_migrate_limit_value_to_limit2.rb new file mode 100644 index 0000000..1ef4122 --- /dev/null +++ b/db/data/20230102161028_migrate_limit_value_to_limit2.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class MigrateLimitValueToLimit2 < ActiveRecord::Migration[6.1] + def up + Weapon.all.each do |weapon| + weapon.limit2 = !(weapon.limit == 0) + weapon.save + end + + Summon.all.each do |summon| + summon.limit2 = !(summon.limit == 0) + summon.save + end + end + + def down + # raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20230102154816_change_limit_to_boolean.rb b/db/migrate/20230102154816_change_limit_to_boolean.rb new file mode 100644 index 0000000..65c36f5 --- /dev/null +++ b/db/migrate/20230102154816_change_limit_to_boolean.rb @@ -0,0 +1,6 @@ +class ChangeLimitToBoolean < ActiveRecord::Migration[6.1] + def change + add_column :weapons, :limit2, :boolean, default: false, null: false + add_column :summons, :limit2, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20230102161702_remove_limit_from_weapons.rb b/db/migrate/20230102161702_remove_limit_from_weapons.rb new file mode 100644 index 0000000..f8e248c --- /dev/null +++ b/db/migrate/20230102161702_remove_limit_from_weapons.rb @@ -0,0 +1,5 @@ +class RemoveLimitFromWeapons < ActiveRecord::Migration[6.1] + def change + remove_column :weapons, :limit, :integer + end +end diff --git a/db/migrate/20230102161738_rename_limit2_on_weapon.rb b/db/migrate/20230102161738_rename_limit2_on_weapon.rb new file mode 100644 index 0000000..5981c35 --- /dev/null +++ b/db/migrate/20230102161738_rename_limit2_on_weapon.rb @@ -0,0 +1,5 @@ +class RenameLimit2OnWeapon < ActiveRecord::Migration[6.1] + def change + rename_column :weapons, :limit2, :limit + end +end diff --git a/db/migrate/20230102161820_remove_limit_from_summons.rb b/db/migrate/20230102161820_remove_limit_from_summons.rb new file mode 100644 index 0000000..324dc7c --- /dev/null +++ b/db/migrate/20230102161820_remove_limit_from_summons.rb @@ -0,0 +1,5 @@ +class RemoveLimitFromSummons < ActiveRecord::Migration[6.1] + def change + remove_column :summons, :limit, :integer + end +end diff --git a/db/migrate/20230102161941_rename_limit2_on_summons.rb b/db/migrate/20230102161941_rename_limit2_on_summons.rb new file mode 100644 index 0000000..f5478dc --- /dev/null +++ b/db/migrate/20230102161941_rename_limit2_on_summons.rb @@ -0,0 +1,5 @@ +class RenameLimit2OnSummons < ActiveRecord::Migration[6.1] + def change + rename_column :summons, :limit2, :limit + end +end