From 5bb5fda6e57fa983fa9dcc81a44df2c6bc5a832e Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sun, 22 Aug 2021 22:38:53 +0200 Subject: [PATCH] - initialize database migration - create database if it does not exist --- .../db/setup_db_tables/address_types.sql | 2 - .../insert_blockchain_types.sql | 5 - .../db/setup_db_tables/insert_migrations.sql | 2 - .../gradido_community/address_types.sql | 7 - .../skeema/gradido_community/admin_errors.sql | 11 - .../gradido_community/blockchain_types.sql | 17 - .../gradido_community/community_profiles.sql | 8 - .../skeema/gradido_community/migrations.sql | 5 - .../gradido_community/operator_types.sql | 6 - .../db/skeema/gradido_community/operators.sql | 8 - .../pending_transactions.sql | 10 - .../db/skeema/gradido_community/roles.sql | 5 - .../skeema/gradido_community/server_users.sql | 12 - .../gradido_community/state_balances.sql | 8 - .../gradido_community/state_created.sql | 11 - .../skeema/gradido_community/state_errors.sql | 8 - .../state_group_addresses.sql | 8 - .../state_group_relationships.sql | 7 - .../skeema/gradido_community/state_groups.sql | 8 - .../state_relationship_types.sql | 6 - .../gradido_community/state_user_roles.sql | 6 - .../state_user_transactions.sql | 9 - .../skeema/gradido_community/state_users.sql | 13 - .../transaction_creations.sql | 9 - .../transaction_group_addaddress.sql | 9 - .../transaction_group_allowtrades.sql | 7 - .../transaction_group_creates.sql | 8 - .../transaction_send_coins.sql | 11 - .../transaction_signatures.sql | 7 - .../gradido_community/transaction_types.sql | 6 - .../skeema/gradido_community/transactions.sql | 10 - database/migrations/1-init_db.ts | 337 +++++++++++++++++- database/package.json | 6 +- database/src/index.ts | 3 + database/src/prepare.ts | 27 ++ 35 files changed, 366 insertions(+), 256 deletions(-) delete mode 100644 community_server/db/setup_db_tables/address_types.sql delete mode 100644 community_server/db/setup_db_tables/insert_blockchain_types.sql delete mode 100644 community_server/db/setup_db_tables/insert_migrations.sql delete mode 100644 community_server/db/skeema/gradido_community/address_types.sql delete mode 100644 community_server/db/skeema/gradido_community/admin_errors.sql delete mode 100644 community_server/db/skeema/gradido_community/blockchain_types.sql delete mode 100644 community_server/db/skeema/gradido_community/community_profiles.sql delete mode 100644 community_server/db/skeema/gradido_community/migrations.sql delete mode 100644 community_server/db/skeema/gradido_community/operator_types.sql delete mode 100644 community_server/db/skeema/gradido_community/operators.sql delete mode 100644 community_server/db/skeema/gradido_community/pending_transactions.sql delete mode 100644 community_server/db/skeema/gradido_community/roles.sql delete mode 100644 community_server/db/skeema/gradido_community/server_users.sql delete mode 100644 community_server/db/skeema/gradido_community/state_balances.sql delete mode 100644 community_server/db/skeema/gradido_community/state_created.sql delete mode 100644 community_server/db/skeema/gradido_community/state_errors.sql delete mode 100644 community_server/db/skeema/gradido_community/state_group_addresses.sql delete mode 100644 community_server/db/skeema/gradido_community/state_group_relationships.sql delete mode 100644 community_server/db/skeema/gradido_community/state_groups.sql delete mode 100644 community_server/db/skeema/gradido_community/state_relationship_types.sql delete mode 100644 community_server/db/skeema/gradido_community/state_user_roles.sql delete mode 100644 community_server/db/skeema/gradido_community/state_user_transactions.sql delete mode 100644 community_server/db/skeema/gradido_community/state_users.sql delete mode 100644 community_server/db/skeema/gradido_community/transaction_creations.sql delete mode 100644 community_server/db/skeema/gradido_community/transaction_group_addaddress.sql delete mode 100644 community_server/db/skeema/gradido_community/transaction_group_allowtrades.sql delete mode 100644 community_server/db/skeema/gradido_community/transaction_group_creates.sql delete mode 100644 community_server/db/skeema/gradido_community/transaction_send_coins.sql delete mode 100644 community_server/db/skeema/gradido_community/transaction_signatures.sql delete mode 100644 community_server/db/skeema/gradido_community/transaction_types.sql delete mode 100644 community_server/db/skeema/gradido_community/transactions.sql create mode 100644 database/src/prepare.ts diff --git a/community_server/db/setup_db_tables/address_types.sql b/community_server/db/setup_db_tables/address_types.sql deleted file mode 100644 index 2a6dc00a5..000000000 --- a/community_server/db/setup_db_tables/address_types.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `address_types` (`id`, `name`, `text`) VALUES -(1, 'user main', 'user main address'); diff --git a/community_server/db/setup_db_tables/insert_blockchain_types.sql b/community_server/db/setup_db_tables/insert_blockchain_types.sql deleted file mode 100644 index 0a58e4392..000000000 --- a/community_server/db/setup_db_tables/insert_blockchain_types.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO `blockchain_types` (`id`, `name`, `text`, `symbol`) VALUES -(1, 'mysql', 'use mysql db as blockchain, work only with single community-server', NULL), -(2, 'hedera', 'use hedera for transactions', 'HBAR'); - - diff --git a/community_server/db/setup_db_tables/insert_migrations.sql b/community_server/db/setup_db_tables/insert_migrations.sql deleted file mode 100644 index 28cb043e6..000000000 --- a/community_server/db/setup_db_tables/insert_migrations.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `migrations` (`id`, `db_version`) VALUES -(1, 3); diff --git a/community_server/db/skeema/gradido_community/address_types.sql b/community_server/db/skeema/gradido_community/address_types.sql deleted file mode 100644 index cb5b1b943..000000000 --- a/community_server/db/skeema/gradido_community/address_types.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `address_types` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL, - `text` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - diff --git a/community_server/db/skeema/gradido_community/admin_errors.sql b/community_server/db/skeema/gradido_community/admin_errors.sql deleted file mode 100644 index 020b4078b..000000000 --- a/community_server/db/skeema/gradido_community/admin_errors.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `admin_errors` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `state_user_id` int(11) NOT NULL, - `controller` varchar(255) NOT NULL, - `action` varchar(255) NOT NULL, - `state` varchar(255) NOT NULL, - `msg` varchar(255) NOT NULL, - `details` varchar(255) DEFAULT NULL, - `created` datetime NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/community_server/db/skeema/gradido_community/blockchain_types.sql b/community_server/db/skeema/gradido_community/blockchain_types.sql deleted file mode 100644 index bd6a12604..000000000 --- a/community_server/db/skeema/gradido_community/blockchain_types.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -/** - * Author: einhornimmond - * Created: 06.04.2021 - */ - -CREATE TABLE `blockchain_types` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - `text` varchar(255) NULL, - `symbol` varchar(10) NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/community_profiles.sql b/community_server/db/skeema/gradido_community/community_profiles.sql deleted file mode 100644 index 22926b126..000000000 --- a/community_server/db/skeema/gradido_community/community_profiles.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `community_profiles` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `state_user_id` int(10) unsigned NOT NULL, - `profile_img` longblob, - `profile_desc` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `state_user_id` (`state_user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/migrations.sql b/community_server/db/skeema/gradido_community/migrations.sql deleted file mode 100644 index 7665bcf29..000000000 --- a/community_server/db/skeema/gradido_community/migrations.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE `migrations` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `db_version` int DEFAULT 0, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/operator_types.sql b/community_server/db/skeema/gradido_community/operator_types.sql deleted file mode 100644 index 35df5264e..000000000 --- a/community_server/db/skeema/gradido_community/operator_types.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `operator_types` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, - `text` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/operators.sql b/community_server/db/skeema/gradido_community/operators.sql deleted file mode 100644 index 74808be9b..000000000 --- a/community_server/db/skeema/gradido_community/operators.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `operators` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `username` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, - `user_pubkey` binary(32) NOT NULL, - `data_base64` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `modified` datetime NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/pending_transactions.sql b/community_server/db/skeema/gradido_community/pending_transactions.sql deleted file mode 100644 index e3d6a4a08..000000000 --- a/community_server/db/skeema/gradido_community/pending_transactions.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE `pending_transactions` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `transactionID` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, - `service` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - `method` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - `h_server_id` int(11) NOT NULL, - `timeout` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - UNIQUE KEY `transactionID` (`transactionID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/roles.sql b/community_server/db/skeema/gradido_community/roles.sql deleted file mode 100644 index 9fe9de710..000000000 --- a/community_server/db/skeema/gradido_community/roles.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE `roles` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/server_users.sql b/community_server/db/skeema/gradido_community/server_users.sql deleted file mode 100644 index 982a4bdc3..000000000 --- a/community_server/db/skeema/gradido_community/server_users.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `server_users` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `username` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, - `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `email` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, - `role` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'admin', - `activated` tinyint(4) NOT NULL DEFAULT '0', - `last_login` datetime DEFAULT NULL, - `created` datetime NOT NULL, - `modified` datetime NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_balances.sql b/community_server/db/skeema/gradido_community/state_balances.sql deleted file mode 100644 index 5f79ce819..000000000 --- a/community_server/db/skeema/gradido_community/state_balances.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `state_balances` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `state_user_id` int(10) unsigned NOT NULL, - `modified` datetime NOT NULL, - `record_date`datetime NULL, - `amount` bigint(20) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_created.sql b/community_server/db/skeema/gradido_community/state_created.sql deleted file mode 100644 index 5bc139594..000000000 --- a/community_server/db/skeema/gradido_community/state_created.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `state_created` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `transaction_id` int(10) unsigned NOT NULL, - `month` tinyint(3) unsigned NOT NULL, - `year` smallint(5) unsigned NOT NULL, - `state_user_id` int(10) unsigned NOT NULL, - `created` datetime NOT NULL, - `short_ident_hash` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `short_ident_hash` (`short_ident_hash`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_errors.sql b/community_server/db/skeema/gradido_community/state_errors.sql deleted file mode 100644 index 8088f6ed2..000000000 --- a/community_server/db/skeema/gradido_community/state_errors.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `state_errors` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `state_user_id` int(10) unsigned NOT NULL, - `transaction_type_id` int(10) unsigned NOT NULL, - `created` datetime NOT NULL, - `message_json` text COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_group_addresses.sql b/community_server/db/skeema/gradido_community/state_group_addresses.sql deleted file mode 100644 index 698a79b98..000000000 --- a/community_server/db/skeema/gradido_community/state_group_addresses.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `state_group_addresses` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `group_id` int(10) unsigned NOT NULL, - `public_key` binary(32) NOT NULL, - `address_type_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - UNIQUE(`public_key`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_group_relationships.sql b/community_server/db/skeema/gradido_community/state_group_relationships.sql deleted file mode 100644 index d2eecbfc0..000000000 --- a/community_server/db/skeema/gradido_community/state_group_relationships.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `state_group_relationships` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `group1_id` int(10) unsigned NOT NULL, - `group2_id` int(10) unsigned NOT NULL, - `state_relationship_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_groups.sql b/community_server/db/skeema/gradido_community/state_groups.sql deleted file mode 100644 index 30a810a19..000000000 --- a/community_server/db/skeema/gradido_community/state_groups.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `state_groups` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `index_id` varbinary(64) NOT NULL, - `name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, - `root_public_key` binary(32) NOT NULL, - `user_count` smallint(5) unsigned NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_relationship_types.sql b/community_server/db/skeema/gradido_community/state_relationship_types.sql deleted file mode 100644 index fd901b8ac..000000000 --- a/community_server/db/skeema/gradido_community/state_relationship_types.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `state_relationship_types` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, - `text` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_user_roles.sql b/community_server/db/skeema/gradido_community/state_user_roles.sql deleted file mode 100644 index 207c2de63..000000000 --- a/community_server/db/skeema/gradido_community/state_user_roles.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `state_user_roles` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `state_user_id` int(11) NOT NULL, - `role_id` int(11) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_user_transactions.sql b/community_server/db/skeema/gradido_community/state_user_transactions.sql deleted file mode 100644 index 5e01cac4a..000000000 --- a/community_server/db/skeema/gradido_community/state_user_transactions.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `state_user_transactions` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `state_user_id` int UNSIGNED NOT NULL, - `transaction_id` int UNSIGNED NOT NULL, - `transaction_type_id` int UNSIGNED NOT NULL, - `balance` bigint(20) DEFAULT 0, - `balance_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/state_users.sql b/community_server/db/skeema/gradido_community/state_users.sql deleted file mode 100644 index 706fa699e..000000000 --- a/community_server/db/skeema/gradido_community/state_users.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE `state_users` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `index_id` smallint(6) NOT NULL DEFAULT '0', - `group_id` int(10) unsigned NOT NULL DEFAULT '0', - `public_key` binary(32) NOT NULL, - `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `first_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `last_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `username` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `disabled` tinyint(4) DEFAULT '0', - PRIMARY KEY (`id`), - UNIQUE KEY `public_key` (`public_key`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transaction_creations.sql b/community_server/db/skeema/gradido_community/transaction_creations.sql deleted file mode 100644 index 8612c764a..000000000 --- a/community_server/db/skeema/gradido_community/transaction_creations.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `transaction_creations` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `transaction_id` int(10) unsigned NOT NULL, - `state_user_id` int(10) unsigned NOT NULL, - `amount` bigint(20) NOT NULL, - `ident_hash` binary(32) NULL, - `target_date` timestamp NULL DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transaction_group_addaddress.sql b/community_server/db/skeema/gradido_community/transaction_group_addaddress.sql deleted file mode 100644 index cb21ed99f..000000000 --- a/community_server/db/skeema/gradido_community/transaction_group_addaddress.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `transaction_group_addaddress` ( - `id` int unsigned NOT NULL AUTO_INCREMENT, - `transaction_id` int unsigned NOT NULL, - `address_type_id` int unsigned NOT NULL, - `remove_from_group` BOOLEAN DEFAULT FALSE, - `public_key` binary(32) NOT NULL, - `state_user_id` int unsigned NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transaction_group_allowtrades.sql b/community_server/db/skeema/gradido_community/transaction_group_allowtrades.sql deleted file mode 100644 index 923e0d5d0..000000000 --- a/community_server/db/skeema/gradido_community/transaction_group_allowtrades.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `transaction_group_allowtrades` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `transaction_id` int(10) unsigned NOT NULL, - `remote_group_id` varbinary(64) NOT NULL, - `allow` tinyint(4) NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transaction_group_creates.sql b/community_server/db/skeema/gradido_community/transaction_group_creates.sql deleted file mode 100644 index b5d7629b4..000000000 --- a/community_server/db/skeema/gradido_community/transaction_group_creates.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `transaction_group_creates` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `transaction_id` int(10) unsigned NOT NULL, - `group_public_key` binary(32) NOT NULL, - `group_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transaction_send_coins.sql b/community_server/db/skeema/gradido_community/transaction_send_coins.sql deleted file mode 100644 index 49423fdbc..000000000 --- a/community_server/db/skeema/gradido_community/transaction_send_coins.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `transaction_send_coins` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `transaction_id` int(10) unsigned NOT NULL, - `sender_public_key` binary(32) NOT NULL, - `state_user_id` int(10) unsigned DEFAULT 0, - `receiver_public_key` binary(32) NOT NULL, - `receiver_user_id` int(10) unsigned DEFAULT 0, - `amount` bigint(20) NOT NULL, - `sender_final_balance` bigint(20) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transaction_signatures.sql b/community_server/db/skeema/gradido_community/transaction_signatures.sql deleted file mode 100644 index 0c13b77da..000000000 --- a/community_server/db/skeema/gradido_community/transaction_signatures.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `transaction_signatures` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `transaction_id` int(10) unsigned NOT NULL, - `signature` binary(64) NOT NULL, - `pubkey` binary(32) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transaction_types.sql b/community_server/db/skeema/gradido_community/transaction_types.sql deleted file mode 100644 index 10aad25b0..000000000 --- a/community_server/db/skeema/gradido_community/transaction_types.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `transaction_types` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL, - `text` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/db/skeema/gradido_community/transactions.sql b/community_server/db/skeema/gradido_community/transactions.sql deleted file mode 100644 index e6009608e..000000000 --- a/community_server/db/skeema/gradido_community/transactions.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE `transactions` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `state_group_id` int(10) unsigned DEFAULT NULL, - `transaction_type_id` int(10) unsigned NOT NULL, - `tx_hash` binary(48) DEFAULT NULL, - `memo` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `blockchain_type_id` bigint(20) unsigned NOT NULL DEFAULT 1, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/database/migrations/1-init_db.ts b/database/migrations/1-init_db.ts index d112ba0b6..b402c0f72 100644 --- a/database/migrations/1-init_db.ts +++ b/database/migrations/1-init_db.ts @@ -1,13 +1,342 @@ +/* FIRST MIGRATION + * + * This migration is special since it takes into account that + * the database can be setup already but also may not be. + * Therefore you will find all `CREATE TABLE` statements with + * a `IF NOT EXISTS`, all `INSERT` with an `IGNORE` and in the + * downgrade function all `DROP TABLE` with a `IF EXISTS`. + * This ensures compatibility for existing or non-existing + * databases. + */ + export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write upgrade logic as parameter of queryFn await queryFn(` - CREATE TABLE TEST (ID INTEGER NULL, NAME VARCHAR(20) NULL); + CREATE TABLE IF NOT EXISTS \`address_types\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL, + \`text\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; `) + await queryFn(` + INSERT IGNORE INTO \`address_types\` (\`id\`, \`name\`, \`text\`) VALUES + (1, 'user main', 'user main address');`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`admin_errors\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`state_user_id\` int(11) NOT NULL, + \`controller\` varchar(255) NOT NULL, + \`action\` varchar(255) NOT NULL, + \`state\` varchar(255) NOT NULL, + \`msg\` varchar(255) NOT NULL, + \`details\` varchar(255) DEFAULT NULL, + \`created\` datetime NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`blockchain_types\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(45) NOT NULL, + \`text\` varchar(255) NULL, + \`symbol\` varchar(10) NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + await queryFn(` + INSERT IGNORE INTO \`blockchain_types\` (\`id\`, \`name\`, \`text\`, \`symbol\`) VALUES + (1, 'mysql', 'use mysql db as blockchain, work only with single community-server', NULL), + (2, 'hedera', 'use hedera for transactions', 'HBAR');`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`community_profiles\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`state_user_id\` int(10) unsigned NOT NULL, + \`profile_img\` longblob, + \`profile_desc\` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (\`id\`), + KEY \`state_user_id\` (\`state_user_id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`operator_types\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, + \`text\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`operators\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`username\` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, + \`user_pubkey\` binary(32) NOT NULL, + \`data_base64\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + \`modified\` datetime NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`pending_transactions\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`transactionID\` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, + \`service\` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, + \`method\` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, + \`h_server_id\` int(11) NOT NULL, + \`timeout\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (\`id\`), + UNIQUE KEY \`transactionID\` (\`transactionID\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`roles\` ( + \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, + \`title\` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`server_users\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`username\` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, + \`password\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + \`email\` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, + \`role\` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'admin', + \`activated\` tinyint(4) NOT NULL DEFAULT '0', + \`last_login\` datetime DEFAULT NULL, + \`created\` datetime NOT NULL, + \`modified\` datetime NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_balances\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`state_user_id\` int(10) unsigned NOT NULL, + \`modified\` datetime NOT NULL, + \`record_date\`datetime NULL, + \`amount\` bigint(20) NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_created\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`transaction_id\` int(10) unsigned NOT NULL, + \`month\` tinyint(3) unsigned NOT NULL, + \`year\` smallint(5) unsigned NOT NULL, + \`state_user_id\` int(10) unsigned NOT NULL, + \`created\` datetime NOT NULL, + \`short_ident_hash\` int(10) unsigned NOT NULL, + PRIMARY KEY (\`id\`), + KEY \`short_ident_hash\` (\`short_ident_hash\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_errors\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`state_user_id\` int(10) unsigned NOT NULL, + \`transaction_type_id\` int(10) unsigned NOT NULL, + \`created\` datetime NOT NULL, + \`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_group_addresses\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`group_id\` int(10) unsigned NOT NULL, + \`public_key\` binary(32) NOT NULL, + \`address_type_id\` int(10) unsigned NOT NULL, + PRIMARY KEY (\`id\`), + UNIQUE(\`public_key\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_group_relationships\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`group1_id\` int(10) unsigned NOT NULL, + \`group2_id\` int(10) unsigned NOT NULL, + \`state_relationship_id\` int(10) unsigned NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_groups\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`index_id\` varbinary(64) NOT NULL, + \`name\` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, + \`root_public_key\` binary(32) NOT NULL, + \`user_count\` smallint(5) unsigned NOT NULL DEFAULT '0', + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_relationship_types\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, + \`text\` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_user_roles\` ( + \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, + \`state_user_id\` int(11) NOT NULL, + \`role_id\` int(11) NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_user_transactions\` ( + \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, + \`state_user_id\` int UNSIGNED NOT NULL, + \`transaction_id\` int UNSIGNED NOT NULL, + \`transaction_type_id\` int UNSIGNED NOT NULL, + \`balance\` bigint(20) DEFAULT 0, + \`balance_date\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`state_users\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`index_id\` smallint(6) NOT NULL DEFAULT '0', + \`group_id\` int(10) unsigned NOT NULL DEFAULT '0', + \`public_key\` binary(32) NOT NULL, + \`email\` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + \`first_name\` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + \`last_name\` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + \`username\` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + \`disabled\` tinyint(4) DEFAULT '0', + PRIMARY KEY (\`id\`), + UNIQUE KEY \`public_key\` (\`public_key\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transaction_creations\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`transaction_id\` int(10) unsigned NOT NULL, + \`state_user_id\` int(10) unsigned NOT NULL, + \`amount\` bigint(20) NOT NULL, + \`ident_hash\` binary(32) NULL, + \`target_date\` timestamp NULL DEFAULT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + `) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transaction_group_addaddress\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`transaction_id\` int unsigned NOT NULL, + \`address_type_id\` int unsigned NOT NULL, + \`remove_from_group\` BOOLEAN DEFAULT FALSE, + \`public_key\` binary(32) NOT NULL, + \`state_user_id\` int unsigned NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transaction_group_allowtrades\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`transaction_id\` int(10) unsigned NOT NULL, + \`remote_group_id\` varbinary(64) NOT NULL, + \`allow\` tinyint(4) NOT NULL DEFAULT '0', + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transaction_group_creates\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`transaction_id\` int(10) unsigned NOT NULL, + \`group_public_key\` binary(32) NOT NULL, + \`group_id\` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + \`name\` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transaction_send_coins\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`transaction_id\` int(10) unsigned NOT NULL, + \`sender_public_key\` binary(32) NOT NULL, + \`state_user_id\` int(10) unsigned DEFAULT 0, + \`receiver_public_key\` binary(32) NOT NULL, + \`receiver_user_id\` int(10) unsigned DEFAULT 0, + \`amount\` bigint(20) NOT NULL, + \`sender_final_balance\` bigint(20) NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transaction_signatures\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`transaction_id\` int(10) unsigned NOT NULL, + \`signature\` binary(64) NOT NULL, + \`pubkey\` binary(32) NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transaction_types\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(90) COLLATE utf8mb4_unicode_ci NOT NULL, + \`text\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) + await queryFn(` + INSERT IGNORE INTO \`transaction_types\` (\`id\`, \`name\`, \`text\`) VALUES + (1, 'creation', 'create new gradidos for member and also for group (in development)'), + (2, 'transfer', 'send gradidos from one member to another, also cross group transfer'), + (3, 'group create', 'create a new group, trigger creation of new hedera topic and new blockchain on node server'), + (4, 'group add member', 'add user to a group or move if he was already in a group'), + (5, 'group remove member', 'remove user from group, maybe he was moved elsewhere'), + (6, 'hedera topic create', 'create new topic on hedera'), + (7, 'hedera topic send message', 'send consensus message over hedera topic'), + (8, 'hedera account create', 'create new account on hedera for holding some founds with unencrypted keys'), + (9, 'decay start', 'signalize the starting point for decay calculation, allowed only once per chain');`) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`transactions\` ( + \`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + \`state_group_id\` int(10) unsigned DEFAULT NULL, + \`transaction_type_id\` int(10) unsigned NOT NULL, + \`tx_hash\` binary(48) DEFAULT NULL, + \`memo\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + \`received\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + \`blockchain_type_id\` bigint(20) unsigned NOT NULL DEFAULT 1, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`) } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn - await queryFn(` - DROP TABLE TEST; - `) + await queryFn(`DROP TABLE IF EXISTS \`address_types\`;`) + await queryFn(`DROP TABLE IF EXISTS \`admin_errors\`;`) + await queryFn(`DROP TABLE IF EXISTS \`blockchain_types\`;`) + await queryFn(`DROP TABLE IF EXISTS \`community_profiles\`;`) + await queryFn(`DROP TABLE IF EXISTS \`operator_types\`;`) + await queryFn(`DROP TABLE IF EXISTS \`operators\`;`) + await queryFn(`DROP TABLE IF EXISTS \`pending_transactions\`;`) + await queryFn(`DROP TABLE IF EXISTS \`roles\`;`) + await queryFn(`DROP TABLE IF EXISTS \`server_users\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_balances\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_created\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_errors\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_group_addresses\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_group_relationships\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_groups\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_relationship_types\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_user_roles\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_user_transactions\`;`) + await queryFn(`DROP TABLE IF EXISTS \`state_users\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transaction_creations\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transaction_group_addaddress\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transaction_group_allowtrades\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transaction_group_creates\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transaction_send_coins\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transaction_signatures\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transaction_types\`;`) + await queryFn(`DROP TABLE IF EXISTS \`transactions\`;`) } diff --git a/database/package.json b/database/package.json index d0608e2dd..ced0054d1 100644 --- a/database/package.json +++ b/database/package.json @@ -13,9 +13,9 @@ "up": "node build/src/index.js up", "down": "node build/src/index.js down", "reset": "node build/src/index.js reset", - "dev_up": "nodemon -w src --ext ts --exec ts-node src/index.ts up", - "dev_down": "nodemon -w src --ext ts --exec ts-node src/index.ts down", - "dev_reset": "nodemon -w src --ext ts --exec ts-node src/index.ts reset", + "dev_up": "nodemon -w ./ --ext ts --exec ts-node src/index.ts up", + "dev_down": "nodemon -w ./ --ext ts --exec ts-node src/index.ts down", + "dev_reset": "nodemon -w ./ --ext ts --exec ts-node src/index.ts reset", "lint": "eslint . --ext .js,.ts" }, "devDependencies": { diff --git a/database/src/index.ts b/database/src/index.ts index dbc3a92ed..af07db609 100644 --- a/database/src/index.ts +++ b/database/src/index.ts @@ -1,8 +1,11 @@ import { createPool, PoolConfig } from 'mysql' import { Migration } from 'ts-mysql-migrate' import CONFIG from './config' +import prepare from './prepare' const run = async (command: string) => { + await prepare() + // Database connection const poolConfig: PoolConfig = { host: CONFIG.DB_HOST, diff --git a/database/src/prepare.ts b/database/src/prepare.ts new file mode 100644 index 000000000..8ab0e8e84 --- /dev/null +++ b/database/src/prepare.ts @@ -0,0 +1,27 @@ +/* PREPARE SCRIPT + * + * This file ensures operations our migration library + * can not take care of are done. + * This applies to all Database Operations like + * creating, deleting, renaming Databases. + */ + +import { createConnection } from 'mysql' +import CONFIG from './config' + +export default async () => { + const con = createConnection({ + host: CONFIG.DB_HOST, + port: CONFIG.DB_PORT, + user: CONFIG.DB_USER, + password: CONFIG.DB_PASSWORD, + }) + + await con.connect() + + // Create Databse `gradido_community` + await con.query(` + CREATE DATABASE IF NOT EXISTS ${CONFIG.DB_DATABASE} + DEFAULT CHARACTER SET utf8mb4 + DEFAULT COLLATE utf8mb4_unicode_ci;`) +}