mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #1031 from gradido/migrate_login_database
migrate_login_database
This commit is contained in:
commit
ca7ca3da73
21
.github/workflows/test.yml
vendored
21
.github/workflows/test.yml
vendored
@ -147,7 +147,7 @@ jobs:
|
||||
##########################################################################
|
||||
- name: mariadb | Build `test` image
|
||||
run: |
|
||||
docker build --target mariadb_server_test -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./
|
||||
docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./
|
||||
docker save "gradido/mariadb:test" > /tmp/mariadb.tar
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
@ -409,10 +409,16 @@ jobs:
|
||||
--health-timeout=3s
|
||||
--health-retries=4
|
||||
steps:
|
||||
- name: Debug service
|
||||
run: echo "$(docker ps)"
|
||||
- name: Debug container choosing script
|
||||
run: echo "$(docker container ls | grep mariadb | awk '{ print $1 }')"
|
||||
# - name: Debug service
|
||||
# run: echo "$(docker ps)"
|
||||
#- name: Debug container choosing script
|
||||
# run: echo "$(docker container ls | grep mariadb | awk '{ print $1 }')"
|
||||
- name: get mariadb container id
|
||||
run: echo "::set-output name=id::$(docker container ls | grep mariadb | awk '{ print $1 }')"
|
||||
id: mariadb_container
|
||||
- name: get automatic created network
|
||||
run: echo "::set-output name=id::$(docker network ls | grep github_network | awk '{ print $1 }')"
|
||||
id: network
|
||||
##########################################################################
|
||||
# CHECKOUT CODE ##########################################################
|
||||
##########################################################################
|
||||
@ -420,6 +426,11 @@ jobs:
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
# Database migration
|
||||
- name: Start database migration
|
||||
run: |
|
||||
docker build --target production_up -t "gradido/database:production_up" database/
|
||||
docker run --network ${{ steps.network.outputs.id }} --name=database --env NODE_ENV=production --env DB_HOST=mariadb --env DB_DATABASE=gradido_community_test -d gradido/database:production_up
|
||||
##########################################################################
|
||||
# Build Login-Server Test Docker image ###################################
|
||||
##########################################################################
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,7 +2,6 @@
|
||||
/node_modules/*
|
||||
.vscode
|
||||
messages.pot
|
||||
.skeema
|
||||
nbproject
|
||||
.metadata
|
||||
/.env
|
||||
|
||||
@ -23,7 +23,7 @@ import schema from './graphql/schema'
|
||||
// TODO implement
|
||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||
|
||||
const DB_VERSION = '0002-add_settings'
|
||||
const DB_VERSION = '0004-login_server_data'
|
||||
|
||||
async function main() {
|
||||
// open mysql connection
|
||||
|
||||
@ -17,7 +17,7 @@ phpServer.host = nginx
|
||||
loginServer.path = http://localhost/account
|
||||
loginServer.default_locale = de
|
||||
loginServer.db.host = mariadb
|
||||
loginServer.db.name = gradido_login
|
||||
loginServer.db.name = gradido_community
|
||||
loginServer.db.user = root
|
||||
loginServer.db.password =
|
||||
loginServer.db.port = 3306
|
||||
|
||||
@ -17,7 +17,7 @@ phpServer.host = nginx
|
||||
loginServer.path = http://localhost/account
|
||||
loginServer.default_locale = de
|
||||
loginServer.db.host = mariadb
|
||||
loginServer.db.name = gradido_login_test
|
||||
loginServer.db.name = gradido_community_test
|
||||
loginServer.db.user = root
|
||||
loginServer.db.password =
|
||||
loginServer.db.port = 3306
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
INSERT INTO `groups` (`id`, `alias`, `name`, `url`, `host`, `home`, `description`) VALUES
|
||||
(1, 'docker', 'docker gradido group', 'localhost', 'nginx', '/', 'gradido test group for docker and stage2 with blockchain db');
|
||||
|
||||
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`
|
||||
CREATE TABLE IF NOT EXISTS \`user_setting\` (
|
||||
CREATE TABLE \`user_setting\` (
|
||||
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`userId\` int(11) NOT NULL,
|
||||
\`key\` varchar(255) NOT NULL,
|
||||
@ -22,5 +22,5 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// write downgrade logic as parameter of queryFn
|
||||
await queryFn(`DROP TABLE IF EXISTS \`user_setting\`;`)
|
||||
await queryFn(`DROP TABLE \`user_setting\`;`)
|
||||
}
|
||||
|
||||
153
database/migrations/0003-login_server_tables.ts
Normal file
153
database/migrations/0003-login_server_tables.ts
Normal file
@ -0,0 +1,153 @@
|
||||
/* 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<Array<any>>) {
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_app_access_tokens\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`user_id\` int NOT NULL,
|
||||
\`access_code\` bigint unsigned NOT NULL,
|
||||
\`created\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
\`updated\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (\`id\`),
|
||||
UNIQUE KEY \`access_code\` (\`access_code\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_elopage_buys\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`elopage_user_id\` int DEFAULT NULL,
|
||||
\`affiliate_program_id\` int NOT NULL,
|
||||
\`publisher_id\` int NOT NULL,
|
||||
\`order_id\` int NOT NULL,
|
||||
\`product_id\` int NOT NULL,
|
||||
\`product_price\` int NOT NULL,
|
||||
\`payer_email\` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
\`publisher_email\` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
\`payed\` tinyint NOT NULL,
|
||||
\`success_date\` datetime NOT NULL,
|
||||
\`event\` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_email_opt_in_types\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`name\` varchar(255) NOT NULL,
|
||||
\`description\` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_email_opt_in\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`user_id\` int NOT NULL,
|
||||
\`verification_code\` bigint unsigned NOT NULL,
|
||||
\`email_opt_in_type_id\` int NOT NULL,
|
||||
\`created\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
\`resend_count\` int DEFAULT '0',
|
||||
\`updated\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (\`id\`),
|
||||
UNIQUE KEY \`verification_code\` (\`verification_code\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_groups\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`alias\` varchar(190) NOT NULL,
|
||||
\`name\` varchar(255) NOT NULL,
|
||||
\`url\` varchar(255) NOT NULL,
|
||||
\`host\` varchar(255) DEFAULT "/",
|
||||
\`home\` varchar(255) DEFAULT "/",
|
||||
\`description\` text,
|
||||
PRIMARY KEY (\`id\`),
|
||||
UNIQUE KEY \`alias\` (\`alias\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_pending_tasks\` (
|
||||
\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
\`user_id\` int UNSIGNED DEFAULT 0,
|
||||
\`request\` varbinary(2048) NOT NULL,
|
||||
\`created\` datetime NOT NULL,
|
||||
\`finished\` datetime DEFAULT '2000-01-01 000000',
|
||||
\`result_json\` text DEFAULT NULL,
|
||||
\`param_json\` text DEFAULT NULL,
|
||||
\`task_type_id\` int UNSIGNED NOT NULL,
|
||||
\`child_pending_task_id\` int UNSIGNED DEFAULT 0,
|
||||
\`parent_pending_task_id\` int UNSIGNED DEFAULT 0,
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_roles\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`name\` varchar(255) NOT NULL,
|
||||
\`description\` varchar(255) NOT NULL,
|
||||
\`flags\` bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_user_backups\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`user_id\` int NOT NULL,
|
||||
\`passphrase\` text NOT NULL,
|
||||
\`mnemonic_type\` int DEFAULT '-1',
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_user_roles\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`user_id\` int NOT NULL,
|
||||
\`role_id\` int NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
await queryFn(`
|
||||
CREATE TABLE \`login_users\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`email\` varchar(191) NOT NULL,
|
||||
\`first_name\` varchar(150) NOT NULL,
|
||||
\`last_name\` varchar(255) DEFAULT '',
|
||||
\`username\` varchar(255) DEFAULT '',
|
||||
\`description\` text DEFAULT '',
|
||||
\`password\` bigint unsigned DEFAULT '0',
|
||||
\`pubkey\` binary(32) DEFAULT NULL,
|
||||
\`privkey\` binary(80) DEFAULT NULL,
|
||||
\`email_hash\` binary(32) DEFAULT NULL,
|
||||
\`created\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
\`email_checked\` tinyint NOT NULL DEFAULT '0',
|
||||
\`passphrase_shown\` tinyint NOT NULL DEFAULT '0',
|
||||
\`language\` varchar(4) NOT NULL DEFAULT 'de',
|
||||
\`disabled\` tinyint DEFAULT '0',
|
||||
\`group_id\` int unsigned DEFAULT 0,
|
||||
\`publisher_id\` int DEFAULT 0,
|
||||
PRIMARY KEY (\`id\`),
|
||||
UNIQUE KEY \`email\` (\`email\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// write downgrade logic as parameter of queryFn
|
||||
await queryFn(`DROP TABLE \`login_app_access_tokens\`;`)
|
||||
await queryFn(`DROP TABLE \`login_elopage_buys\`;`)
|
||||
await queryFn(`DROP TABLE \`login_email_opt_in_types\`;`)
|
||||
await queryFn(`DROP TABLE \`login_email_opt_in\`;`)
|
||||
await queryFn(`DROP TABLE \`login_groups\`;`)
|
||||
await queryFn(`DROP TABLE \`login_pending_tasks\`;`)
|
||||
await queryFn(`DROP TABLE \`login_roles\`;`)
|
||||
await queryFn(`DROP TABLE \`login_user_backups\`;`)
|
||||
await queryFn(`DROP TABLE \`login_user_roles\`;`)
|
||||
await queryFn(`DROP TABLE \`login_users\`;`)
|
||||
}
|
||||
74
database/migrations/0004-login_server_data.ts
Normal file
74
database/migrations/0004-login_server_data.ts
Normal file
@ -0,0 +1,74 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
const LOGIN_SERVER_DB = 'gradido_login'
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
const loginDatabaseExists = await queryFn(`
|
||||
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${LOGIN_SERVER_DB}'
|
||||
`)
|
||||
if (loginDatabaseExists.length === 0) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Skipping Login Server Database migration - Database ${LOGIN_SERVER_DB} not found`)
|
||||
return
|
||||
}
|
||||
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_app_access_tokens\` SELECT * FROM ${LOGIN_SERVER_DB}.\`app_access_tokens\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_elopage_buys\` SELECT * FROM ${LOGIN_SERVER_DB}.\`elopage_buys\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_email_opt_in_types\` SELECT * FROM ${LOGIN_SERVER_DB}.\`email_opt_in_types\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_email_opt_in\` SELECT * FROM ${LOGIN_SERVER_DB}.\`email_opt_in\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_groups\` SELECT * FROM ${LOGIN_SERVER_DB}.\`groups\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_pending_tasks\` SELECT * FROM ${LOGIN_SERVER_DB}.\`pending_tasks\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_roles\` SELECT * FROM ${LOGIN_SERVER_DB}.\`roles\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_user_backups\` SELECT * FROM ${LOGIN_SERVER_DB}.\`user_backups\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_user_roles\` SELECT * FROM ${LOGIN_SERVER_DB}.\`user_roles\`;
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO \`login_users\` SELECT * FROM ${LOGIN_SERVER_DB}.\`users\`;
|
||||
`)
|
||||
|
||||
// TODO clarify if we need this on non docker environment?
|
||||
await queryFn(`
|
||||
INSERT IGNORE INTO \`login_groups\` (\`id\`, \`alias\`, \`name\`, \`url\`, \`host\`, \`home\`, \`description\`) VALUES
|
||||
(1, 'docker', 'docker gradido group', 'localhost', 'nginx', '/', 'gradido test group for docker and stage2 with blockchain db');
|
||||
`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// write downgrade logic as parameter of queryFn
|
||||
await queryFn(`DELETE FROM \`login_app_access_tokens\`;`)
|
||||
await queryFn(`DELETE FROM \`login_elopage_buys\`;`)
|
||||
await queryFn(`DELETE FROM \`login_email_opt_in_types\`;`)
|
||||
await queryFn(`DELETE FROM \`login_email_opt_in\`;`)
|
||||
await queryFn(`DELETE FROM \`login_groups\`;`)
|
||||
await queryFn(`DELETE FROM \`login_pending_tasks\`;`)
|
||||
await queryFn(`DELETE FROM \`login_roles\`;`)
|
||||
await queryFn(`DELETE FROM \`login_user_backups\`;`)
|
||||
await queryFn(`DELETE FROM \`login_user_roles\`;`)
|
||||
await queryFn(`DELETE FROM \`login_users\`;`)
|
||||
}
|
||||
@ -36,8 +36,6 @@ cd $PROJECT_PATH
|
||||
# git checkout -f master
|
||||
git pull
|
||||
cd deployment/bare_metal
|
||||
echo 'update schemas' >> $UPDATE_HTML
|
||||
./update_db_schemas.sh
|
||||
echo 'starting with rebuilding login-server<br>' >> $UPDATE_HTML
|
||||
./build_and_start_login_server.sh
|
||||
echo 'starting with rebuilding frontend<br>' >> $UPDATE_HTML
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
# For that to work skeema needed to be installed on system
|
||||
# in login_server/skeema skeema configuration files need to be there also in the subfolders
|
||||
# Update DB Schemas (only the schemas, not the data)
|
||||
|
||||
cd ../../login_server/skeema
|
||||
skeema push --allow-unsafe
|
||||
@ -136,22 +136,7 @@ services:
|
||||
- external-net
|
||||
volumes:
|
||||
- /sessions
|
||||
|
||||
#########################################################
|
||||
## skeema for updating dbs if changes happend ###########
|
||||
#########################################################
|
||||
skeema:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./skeema/Dockerfile
|
||||
target: skeema_dev_run
|
||||
depends_on:
|
||||
- mariadb
|
||||
networks:
|
||||
- internal-net
|
||||
volumes:
|
||||
- ./login_server/skeema/gradido_login:/skeema/gradido_login
|
||||
|
||||
|
||||
volumes:
|
||||
frontend_node_modules:
|
||||
backend_node_modules:
|
||||
|
||||
@ -9,7 +9,7 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./mariadb/Dockerfile
|
||||
target: mariadb_server_test
|
||||
target: mariadb_server
|
||||
environment:
|
||||
- MARIADB_ALLOW_EMPTY_PASSWORD=1
|
||||
- MARIADB_USER=root
|
||||
@ -75,19 +75,6 @@ services:
|
||||
- external-net
|
||||
volumes:
|
||||
- /sessions
|
||||
|
||||
#########################################################
|
||||
## skeema for updating dbs if changes happend ###########
|
||||
#########################################################
|
||||
skeema:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./skeema/Dockerfile
|
||||
target: skeema_run
|
||||
depends_on:
|
||||
- mariadb
|
||||
networks:
|
||||
- internal-net
|
||||
|
||||
networks:
|
||||
external-net:
|
||||
|
||||
@ -35,9 +35,8 @@ services:
|
||||
#########################################################
|
||||
mariadb:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./mariadb/Dockerfile
|
||||
target: mariadb_server_test
|
||||
context: ./mariadb
|
||||
target: mariadb_server
|
||||
environment:
|
||||
- MARIADB_ALLOW_EMPTY_PASSWORD=1
|
||||
- MARIADB_USER=root
|
||||
@ -158,41 +157,6 @@ services:
|
||||
- internal-net
|
||||
volumes:
|
||||
- ./community_server/config/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini
|
||||
|
||||
#########################################################
|
||||
## skeema for updating dbs if changes happend ###########
|
||||
#########################################################
|
||||
skeema:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./skeema/Dockerfile
|
||||
target: skeema_run
|
||||
depends_on:
|
||||
- mariadb
|
||||
networks:
|
||||
- internal-net
|
||||
|
||||
#########################################################
|
||||
## GRADIDO NODE v1 ######################################
|
||||
#########################################################
|
||||
# gradido-node:
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile
|
||||
# volumes:
|
||||
# - ${GN_INSTANCE_FOLDER}:/opt/instance
|
||||
# container_name: ${GN_CONTAINER_NAME}
|
||||
|
||||
#########################################################
|
||||
## GRADIDO NODE test ###################################
|
||||
#########################################################
|
||||
# gradido-node-test:
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile
|
||||
# container_name: gn-test
|
||||
# working_dir: /opt/gn/build
|
||||
# command: ["./unit_tests"]
|
||||
|
||||
networks:
|
||||
external-net:
|
||||
|
||||
@ -15,7 +15,7 @@ This document describes the technical overview for the Gradido infrastructur. Be
|
||||
|
||||

|
||||
|
||||
### Database Skeema
|
||||
### Database Skeema (outdated)
|
||||
|
||||

|
||||
|
||||
|
||||
1
login_server/.gitignore
vendored
1
login_server/.gitignore
vendored
@ -5,6 +5,5 @@ src/cpsp/*.h
|
||||
src/cpsp/*.cpp
|
||||
src/cpp/proto/
|
||||
build*/
|
||||
/skeema/gradido_login/insert/crypto_key.sql
|
||||
|
||||
src/LOCALE/messages.pot
|
||||
|
||||
@ -56,8 +56,7 @@ To update messages.pot run
|
||||
This will be also called by ./scripts/build_debug.sh
|
||||
|
||||
## database
|
||||
Login-Server needs a db to run, it is tested with mariadb
|
||||
table definitions are found in folder ./skeema/gradido_login
|
||||
Login-Server needs a db to run, it is tested with mariadb.
|
||||
Currently at least one group must be present in table groups.
|
||||
For example:
|
||||
```sql
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
CREATE TABLE `app_access_tokens` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int NOT NULL,
|
||||
`access_code` bigint unsigned NOT NULL,
|
||||
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `access_code` (`access_code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,15 +0,0 @@
|
||||
CREATE TABLE `elopage_buys` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`elopage_user_id` int DEFAULT NULL,
|
||||
`affiliate_program_id` int NOT NULL,
|
||||
`publisher_id` int NOT NULL,
|
||||
`order_id` int NOT NULL,
|
||||
`product_id` int NOT NULL,
|
||||
`product_price` int NOT NULL,
|
||||
`payer_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
`publisher_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
`payed` tinyint NOT NULL,
|
||||
`success_date` datetime NOT NULL,
|
||||
`event` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,11 +0,0 @@
|
||||
CREATE TABLE `email_opt_in` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int NOT NULL,
|
||||
`verification_code` bigint unsigned NOT NULL,
|
||||
`email_opt_in_type_id` int NOT NULL,
|
||||
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`resend_count` int DEFAULT '0',
|
||||
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `verification_code` (`verification_code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,6 +0,0 @@
|
||||
CREATE TABLE `email_opt_in_types` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`description` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,11 +0,0 @@
|
||||
CREATE TABLE `groups` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`alias` varchar(190) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`url` varchar(255) NOT NULL,
|
||||
`host` varchar(255) DEFAULT "/",
|
||||
`home` varchar(255) DEFAULT "/",
|
||||
`description` text,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `alias` (`alias`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,13 +0,0 @@
|
||||
CREATE TABLE `pending_tasks` (
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int UNSIGNED DEFAULT 0,
|
||||
`request` varbinary(2048) NOT NULL,
|
||||
`created` datetime NOT NULL,
|
||||
`finished` datetime DEFAULT '2000-01-01 000000',
|
||||
`result_json` text DEFAULT NULL,
|
||||
`param_json` text DEFAULT NULL,
|
||||
`task_type_id` int UNSIGNED NOT NULL,
|
||||
`child_pending_task_id` int UNSIGNED DEFAULT 0,
|
||||
`parent_pending_task_id` int UNSIGNED DEFAULT 0,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,7 +0,0 @@
|
||||
CREATE TABLE `roles` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`description` varchar(255) NOT NULL,
|
||||
`flags` bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,7 +0,0 @@
|
||||
CREATE TABLE `user_backups` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int NOT NULL,
|
||||
`passphrase` text NOT NULL,
|
||||
`mnemonic_type` int DEFAULT '-1',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,6 +0,0 @@
|
||||
CREATE TABLE `user_roles` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int NOT NULL,
|
||||
`role_id` int NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,21 +0,0 @@
|
||||
CREATE TABLE `users` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`email` varchar(191) NOT NULL,
|
||||
`first_name` varchar(150) NOT NULL,
|
||||
`last_name` varchar(255) DEFAULT '',
|
||||
`username` varchar(255) DEFAULT '',
|
||||
`description` text DEFAULT '',
|
||||
`password` bigint unsigned DEFAULT '0',
|
||||
`pubkey` binary(32) DEFAULT NULL,
|
||||
`privkey` binary(80) DEFAULT NULL,
|
||||
`email_hash` binary(32) DEFAULT NULL,
|
||||
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`email_checked` tinyint NOT NULL DEFAULT '0',
|
||||
`passphrase_shown` tinyint NOT NULL DEFAULT '0',
|
||||
`language` varchar(4) NOT NULL DEFAULT 'de',
|
||||
`disabled` tinyint DEFAULT '0',
|
||||
`group_id` int unsigned DEFAULT 0,
|
||||
`publisher_id` int DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `email` (`email`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -58,7 +58,7 @@ bool EmailManager::init(const Poco::Util::LayeredConfiguration& cfg)
|
||||
void EmailManager::addEmail(model::Email* email) {
|
||||
if (mDisableEmail) {
|
||||
std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S");
|
||||
std::string log_message = dateTimeString + " Email should be sended to: ";
|
||||
std::string log_message = dateTimeString + " Email should have been sent to: ";
|
||||
auto email_user = email->getUser();
|
||||
Poco::AutoPtr<model::table::User> email_model;
|
||||
if (email_user) {
|
||||
|
||||
@ -148,7 +148,7 @@ Session* SessionManager::getNewSession(int* handle)
|
||||
mWorkingMutex.tryLock(500);
|
||||
}
|
||||
catch (Poco::TimeoutException &ex) {
|
||||
printf("[%s] exception timout mutex: %s\n", functionName, ex.displayText().data());
|
||||
printf("[%s] exception timeout mutex: %s\n", functionName, ex.displayText().data());
|
||||
return nullptr;
|
||||
}
|
||||
//mWorkingMutex.lock();
|
||||
|
||||
@ -439,6 +439,7 @@ namespace controller {
|
||||
return 0;
|
||||
auto cm = ConnectionManager::getInstance();
|
||||
auto em = ErrorManager::getInstance();
|
||||
auto db = new model::table::User();
|
||||
static const char* function_name = "User::checkIfVerificationEmailsShouldBeResend";
|
||||
|
||||
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
|
||||
@ -446,8 +447,9 @@ namespace controller {
|
||||
std::vector<Poco::Tuple<int,Poco::DateTime>> results;
|
||||
int email_checked = 0;
|
||||
int resend_count = 1;
|
||||
select << "select u.id, v.created from users as u "
|
||||
<< "LEFT JOIN email_opt_in as v ON(u.id = v.user_id) "
|
||||
std::string table_name_email_opt_in = "login_email_opt_in";
|
||||
select << "select u.id, v.created from " << db->getTableName() << " as u "
|
||||
<< "LEFT JOIN " << table_name_email_opt_in << " as v ON(u.id = v.user_id) "
|
||||
<< "where u.email_checked = ? "
|
||||
<< "AND v.resend_count <= ? "
|
||||
<< "ORDER BY u.id, v.created " ,
|
||||
@ -519,14 +521,15 @@ namespace controller {
|
||||
{
|
||||
auto cm = ConnectionManager::getInstance();
|
||||
auto em = ErrorManager::getInstance();
|
||||
auto db = new model::table::User();
|
||||
static const char* function_name = "User::addMissingEmailHashes";
|
||||
|
||||
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
|
||||
Poco::Data::Statement select(session);
|
||||
std::vector<Poco::Tuple<int, std::string>> results;
|
||||
|
||||
select << "select id, email from users "
|
||||
<< "where email_hash IS NULL "
|
||||
select << "select id, email from " << db->getTableName()
|
||||
<< " where email_hash IS NULL "
|
||||
, Poco::Data::Keywords::into(results)
|
||||
;
|
||||
int result_count = 0;
|
||||
@ -556,7 +559,7 @@ namespace controller {
|
||||
// update db
|
||||
// reuse connection, I hope it's working
|
||||
Poco::Data::Statement update(session);
|
||||
update << "UPDATE users set email_hash = ? where id = ?"
|
||||
update << "UPDATE " << db->getTableName() << " set email_hash = ? where id = ?"
|
||||
, Poco::Data::Keywords::use(updates);
|
||||
int updated_count = 0;
|
||||
try {
|
||||
|
||||
@ -19,7 +19,7 @@ namespace model {
|
||||
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "app_access_tokens"; }
|
||||
const char* getTableName() const { return "login_app_access_tokens"; }
|
||||
std::string toString();
|
||||
|
||||
inline Poco::UInt64 getCode() const { return mAccessCode; }
|
||||
|
||||
@ -34,7 +34,7 @@ namespace model {
|
||||
ElopageBuy();
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "elopage_buys"; }
|
||||
const char* getTableName() const { return "login_elopage_buys"; }
|
||||
|
||||
std::string toString();
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ namespace model {
|
||||
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "email_opt_in"; }
|
||||
const char* getTableName() const { return "login_email_opt_in"; }
|
||||
std::string toString();
|
||||
|
||||
inline Poco::UInt64 getCode() const { return mEmailVerificationCode; }
|
||||
|
||||
@ -17,7 +17,7 @@ namespace model {
|
||||
Group(GroupTuple userTuple);
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "groups"; }
|
||||
const char* getTableName() const { return "login_groups"; }
|
||||
std::string toString();
|
||||
|
||||
inline const std::string& getAlias() const { return mAlias; }
|
||||
|
||||
@ -30,7 +30,7 @@ namespace model {
|
||||
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "pending_tasks"; }
|
||||
const char* getTableName() const { return "login_pending_tasks"; }
|
||||
std::string toString();
|
||||
|
||||
//! \brief update table row with current request
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_ROLES_INCLUDE
|
||||
#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_ROLES_INCLUDE
|
||||
|
||||
#include "ModelBase.h"
|
||||
#include "Poco/Types.h"
|
||||
#include "Poco/Tuple.h"
|
||||
|
||||
namespace model {
|
||||
namespace table {
|
||||
|
||||
enum RoleType {
|
||||
ROLE_ADMIN = 1
|
||||
};
|
||||
|
||||
class Roles : public ModelBase
|
||||
{
|
||||
|
||||
};
|
||||
/*
|
||||
typedef Poco::Tuple<int, int, Poco::UInt64, int> EmailOptInTuple;
|
||||
|
||||
class EmailOptIn : public ModelBase
|
||||
{
|
||||
public:
|
||||
EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type);
|
||||
EmailOptIn(const Poco::UInt64& code, EmailOptInType type);
|
||||
EmailOptIn(const EmailOptInTuple& tuple);
|
||||
EmailOptIn();
|
||||
~EmailOptIn();
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() { return "email_opt_in"; }
|
||||
std::string toString();
|
||||
|
||||
inline Poco::UInt64 getCode() const { return mEmailVerificationCode; }
|
||||
inline int getUserId() const { return mUserId; }
|
||||
inline EmailOptInType getType() const { return static_cast<EmailOptInType>(mType); }
|
||||
inline void setCode(Poco::UInt64 code) { mEmailVerificationCode = code; }
|
||||
inline void setUserId(int user_Id) { mUserId = user_Id; }
|
||||
|
||||
static const char* typeToString(EmailOptInType type);
|
||||
protected:
|
||||
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
|
||||
Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session);
|
||||
Poco::Data::Statement _loadMultipleFromDB(Poco::Data::Session session, const std::string& fieldName);
|
||||
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::vector<std::string>& fieldNames, MysqlConditionType conditionType = MYSQL_CONDITION_AND);
|
||||
Poco::Data::Statement _insertIntoDB(Poco::Data::Session session);
|
||||
|
||||
int mUserId;
|
||||
// data type must be a multiple of 4
|
||||
Poco::UInt64 mEmailVerificationCode;
|
||||
int mType;
|
||||
|
||||
};
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_ROLES_INCLUDE
|
||||
@ -83,11 +83,11 @@ namespace model {
|
||||
|
||||
|
||||
if (mPasswordHashed) {
|
||||
insert << "INSERT INTO users (email, first_name, last_name, username, description, password, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?,?);",
|
||||
insert << "INSERT INTO " << getTableName() << " (email, first_name, last_name, username, description, password, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?,?);",
|
||||
use(mEmail), use(mFirstName), use(mLastName), use(mUsername), use(mDescription), bind(mPasswordHashed), use(mEmailHash), use(mLanguageKey), use(mGroupId), use(mPublisherId);
|
||||
}
|
||||
else {
|
||||
insert << "INSERT INTO users (email, first_name, last_name, username, description, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?);",
|
||||
insert << "INSERT INTO " << getTableName() << " (email, first_name, last_name, username, description, email_hash, language, group_id, publisher_id) VALUES(?,?,?,?,?,?,?,?,?);",
|
||||
use(mEmail), use(mFirstName), use(mLastName), use(mUsername), use(mDescription), use(mEmailHash), use(mLanguageKey), use(mGroupId), use(mPublisherId);
|
||||
|
||||
}
|
||||
@ -103,10 +103,13 @@ namespace model {
|
||||
}
|
||||
Poco::Data::Statement select(session);
|
||||
|
||||
select << "SELECT " << getTableName() << ".id, email, first_name, last_name, username, description, password, pubkey, privkey, email_hash, created, email_checked, language, disabled, group_id, publisher_id, user_roles.role_id "
|
||||
std::string table_name_user_roles = "login_user_roles";
|
||||
|
||||
select << "SELECT " << getTableName() << ".id, email, first_name, last_name, username, description, password, pubkey, privkey, email_hash, created, email_checked, language, disabled, group_id, publisher_id, " << table_name_user_roles << ".role_id "
|
||||
<< " FROM " << getTableName()
|
||||
<< " LEFT JOIN user_roles ON " << getTableName() << ".id = user_roles.user_id "
|
||||
<< " WHERE " << _fieldName << " = ?" ,
|
||||
<< " LEFT JOIN " << table_name_user_roles
|
||||
<< " ON " << getTableName() << ".id = " << table_name_user_roles << ".user_id "
|
||||
<< " WHERE " << _fieldName << " = ?; " ,
|
||||
into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mUsername), into(mDescription), into(mPasswordHashed),
|
||||
into(mPublicKey), into(mPrivateKey), into(mEmailHash), into(mCreated), into(mEmailChecked),
|
||||
into(mLanguageKey), into(mDisabled), into(mGroupId), into(mPublisherId), into(mRole);
|
||||
@ -194,7 +197,7 @@ namespace model {
|
||||
|
||||
Poco::Data::Statement update(session);
|
||||
|
||||
update << "UPDATE users SET password = ?, privkey = ? where id = ?;",
|
||||
update << "UPDATE " << getTableName() << " SET password = ?, privkey = ? where id = ?;",
|
||||
bind(mPasswordHashed), use(mPrivateKey), use(mID);
|
||||
|
||||
|
||||
@ -221,7 +224,7 @@ namespace model {
|
||||
|
||||
Poco::Data::Statement update(session);
|
||||
|
||||
update << "UPDATE users SET pubkey = ?, privkey = ? where id = ?;",
|
||||
update << "UPDATE " << getTableName() << " SET pubkey = ?, privkey = ? where id = ?;",
|
||||
use(mPublicKey), use(mPrivateKey), use(mID);
|
||||
|
||||
|
||||
@ -246,7 +249,7 @@ namespace model {
|
||||
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
|
||||
|
||||
Poco::Data::Statement update(session);
|
||||
update << "UPDATE users SET first_name = ?, last_name = ?, username = ?, description = ?, disabled = ?, language = ?, publisher_id = ? where id = ?;",
|
||||
update << "UPDATE " << getTableName() << " SET first_name = ?, last_name = ?, username = ?, description = ?, disabled = ?, language = ?, publisher_id = ? where id = ?;",
|
||||
use(mFirstName), use(mLastName), use(mUsername), use(mDescription), use(mDisabled), use(mLanguageKey), use(mPublisherId), use(mID);
|
||||
|
||||
try {
|
||||
|
||||
@ -54,7 +54,7 @@ namespace model {
|
||||
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "users"; }
|
||||
const char* getTableName() const { return "login_users"; }
|
||||
std::string toString();
|
||||
std::string toHTMLString();
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ namespace model {
|
||||
UserBackup();
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "user_backups"; }
|
||||
const char* getTableName() const { return "login_user_backups"; }
|
||||
std::string toString();
|
||||
|
||||
inline int getUserId() const { return mUserId; }
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include "ModelBase.h"
|
||||
#include "Poco/Types.h"
|
||||
#include "Poco/Tuple.h"
|
||||
//#include "Roles.h"
|
||||
|
||||
namespace model {
|
||||
namespace table {
|
||||
@ -25,7 +24,7 @@ namespace model {
|
||||
UserRole();
|
||||
|
||||
// generic db operations
|
||||
const char* getTableName() const { return "user_roles"; }
|
||||
const char* getTableName() const { return "login_user_roles"; }
|
||||
std::string toString();
|
||||
|
||||
inline int getUserId() const { return mUserId; }
|
||||
|
||||
@ -176,9 +176,9 @@ int load(int argc, char* argv[]) {
|
||||
|
||||
// clean up and fill db
|
||||
std::string tables[] = {
|
||||
"groups",
|
||||
"users",
|
||||
"user_roles"
|
||||
"login_groups",
|
||||
"login_users",
|
||||
"login_user_roles"
|
||||
};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (runMysql("TRUNCATE " + tables[i])) {
|
||||
@ -191,7 +191,7 @@ int load(int argc, char* argv[]) {
|
||||
|
||||
std::stringstream ss;
|
||||
// password = TestP4ssword&H
|
||||
ss << "INSERT INTO `users` (`id`, `email`, `first_name`, `last_name`, `username`, `password`, `pubkey`, `privkey`, `created`, `email_checked`, `passphrase_shown`, `language`, `disabled`, `group_id`) VALUES "
|
||||
ss << "INSERT INTO `login_users` (`id`, `email`, `first_name`, `last_name`, `username`, `password`, `pubkey`, `privkey`, `created`, `email_checked`, `passphrase_shown`, `language`, `disabled`, `group_id`) VALUES "
|
||||
<< "(1, 'd_schultz32@gmx.de', 'DDD', 'Schultz', 'Diddel', 18242007140018938940, 0x69f2fefd6fa6947a370b9f8d3147f6617cf67416517ce25cb2d63901c666933c, 0x567f3e623a1899d1f8d69190c5799433c134ce0137c0c38cc0347874586d6234a19f2a0b484e6cc1863502e580ae6c17db1131f29a35eba45a46be29c7ee592940a3bd3ad519075fdeed6e368f0eb818, '2020-02-20 16:05:44', 1, 0, 'de', 0, 1), ";
|
||||
|
||||
// if this isn't the same, some tests will fail, so we update the test data here.
|
||||
@ -211,7 +211,7 @@ int load(int argc, char* argv[]) {
|
||||
}
|
||||
ss.str(std::string());
|
||||
|
||||
ss << "INSERT INTO `user_roles` (`id`, `user_id`, `role_id`) VALUES"
|
||||
ss << "INSERT INTO `login_user_roles` (`id`, `user_id`, `role_id`) VALUES"
|
||||
<< "(1, 3, 1);";
|
||||
|
||||
if (runMysql(ss.str())) {
|
||||
@ -219,7 +219,7 @@ int load(int argc, char* argv[]) {
|
||||
}
|
||||
ss.str(std::string());
|
||||
|
||||
ss << "INSERT INTO `groups` (`id`, `alias`, `name`, `url`, `description`) VALUES"
|
||||
ss << "INSERT INTO `login_groups` (`id`, `alias`, `name`, `url`, `description`) VALUES"
|
||||
<< "(1, 'gdd1', 'Gradido1', 'gdd1.gradido.com', 'Der erste offizielle Gradido Server (zum Testen)'), "
|
||||
<< "(2, 'gdd_test', 'Gradido Test', 'gdd1.gradido.com', 'Testgroup (zum Testen)'); ";
|
||||
if (runMysql(ss.str())) {
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
[production]
|
||||
flavor=mariadb:10.5
|
||||
host=127.0.0.1
|
||||
port=3306
|
||||
user=root
|
||||
@ -1,3 +0,0 @@
|
||||
default-character-set=utf8mb4
|
||||
default-collation=utf8mb4_unicode_ci
|
||||
schema=gradido_login
|
||||
@ -3,29 +3,7 @@
|
||||
#########################################################################################################
|
||||
FROM mariadb/server:10.5 as mariadb_server
|
||||
|
||||
ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d"
|
||||
# ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d"
|
||||
|
||||
RUN mkdir -p ${DOCKER_WORKDIR}
|
||||
WORKDIR ${DOCKER_WORKDIR}
|
||||
|
||||
# create databases
|
||||
COPY ./mariadb/setup_dbs.sql a1_setup_dbs.sql
|
||||
# login server db
|
||||
COPY ./login_server/skeema/ .
|
||||
RUN cd ./gradido_login/ && for f in *.sql; do cp -- "$f" "../b1_$f"; sed -i '1i use gradido_login;' "../b1_$f"; done
|
||||
COPY ./configs/login_server/setup_db_tables ./gradido_login/insert
|
||||
RUN cd ./gradido_login/insert && for f in *.sql; do cp -- "$f" "../../c1_$f"; sed -i '1i use gradido_login;' "../../c1_$f"; done
|
||||
|
||||
#########################################################################################################
|
||||
# mariadb server with test dbs
|
||||
#########################################################################################################
|
||||
FROM mariadb_server as mariadb_server_test
|
||||
|
||||
# create test databases
|
||||
COPY ./mariadb/setup_test_dbs.sql a2_setup_dbs.sql
|
||||
|
||||
# login server test db
|
||||
COPY ./login_server/skeema/ .
|
||||
RUN cd ./gradido_login/ && for f in *.sql; do cp -- "$f" "../b2_$f"; sed -i '1i use gradido_login_test;' "../b2_$f"; done
|
||||
COPY ./configs/login_server/setup_db_tables ./gradido_login/insert
|
||||
RUN cd ./gradido_login/insert && for f in *.sql; do cp -- "$f" "../../c2_$f"; sed -i '1i use gradido_login_test;' "../../c2_$f"; done
|
||||
# RUN mkdir -p ${DOCKER_WORKDIR}
|
||||
# WORKDIR ${DOCKER_WORKDIR}
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
create database gradido_login
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
create database IF NOT EXISTS _skeema_tmp
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
FLUSH PRIVILEGES;
|
||||
@ -1,55 +0,0 @@
|
||||
#!/bin/bash
|
||||
COLOR_GREEN="\033[0;32m"
|
||||
COLOR_YELLOW="\e[33m"
|
||||
COLOR_NONE="\033[0m"
|
||||
|
||||
LOGIN_DB_USER=gradido_login_live
|
||||
LOGIN_DB_NAME=gradido_login_live
|
||||
LOGIN_DB_PASSWD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo);
|
||||
|
||||
COMMUNITY_DB_USER=gradido_community_live
|
||||
COMMUNITY_DB_NAME=gradido_community_live
|
||||
COMMUNITY_DB_PASSWD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo);
|
||||
|
||||
# create table
|
||||
mysql <<EOFMYSQL
|
||||
create database $LOGIN_DB_NAME
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
create database $COMMUNITY_DB_NAME
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
create database IF NOT EXISTS _skeema_tmp
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
CREATE USER '$LOGIN_DB_USER'@'localhost' IDENTIFIED BY '$LOGIN_DB_PASSWD';
|
||||
GRANT ALL PRIVILEGES ON $LOGIN_DB_NAME.* TO '$LOGIN_DB_USER'@'localhost';
|
||||
GRANT ALL PRIVILEGES ON _skeema_tmp.* TO '$LOGIN_DB_USER'@'localhost';
|
||||
|
||||
CREATE USER '$COMMUNITY_DB_USER'@'localhost' IDENTIFIED BY '$COMMUNITY_DB_PASSWD';
|
||||
GRANT ALL PRIVILEGES ON $COMMUNITY_DB_NAME.* TO '$COMMUNITY_DB_USER'@'localhost';
|
||||
GRANT ALL PRIVILEGES ON _skeema_tmp.* TO '$COMMUNITY_DB_USER'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
||||
EOFMYSQL
|
||||
|
||||
# populate db of login-server
|
||||
cd ../login_server/skeema
|
||||
sudo cat << EOF > .skeema
|
||||
[production]
|
||||
flavor=mariadb:10.3.25
|
||||
host=127.0.0.1
|
||||
port=3306
|
||||
user=$LOGIN_DB_USER
|
||||
EOF
|
||||
cd gradido_login
|
||||
sudo cat << EOF > .skeema
|
||||
default-character-set=utf8mb4
|
||||
default-collation=utf8mb4_unicode_ci
|
||||
schema=$LOGIN_DB_NAME
|
||||
EOF
|
||||
|
||||
source $HOME/.gvm/scripts/gvm
|
||||
gvm use go1.14.4
|
||||
skeema push -p$LOGIN_DB_PASSWD
|
||||
|
||||
echo -e "${COLOR_YELLOW}Login-Server db password: $LOGIN_DB_PASSWD${COLOR_NONE}"
|
||||
@ -1,10 +0,0 @@
|
||||
create database gradido_login_test
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
create database gradido_community_test
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
create database IF NOT EXISTS _skeema_tmp
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
FLUSH PRIVILEGES;
|
||||
@ -1,5 +0,0 @@
|
||||
[production]
|
||||
flavor=mariadb:10.5
|
||||
host=mariadb
|
||||
port=3306
|
||||
user=root
|
||||
@ -1,39 +0,0 @@
|
||||
#########################################################################################################
|
||||
# Build skeema
|
||||
#########################################################################################################
|
||||
FROM golang:1.17.1 as skeema_build
|
||||
RUN go get -d -v github.com/skeema/skeema
|
||||
WORKDIR /go/src/github.com/skeema/skeema
|
||||
RUN go install github.com/skeema/skeema@v1.5.3
|
||||
|
||||
#########################################################################################################
|
||||
# Run skeema for dev (dynamic)
|
||||
#########################################################################################################
|
||||
FROM skeema_build as skeema_dev_run
|
||||
|
||||
ENV DOCKER_WORKDIR="/skeema"
|
||||
|
||||
RUN mkdir -p ${DOCKER_WORKDIR}
|
||||
WORKDIR ${DOCKER_WORKDIR}
|
||||
|
||||
COPY ./skeema/.skeema .
|
||||
COPY ./mariadb/.skeema.login .
|
||||
|
||||
CMD cp .skeema.login ./gradido_login/.skeema && skeema push --allow-unsafe && rm ./gradido_login/.skeema
|
||||
|
||||
#########################################################################################################
|
||||
# Run skeema
|
||||
#########################################################################################################
|
||||
FROM skeema_build as skeema_run
|
||||
|
||||
ENV DOCKER_WORKDIR="/skeema"
|
||||
|
||||
RUN mkdir -p ${DOCKER_WORKDIR}
|
||||
WORKDIR ${DOCKER_WORKDIR}
|
||||
|
||||
COPY ./skeema/.skeema .
|
||||
COPY ./login_server/skeema/ .
|
||||
COPY ./mariadb/.skeema.login ./gradido_login/.skeema
|
||||
|
||||
CMD skeema push --allow-unsafe
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user