diff --git a/community_server/tests/Fixture/StateUsersFixture.php b/community_server/tests/Fixture/UserFixture.php similarity index 55% rename from community_server/tests/Fixture/StateUsersFixture.php rename to community_server/tests/Fixture/UserFixture.php index a9b033bf7..e6d59a238 100644 --- a/community_server/tests/Fixture/StateUsersFixture.php +++ b/community_server/tests/Fixture/UserFixture.php @@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture; /** * StateUsersFixture */ -class StateUsersFixture extends BaseTestFixture +class UserFixture extends BaseTestFixture { /** * Fields @@ -16,17 +16,16 @@ class StateUsersFixture extends BaseTestFixture // @codingStandardsIgnoreStart public $fields = [ 'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], - 'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null], - 'group_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null], - 'public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], + 'groupId' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'pubkey' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'email' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null], - 'first_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null], - 'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null], + 'firstNname' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null], + 'lastName' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null], 'username' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null], 'disabled' => ['type' => 'tinyinteger', 'length' => 4, 'unsigned' => false, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null], '_constraints' => [ 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], - 'public_key' => ['type' => 'unique', 'columns' => ['public_key'], 'length' => []], + 'pubkey' => ['type' => 'unique', 'columns' => ['pubkey'], 'length' => []], ], '_options' => [ 'engine' => 'InnoDB', @@ -44,9 +43,9 @@ class StateUsersFixture extends BaseTestFixture public function init() { $sql_entrys = [ - [1, 0, 0, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0], - [3, 0, 0, '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6', 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0], - [4, 0, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] + [1, 0, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0], + [3, 0, '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6', 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0], + [4, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] ]; $this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields); parent::init(); diff --git a/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php b/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php index f990b3e57..496e7e3c5 100644 --- a/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php +++ b/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php @@ -21,7 +21,7 @@ class JsonRequestHandlerControllerTest extends TestCase public $fixtures = [ 'app.TransactionCreations', 'app.Transactions', - 'app.StateUsers', + 'app.User', 'app.StateUserTransactions', 'app.StateErrors', 'app.TransactionSignatures', diff --git a/database/migrations/0002-update_user.ts b/database/migrations/0002-update_user.ts index 54e6acc7e..d23beab90 100644 --- a/database/migrations/0002-update_user.ts +++ b/database/migrations/0002-update_user.ts @@ -10,47 +10,46 @@ */ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { - // write upgrade logic as parameter of queryFn - - // rename table - await queryFn(` + // write upgrade logic as parameter of queryFn + + // rename table + await queryFn(` ALTER TABLE state_users RENAME TO user; `) - // drop not used columns - await queryFn(` + // drop not used columns + await queryFn(` ALTER TABLE user DROP COLUMN index_id; `) - // rename from snake case to camel case (cakePHP standard to typeorm standard) - await queryFn(` + // rename from snake case to camel case (cakePHP standard to typeorm standard) + await queryFn(` ALTER TABLE user CHANGE COLUMN group_id groupId int(10) unsigned NOT NULL DEFAULT '0', CHANGE COLUMN public_key pubkey binary(32) NOT NULL, CHANGE COLUMN first_name firstName varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, CHANGE COLUMN last_name lastName varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL; `) - } - - export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { - // write downgrade logic as parameter of queryFn - // rename table - await queryFn(` +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + // write downgrade logic as parameter of queryFn + // rename table + await queryFn(` ALTER TABLE user RENAME TO state_users; `) - // put back dropped column - await queryFn(` + // put back dropped column + await queryFn(` ALTER TABLE state_users ADD index_id smallint(6) NOT NULL DEFAULT '0'; `) - // rename from camel case to snake case (typeorm standard to cakePHP standard) - await queryFn(` + // rename from camel case to snake case (typeorm standard to cakePHP standard) + await queryFn(` ALTER TABLE state_users CHANGE COLUMN groupId group_id int(10) unsigned NOT NULL DEFAULT '0', CHANGE COLUMN pubkey public_key binary(32) NOT NULL, CHANGE COLUMN firstName first_name varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, CHANGE COLUMN lastName last_name varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL; `) - } - \ No newline at end of file +}