From a22593925a15d00db3afbccb5cc7228f295fabd2 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Mon, 10 May 2021 15:37:39 +0000 Subject: [PATCH] more migrations --- .../db/setup_db_tables/insert_migrations.sql | 2 + .../src/Controller/MigrationsController.php | 6 +- .../src/Model/Table/BlockchainTypesTable.php | 35 ++++++++++- .../src/Model/Table/TransactionTypesTable.php | 60 ++++++++++++++++++- 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 community_server/db/setup_db_tables/insert_migrations.sql diff --git a/community_server/db/setup_db_tables/insert_migrations.sql b/community_server/db/setup_db_tables/insert_migrations.sql new file mode 100644 index 000000000..e6f38117d --- /dev/null +++ b/community_server/db/setup_db_tables/insert_migrations.sql @@ -0,0 +1,2 @@ +INSERT INTO `migrations` (`id`, `db_version`) VALUES +(1, 2); diff --git a/community_server/src/Controller/MigrationsController.php b/community_server/src/Controller/MigrationsController.php index c2febef0f..ddf02bfdc 100644 --- a/community_server/src/Controller/MigrationsController.php +++ b/community_server/src/Controller/MigrationsController.php @@ -41,7 +41,9 @@ class MigrationsController extends AppController $startTime = microtime(true); $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); + $transactionTypesTable = TableRegistry::getTableLocator()->get('TransactionTypes'); $stateBalancesTable = TableRegistry::getTableLocator()->get('StateBalances'); + $blockchainTypesTable = TableRegistry::getTableLocator()->get('BlockchainTypes'); $new_db_version = 1; @@ -51,7 +53,9 @@ class MigrationsController extends AppController $stateUserTransactionsTable->truncate(); $commands = [ [$transactionsTable, 'fillStateUserTransactions'], - [$stateBalancesTable, 'updateAllBalances'] + [$stateBalancesTable, 'updateAllBalances'], + [$blockchainTypesTable, 'fillWithDefault'], + [$transactionTypesTable, 'fillWithDefault'] ]; $new_db_version = 2; } diff --git a/community_server/src/Model/Table/BlockchainTypesTable.php b/community_server/src/Model/Table/BlockchainTypesTable.php index 90213ac9f..252fb8fd7 100644 --- a/community_server/src/Model/Table/BlockchainTypesTable.php +++ b/community_server/src/Model/Table/BlockchainTypesTable.php @@ -18,7 +18,7 @@ use Cake\Validation\Validator; * @method \App\Model\Entity\BlockchainType[] patchEntities($entities, array $data, array $options = []) * @method \App\Model\Entity\BlockchainType findOrCreate($search, callable $callback = null, $options = []) */ -class BlockchainTypesTable extends Table +class BlockchainTypesTable extends AppTable { /** * Initialize method @@ -65,4 +65,37 @@ class BlockchainTypesTable extends Table return $validator; } + + public function fillWithDefault() + { + $entry_contents = [ + [ + 'id' => 1, + 'name' => 'mysql', + 'text' => 'use mysql db as blockchain, work only with single community-server', + 'symbol' => NULL + ], + [ + 'id' => 2, + 'name' => 'hedera', + 'text' => 'use hedera for transactions', + 'symbol' => 'HBAR' + ] + ]; + $entities = $this->newEntities($entry_contents); + $this->truncate(); + $save_results = $this->saveMany($entities); + $errors = []; + foreach($save_results as $i => $result) + { + if(!$result) { + $errors[] = $entities[$i]->getErrors(); + } + } + if(count($errors) > 0) { + return ['success' => false, 'msg' => 'error by saving blockchain types', 'errors' => $errors]; + } + return ['success' => true]; + + } } diff --git a/community_server/src/Model/Table/TransactionTypesTable.php b/community_server/src/Model/Table/TransactionTypesTable.php index 5cc842f5e..7669ff2b3 100644 --- a/community_server/src/Model/Table/TransactionTypesTable.php +++ b/community_server/src/Model/Table/TransactionTypesTable.php @@ -20,7 +20,7 @@ use Cake\Validation\Validator; * @method \App\Model\Entity\TransactionType[] patchEntities($entities, array $data, array $options = []) * @method \App\Model\Entity\TransactionType findOrCreate($search, callable $callback = null, $options = []) */ -class TransactionTypesTable extends Table +class TransactionTypesTable extends AppTable { /** * Initialize method @@ -66,4 +66,62 @@ class TransactionTypesTable extends Table return $validator; } + + public function fillWithDefault() + { + + $entry_contents = [ + [ + 'id' => 1, + 'name' => 'creation', + 'text' => 'create new gradidos for member and also for group (in development)', + ], [ + 'id' => 2, + 'name' => 'transfer', + 'text' => 'send gradidos from one member to another, also cross group transfer', + ], [ + 'id' => 3, + 'name' => 'group create', + 'text' => 'create a new group, trigger creation of new hedera topic and new blockchain on node server' + ], [ + 'id' => 4, + 'name' => 'group add member', + 'text' => 'add user to a group or move if he was already in a group' + ], [ + 'id' => 5, + 'name' => 'group remove member', + 'text' => 'remove user from group, maybe he was moved elsewhere' + ],[ + 'id' => 6, + 'name' => 'hedera topic create', + 'text' => 'create new topic on hedera' + ],[ + 'id' => 7, + 'name' => 'hedera topic send message', + 'text' => 'send consensus message over hedera topic' + ],[ + 'id' => 8, + 'name' => 'hedera account create', + 'text' => 'create new account on hedera for holding some founds with unencrypted keys' + ],[ + 'id' => 9, + 'name' => 'decay start', + 'text' => 'signalize the starting point for decay calculation, allowed only once per chain' + ] + ]; + $entities = $this->newEntities($entry_contents); + $this->truncate(); + $save_results = $this->saveMany($entities); + $errors = []; + foreach($save_results as $i => $result) + { + if(!$result) { + $errors[] = $entities[$i]->getErrors(); + } + } + if(count($errors) > 0) { + return ['success' => false, 'msg' => 'error by saving transaction types', 'errors' => $errors]; + } + return ['success' => true]; + } }