remove db_name configuration

This commit is contained in:
Daniel Seifert 2024-11-01 21:49:52 +01:00
parent d98a79efce
commit 05b7443a3a
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
3 changed files with 10 additions and 9 deletions

View File

@ -7,8 +7,7 @@ set('db_conf_path', function () {
}); });
set('database_configured', function() { set('database_configured', function() {
return has('db_name') && strlen(get('db_name')) && return has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]");
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]");
}); });
set('mysql_configured', function() { set('mysql_configured', function() {
@ -20,4 +19,3 @@ set('mysqldump_configured', function() {
return has('bin/mysql') && strlen(get('bin/mysql')) && return has('bin/mysql') && strlen(get('bin/mysql')) &&
get('database_configured'); get('database_configured');
}); });

View File

@ -22,9 +22,10 @@ task('setup:createDbConfig', function () {
if (test("[ -f {{db_conf_path}} ]")) { if (test("[ -f {{db_conf_path}} ]")) {
$db_host = ask('database host', 'localhost'); $db_host = ask('database host', 'localhost');
$db_port = ask('database port', '3306'); $db_port = ask('database port', '3306');
$db_name = ask('database name');
$db_user = ask('database user'); $db_user = ask('database user');
$db_pass = askHiddenResponse('database password'); $db_pass = askHiddenResponse('database password');
run('printf "[mysql]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\nhost='.$db_host.'\nport='.$db_port.'\n\n[mysqldump]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\nhost='.$db_host.'\nport='.$db_port.'" > {{db_conf_path}}'); run('printf "[mysql]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\ndatabase=\"'.$db_name.'\"\nhost='.$db_host.'\nport='.$db_port.'\n\n[mysqldump]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\ndatabase=\"'.$db_name.'\"\nhost='.$db_host.'\nport='.$db_port.'" > {{db_conf_path}}');
info('config successful created'); info('config successful created');
} else { } else {
throw new \RuntimeException('can not create {{db_conf_path}}, task stopped'); throw new \RuntimeException('can not create {{db_conf_path}}, task stopped');
@ -32,4 +33,4 @@ task('setup:createDbConfig', function () {
} catch(\RuntimeException $e) { } catch(\RuntimeException $e) {
warning($e->getMessage()); warning($e->getMessage());
} }
}); });

View File

@ -9,13 +9,14 @@ task('shop:runMigration', [
'shop:setShopsOnline' 'shop:setShopsOnline'
]); ]);
require_once 'inc/database.php'; require_once 'inc/database.php';
desc('set shops offline'); desc('set shops offline');
task('shop:setShopsOffline', function() { task('shop:setShopsOffline', function() {
if (get('mysql_configured')) { if (get('mysql_configured')) {
$query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';"; $query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';";
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"'); run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} -e "'.$query.'"');
} else { } else {
warning('missing config, task skipped'); warning('missing config, task skipped');
} }
@ -38,7 +39,7 @@ desc('set shops online');
task('shop:setShopsOnline', function() { task('shop:setShopsOnline', function() {
if (get('mysql_configured')) { if (get('mysql_configured')) {
$query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';"; $query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';";
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"'); run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} -e "'.$query.'"');
} else { } else {
warning('missing config, task skipped'); warning('missing config, task skipped');
} }
@ -66,10 +67,11 @@ task('shop:cloneDatabase', function () {
$source_name = ask('source database name'); $source_name = ask('source database name');
$source_user = ask('source database user'); $source_user = ask('source database user');
$source_pass = askHiddenResponse('source database password'); $source_pass = askHiddenResponse('source database password');
if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "{{db_name}}"? The target database "{{db_name}}" will be overwritten!')) { $target_name = parse_ini_file(get('db_conf_path'))['database'];
if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "'.$target_name.'"? The target database "'.$target_name.'" will be overwritten!')) {
info('cloning database'); info('cloning database');
$auth = "-h".$source_host." -P".$source_port." -u".$source_user." -p'".$source_pass."'"; $auth = "-h".$source_host." -P".$source_port." -u".$source_user." -p'".$source_pass."'";
run("{{bin/mysqldump}} ".$auth." --opt --no-create-db -f ".$source_name." $({{bin/mysql}} ".$auth." -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") | {{bin/mysql}} --defaults-extra-file={{db_conf_path}} -f {{db_name}}"); run("{{bin/mysqldump}} ".$auth." --opt --no-create-db -f ".$source_name." $({{bin/mysql}} ".$auth." -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") | {{bin/mysql}} --defaults-extra-file={{db_conf_path}} -f");
info('creating views'); info('creating views');
run('{{release_or_current_path}}/vendor/bin/oe-eshop-db_views_regenerate'); run('{{release_or_current_path}}/vendor/bin/oe-eshop-db_views_regenerate');
info('successfully finished'); info('successfully finished');