From e0ea18a6d055b31227406f801d85c1eae50447a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 28 Apr 2023 21:06:36 +0200 Subject: [PATCH] RVRNEXT-5 migration for main_currency_id --- .../20230428_1826_community_main_currency.php | 19 +++++++++++++++++++ .../20230428_1826_community_main_currency.sql | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 database/migrations/data/20230428_1826_community_main_currency.php create mode 100644 database/migrations/structure/20230428_1826_community_main_currency.sql diff --git a/database/migrations/data/20230428_1826_community_main_currency.php b/database/migrations/data/20230428_1826_community_main_currency.php new file mode 100644 index 0000000..ce679da --- /dev/null +++ b/database/migrations/data/20230428_1826_community_main_currency.php @@ -0,0 +1,19 @@ +selectMultipleFromDb($select, Community::class); + +foreach ($communities as $community) { + $mainCurrency = new Currency(); + $mainCurrency->setCommunity($community); + $mainCurrency->setCode($community->getCurrency()); + $mainCurrency->setRoundDigits(0); + Container::$persistentDataManager->saveToDb($mainCurrency); + + $community->setMainCurrency($mainCurrency); + Container::$persistentDataManager->saveToDb($community); +} diff --git a/database/migrations/structure/20230428_1826_community_main_currency.sql b/database/migrations/structure/20230428_1826_community_main_currency.sql new file mode 100644 index 0000000..a4b5044 --- /dev/null +++ b/database/migrations/structure/20230428_1826_community_main_currency.sql @@ -0,0 +1,4 @@ +ALTER TABLE `communities` +ADD `main_currency_id` int(10) unsigned DEFAULT NULL, +ADD KEY `main_currency_id` (`main_currency_id`), +ADD CONSTRAINT `communities_main_currency_id` FOREIGN KEY (`main_currency_id`) REFERENCES `currencies` (`id`);