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`);