mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added new/missing parameters to pg_restore. #6562
This commit is contained in:
@@ -331,6 +331,7 @@ def _get_args_params_values(data, conn, backup_obj_type, backup_file, server,
|
||||
set_param('verbose', '--verbose')
|
||||
set_param('dqoute', '--quote-all-identifiers')
|
||||
set_param('use_set_session_auth', '--use-set-session-authorization')
|
||||
set_value('exclude_schema', '--exclude-schema')
|
||||
set_value('extra_float_digits', '--extra-float-digits', None,
|
||||
manager.version >= 120000)
|
||||
set_value('lock_wait_timeout', '--lock-wait-timeout')
|
||||
|
||||
@@ -379,6 +379,21 @@ export class MiscellaneousSchema extends BaseUISchema {
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous'),
|
||||
inlineNext: true,
|
||||
}, {
|
||||
id: 'exclude_schema',
|
||||
label: gettext('Exclude schema'),
|
||||
type: 'text',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous'),
|
||||
visible: isVisibleForServerBackup(obj?._top?.backupType)
|
||||
}, {
|
||||
id: 'exclude_database',
|
||||
label: gettext('Exclude database'),
|
||||
type: 'text',
|
||||
disabled: false,
|
||||
min_version: 160000,
|
||||
group: gettext('Miscellaneous'),
|
||||
visible: isVisibleForObjectBackup(obj?._top?.backupType)
|
||||
}, {
|
||||
id: 'extra_float_digits',
|
||||
label: gettext('Extra float digits'),
|
||||
@@ -392,14 +407,6 @@ export class MiscellaneousSchema extends BaseUISchema {
|
||||
type: 'int',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous')
|
||||
}, {
|
||||
id: 'exclude_database',
|
||||
label: gettext('Exclude database'),
|
||||
type: 'text',
|
||||
disabled: false,
|
||||
min_version: 160000,
|
||||
group: gettext('Miscellaneous'),
|
||||
visible: isVisibleForObjectBackup(obj.backupType)
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -569,7 +576,7 @@ export default class BackupSchema extends BaseUISchema {
|
||||
state.on_conflict_do_nothing = false;
|
||||
return true;
|
||||
},
|
||||
inlineNext: true,
|
||||
inlineNext: obj.backupType == 'server'? false : true,
|
||||
}, {
|
||||
id: 'include_create_database',
|
||||
label: gettext('Include CREATE DATABASE statement'),
|
||||
@@ -691,6 +698,15 @@ export default class BackupSchema extends BaseUISchema {
|
||||
label: gettext('Miscellaneous'),
|
||||
group: gettext('Options'),
|
||||
schema: obj.getMiscellaneousSchema(),
|
||||
}, {
|
||||
id: 'objects',
|
||||
label: gettext('objects'),
|
||||
group: gettext('Objects'),
|
||||
type: 'tree',
|
||||
visible: () => {
|
||||
return isVisibleForServerBackup(obj?.backupType);
|
||||
},
|
||||
tree_type: 'checkbox'
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@@ -538,6 +538,31 @@ class BackupCreateJobTest(BaseTestGenerator):
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
('When backup the object with option - Exclude schema',
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
name='test_backup_server',
|
||||
port=5444,
|
||||
host='localhost',
|
||||
database='postgres',
|
||||
bfile='test_backup',
|
||||
username='postgres'
|
||||
),
|
||||
params=dict(
|
||||
file='test_backup_file',
|
||||
format='custom',
|
||||
verbose=True,
|
||||
schemas=[],
|
||||
tables=[],
|
||||
database='postgres',
|
||||
exclude_schema="sch*"
|
||||
),
|
||||
url=BACKUP_OBJECT_URL,
|
||||
expected_cmd_opts=[VERBOSE, '--exclude-schema', 'sch*'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
('When backup the object with option - Extra float digits',
|
||||
dict(
|
||||
class_params=dict(
|
||||
|
||||
@@ -10,21 +10,17 @@
|
||||
"""Implements Restore Utility"""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
from flask import render_template, request, current_app, \
|
||||
url_for, Response
|
||||
from flask import render_template, request, current_app, Response
|
||||
from flask_babel import gettext as _
|
||||
from flask_security import login_required, current_user
|
||||
from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
|
||||
from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
|
||||
fs_short_path, document_dir, does_utility_exist, get_server, \
|
||||
filename_with_file_manager_path
|
||||
from pgadmin.utils import PgAdminModule, fs_short_path, does_utility_exist, \
|
||||
get_server, filename_with_file_manager_path
|
||||
from pgadmin.utils.ajax import make_json_response, bad_request, \
|
||||
internal_server_error
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.model import Server, SharedServer
|
||||
from pgadmin.utils.constants import MIMETYPE_APP_JS
|
||||
|
||||
# set template path for sql scripts
|
||||
@@ -294,33 +290,50 @@ def _set_args_param_values(data, manager, server, driver, conn, _file):
|
||||
|
||||
if data['format'] == 'directory':
|
||||
args.extend(['--format=d'])
|
||||
set_value('no_of_jobs', '--jobs', data, args)
|
||||
|
||||
# Sections
|
||||
set_param('pre_data', '--section=pre-data', data, args)
|
||||
set_param('data', '--section=data', data, args)
|
||||
set_param('post_data', '--section=post-data', data, args)
|
||||
|
||||
# Do not Save
|
||||
if not set_param('only_data', '--data-only', data, args):
|
||||
set_param('dns_owner', '--no-owner', data, args)
|
||||
set_param('dns_privilege', '--no-privileges', data, args)
|
||||
set_param('dns_tablespace', '--no-tablespaces', data, args)
|
||||
if manager.version >= 110000:
|
||||
set_param('dns_comments', '--no-comments', data, args)
|
||||
set_param('dns_publications', '--no-publications', data, args)
|
||||
set_param('dns_subscriptions', '--no-subscriptions', data,
|
||||
args)
|
||||
set_param('dns_security_labels', '--no-security-labels', data,
|
||||
args)
|
||||
if manager.version >= 150000:
|
||||
set_param('dns_table_access_method',
|
||||
'--no-table-access-method', data, args)
|
||||
|
||||
# Query Options
|
||||
set_param('include_create_database', '--create', data, args)
|
||||
set_param('clean', '--clean', data, args)
|
||||
set_param('if_exists', '--if-exists', data, args)
|
||||
set_param('single_transaction', '--single-transaction', data, args)
|
||||
|
||||
# Table options
|
||||
set_param('enable_row_security', '--enable-row-security', data, args)
|
||||
set_param('no_data_fail_table', '--no-data-for-failed-tables', data,
|
||||
args)
|
||||
|
||||
# Disable options
|
||||
if not set_param('only_schema', '--schema-only', data, args):
|
||||
set_param('disable_trigger', '--disable-triggers', data, args)
|
||||
|
||||
set_param('include_create_database', '--create', data, args)
|
||||
set_param('clean', '--clean', data, args)
|
||||
set_param('single_transaction', '--single-transaction', data, args)
|
||||
set_param('no_data_fail_table', '--no-data-for-failed-tables', data,
|
||||
args)
|
||||
# Misc Options
|
||||
set_param('verbose', '--verbose', data, args)
|
||||
set_param('use_set_session_auth', '--use-set-session-authorization',
|
||||
data, args)
|
||||
set_param('exit_on_error', '--exit-on-error', data, args)
|
||||
|
||||
if manager.version >= 110000:
|
||||
set_param('no_comments', '--no-comments', data, args)
|
||||
|
||||
set_value('no_of_jobs', '--jobs', data, args)
|
||||
set_param('verbose', '--verbose', data, args)
|
||||
set_value('exclude_schema', '--exclude-schema', data, args)
|
||||
|
||||
set_multiple('schemas', '--schema', data, args, driver, conn, False)
|
||||
set_multiple('tables', '--table', data, args, driver, conn, False)
|
||||
|
||||
@@ -12,7 +12,7 @@ import {getUtilityView} from '../../../../browser/static/js/utility_view';
|
||||
import Notify from '../../../../static/js/helpers/Notifier';
|
||||
import getApiInstance from 'sources/api_instance';
|
||||
import {retrieveAncestorOfTypeServer} from 'sources/tree/tree_utils';
|
||||
import RestoreSchema, {getRestoreSaveOptSchema, getRestoreQueryOptionSchema, getRestoreDisableOptionSchema, getRestoreMiscellaneousSchema, getRestoreTypeObjSchema, getRestoreSectionSchema} from './restore.ui';
|
||||
import RestoreSchema, {getRestoreSaveOptSchema, getRestoreDisableOptionSchema, getRestoreMiscellaneousSchema, getRestoreTypeObjSchema, getRestoreSectionSchema} from './restore.ui';
|
||||
|
||||
define('tools.restore', [
|
||||
'sources/gettext', 'sources/url_for', 'pgadmin.browser',
|
||||
@@ -79,7 +79,6 @@ define('tools.restore', [
|
||||
()=>getRestoreSectionSchema({selectedNodeType: itemNodeData._type}),
|
||||
()=>getRestoreTypeObjSchema({selectedNodeType: itemNodeData._type}),
|
||||
()=>getRestoreSaveOptSchema({nodeInfo: treeNodeInfo}),
|
||||
()=>getRestoreQueryOptionSchema({selectedNodeType: itemNodeData._type, nodeInfo: treeNodeInfo}),
|
||||
()=>getRestoreDisableOptionSchema({nodeInfo: treeNodeInfo}),
|
||||
()=>getRestoreMiscellaneousSchema({nodeInfo: treeNodeInfo}),
|
||||
{
|
||||
|
||||
@@ -42,6 +42,7 @@ export class RestoreSectionSchema extends BaseUISchema {
|
||||
label: gettext('Pre-data'),
|
||||
type: 'switch',
|
||||
group: gettext('Sections'),
|
||||
inlineNext: true,
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(state) {
|
||||
return obj.isDisabled(state);
|
||||
@@ -51,6 +52,7 @@ export class RestoreSectionSchema extends BaseUISchema {
|
||||
label: gettext('Data'),
|
||||
type: 'switch',
|
||||
group: gettext('Sections'),
|
||||
inlineNext: true,
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(state) {
|
||||
return obj.isDisabled(state);
|
||||
@@ -95,6 +97,7 @@ export class RestoreTypeObjSchema extends BaseUISchema {
|
||||
label: gettext('Only data'),
|
||||
type: 'switch',
|
||||
group: gettext('Type of objects'),
|
||||
inlineNext: true,
|
||||
deps: ['pre_data', 'data', 'post_data', 'only_schema'],
|
||||
disabled: function(state) {
|
||||
if(obj.selectedNodeType == 'table') {
|
||||
@@ -156,26 +159,62 @@ export class RestoreSaveOptSchema extends BaseUISchema {
|
||||
label: gettext('Owner'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
inlineNext: true,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'dns_privilege',
|
||||
label: gettext('Privilege'),
|
||||
label: gettext('Privileges'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
inlineNext: true,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'dns_tablespace',
|
||||
label: gettext('Tablespace'),
|
||||
label: gettext('Tablespaces'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
inlineNext: true,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'no_comments',
|
||||
id: 'dns_comments',
|
||||
label: gettext('Comments'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
inlineNext: true,
|
||||
group: gettext('Do not save'),
|
||||
min_version: 110000
|
||||
}, {
|
||||
id: 'dns_publications',
|
||||
label: gettext('Publications'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
inlineNext: true,
|
||||
min_version: 110000
|
||||
}, {
|
||||
id: 'dns_subscriptions',
|
||||
label: gettext('Subscriptions'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
inlineNext: true,
|
||||
min_version: 110000
|
||||
}, {
|
||||
id: 'dns_security_labels',
|
||||
label: gettext('Security labels'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
inlineNext: true,
|
||||
min_version: 110000
|
||||
}, {
|
||||
id: 'dns_table_access_method',
|
||||
label: gettext('Table access methods'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
inlineNext: true,
|
||||
min_version: 150000
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -184,59 +223,6 @@ export function getRestoreSaveOptSchema(fieldOptions) {
|
||||
return new RestoreSaveOptSchema(fieldOptions);
|
||||
}
|
||||
|
||||
export class RestoreQueryOptionSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, initValues={}) {
|
||||
super({
|
||||
id: null,
|
||||
...initValues,
|
||||
});
|
||||
|
||||
this.fieldOptions = {
|
||||
nodeInfo: null,
|
||||
backupType: null,
|
||||
...fieldOptions,
|
||||
};
|
||||
|
||||
this.selectedNodeType = this.fieldOptions.selectedNodeType;
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
let obj = this;
|
||||
return [{
|
||||
id: 'include_create_database',
|
||||
label: gettext('Include CREATE DATABASE statement'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Queries')
|
||||
}, {
|
||||
id: 'clean',
|
||||
label: gettext('Clean before restore'),
|
||||
type: 'switch',
|
||||
group: gettext('Queries'),
|
||||
disabled: function(state) {
|
||||
if(obj.selectedNodeType === 'function' || obj.selectedNodeType === 'trigger_function') {
|
||||
state.clean = true;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
}, {
|
||||
id: 'single_transaction',
|
||||
label: gettext('Single transaction'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Queries'),
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
export function getRestoreQueryOptionSchema(fieldOptions) {
|
||||
return new RestoreQueryOptionSchema(fieldOptions);
|
||||
}
|
||||
|
||||
export class RestoreDisableOptionSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, initValues={}) {
|
||||
super({
|
||||
@@ -258,16 +244,10 @@ export class RestoreDisableOptionSchema extends BaseUISchema {
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'disable_trigger',
|
||||
label: gettext('Trigger'),
|
||||
label: gettext('Triggers'),
|
||||
type: 'switch',
|
||||
disable: false,
|
||||
group: gettext('Disable')
|
||||
}, {
|
||||
id: 'no_data_fail_table',
|
||||
label: gettext('No data for Failed Tables'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Disable'),
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -313,6 +293,12 @@ export class RestoreMiscellaneousSchema extends BaseUISchema {
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior'),
|
||||
}, {
|
||||
id: 'exclude_schema',
|
||||
label: gettext('Exclude schema'),
|
||||
type: 'text',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior')
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -324,7 +310,7 @@ export function getRestoreMiscellaneousSchema(fieldOptions) {
|
||||
//Restore Schema
|
||||
export default class RestoreSchema extends BaseUISchema {
|
||||
|
||||
constructor(restoreSectionSchema, restoreTypeObjSchema, restoreSaveOptSchema, restoreQueryOptionSchema, restoreDisableOptionSchema, restoreMiscellaneousSchema, fieldOptions = {}, treeNodeInfo={}, pgBrowser=null) {
|
||||
constructor(restoreSectionSchema, restoreTypeObjSchema, restoreSaveOptSchema, restoreDisableOptionSchema, restoreMiscellaneousSchema, fieldOptions = {}, treeNodeInfo={}, pgBrowser=null) {
|
||||
super({
|
||||
custom: false,
|
||||
file: undefined,
|
||||
@@ -351,7 +337,6 @@ export default class RestoreSchema extends BaseUISchema {
|
||||
this.getSectionSchema = restoreSectionSchema;
|
||||
this.getRestoreTypeObjSchema = restoreTypeObjSchema;
|
||||
this.getRestoreSaveOptSchema = restoreSaveOptSchema;
|
||||
this.getRestoreQueryOptionSchema = restoreQueryOptionSchema;
|
||||
this.getRestoreDisableOptionSchema = restoreDisableOptionSchema;
|
||||
this.getRestoreMiscellaneousSchema = restoreMiscellaneousSchema;
|
||||
this.treeNodeInfo = treeNodeInfo;
|
||||
@@ -408,27 +393,70 @@ export default class RestoreSchema extends BaseUISchema {
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Sections'),
|
||||
group: gettext('Data/Objects'),
|
||||
group: gettext('Data Options'),
|
||||
schema:obj.getSectionSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Type of objects'),
|
||||
group: gettext('Data/Objects'),
|
||||
group: gettext('Data Options'),
|
||||
schema:obj.getRestoreTypeObjSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Do not save'),
|
||||
group: gettext('Data/Objects'),
|
||||
group: gettext('Data Options'),
|
||||
schema:obj.getRestoreSaveOptSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Queries'),
|
||||
group: gettext('Options'),
|
||||
schema:obj.getRestoreQueryOptionSchema(),
|
||||
visible: true
|
||||
id: 'include_create_database',
|
||||
label: gettext('Include CREATE DATABASE statement'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Query Options')
|
||||
}, {
|
||||
id: 'clean',
|
||||
label: gettext('Clean before restore'),
|
||||
type: 'switch',
|
||||
group: gettext('Query Options'),
|
||||
inlineNext: true,
|
||||
disabled: function(state) {
|
||||
if(obj.selectedNodeType === 'function' || obj.selectedNodeType === 'trigger_function') {
|
||||
state.clean = true;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
}, {
|
||||
id: 'if_exists',
|
||||
label: gettext('Include IF EXISTS clause'),
|
||||
type: 'switch',
|
||||
group: gettext('Query Options'),
|
||||
deps: ['clean'],
|
||||
disabled: function(state) {
|
||||
if (state.clean) {
|
||||
return false;
|
||||
}
|
||||
state.if_exists = false;
|
||||
return true;
|
||||
},
|
||||
}, {
|
||||
id: 'single_transaction',
|
||||
label: gettext('Single transaction'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Query Options'),
|
||||
}, {
|
||||
id: 'enable_row_security',
|
||||
label: gettext('Enable row security'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Table Options'),
|
||||
}, {
|
||||
id: 'no_data_fail_table',
|
||||
label: gettext('No data for failed tables'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Table Options'),
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Disable'),
|
||||
|
||||
@@ -18,6 +18,8 @@ from pgadmin.browser.server_groups.servers.databases.tests import utils as \
|
||||
from unittest.mock import patch, MagicMock
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
RESTORE_JOB_URL = '/restore/job/{0}'
|
||||
|
||||
|
||||
class RestoreCreateJobTest(BaseTestGenerator):
|
||||
"""Test the RestoreCreateJob class"""
|
||||
@@ -43,7 +45,7 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
tables=[],
|
||||
database='postgres'
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--verbose'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
@@ -69,7 +71,7 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
tables=[],
|
||||
database='postgres'
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--verbose', '--format=d'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
@@ -100,7 +102,7 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
only_data=True,
|
||||
only_schema=True
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--verbose', '--jobs', '2',
|
||||
'--section=pre-data', '--section=data',
|
||||
'--section=post-data'],
|
||||
@@ -133,7 +135,7 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
only_schema=True,
|
||||
dns_owner=True
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--verbose', '--data-only'],
|
||||
not_expected_cmd_opts=[],
|
||||
# Below options should be enabled once we fix the issue #3368
|
||||
@@ -164,14 +166,15 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
dns_tablespace=True,
|
||||
only_data=False
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--no-owner',
|
||||
'--no-tablespaces',
|
||||
'--no-privileges'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
('When restore object with option - Do not save comments',
|
||||
('When restore object with option - Do not save comments, '
|
||||
'Publications, Subscriptions, Security Labels',
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
@@ -190,22 +193,27 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
schemas=[],
|
||||
tables=[],
|
||||
database='postgres',
|
||||
no_comments=True,
|
||||
dns_comments=True,
|
||||
dns_publications=True,
|
||||
dns_subscriptions=True,
|
||||
dns_security_labels=True,
|
||||
only_data=False
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
expected_cmd_opts=['--no-comments'],
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--no-comments', '--no-publications',
|
||||
'--no-subscriptions', '--no-security-labels'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None],
|
||||
server_min_version=110000,
|
||||
message='Restore object with --no-comments is not supported '
|
||||
'by EPAS/PG server less than 11.0'
|
||||
message='Restore object with --no-comments --no-publications,'
|
||||
'--no-subscriptions, --no-security-labels is not '
|
||||
'supported by EPAS/PG server less than 11.0'
|
||||
)),
|
||||
('When restore object with option - Queries',
|
||||
('When restore object with option - Do not save Table Access Method ',
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
name='test_restore_file',
|
||||
name='test_restore_server',
|
||||
port=5444,
|
||||
host='localhost',
|
||||
database='postgres',
|
||||
@@ -213,7 +221,36 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
username='postgres'
|
||||
),
|
||||
params=dict(
|
||||
file='test_backup_file',
|
||||
file='test_restore_file',
|
||||
format='custom',
|
||||
verbose=True,
|
||||
custom=False,
|
||||
schemas=[],
|
||||
tables=[],
|
||||
database='postgres',
|
||||
dns_table_access_method=True
|
||||
),
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--no-table-access-method'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None],
|
||||
server_min_version=150000,
|
||||
message='Restore object with --no-table-access-method is not '
|
||||
'supported by EPAS/PG server less than 15.0'
|
||||
)),
|
||||
('When restore object with option - Queries',
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
name='test_restore_server',
|
||||
port=5444,
|
||||
host='localhost',
|
||||
database='postgres',
|
||||
bfile='test_restore',
|
||||
username='postgres'
|
||||
),
|
||||
params=dict(
|
||||
file='test_restore_file',
|
||||
format='custom',
|
||||
verbose=True,
|
||||
schemas=[],
|
||||
@@ -222,10 +259,40 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
clean=True,
|
||||
include_create_database=True,
|
||||
single_transaction=True,
|
||||
if_exists=True,
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--create', '--clean',
|
||||
'--single-transaction'],
|
||||
'--single-transaction', '--if-exists'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
('When restore object with Table options - enable row security and '
|
||||
'No data for failed tables',
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
name='test_restore_server',
|
||||
port=5444,
|
||||
host='localhost',
|
||||
database='postgres',
|
||||
bfile='test_restore',
|
||||
username='postgres'
|
||||
),
|
||||
params=dict(
|
||||
file='test_restore_file',
|
||||
format='custom',
|
||||
verbose=True,
|
||||
schemas=[],
|
||||
tables=[],
|
||||
database='postgres',
|
||||
enable_row_security=True,
|
||||
no_data_fail_table=True,
|
||||
only_schema=False
|
||||
),
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--enable-row-security',
|
||||
'--no-data-for-failed-tables'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
@@ -233,7 +300,7 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
name='test_restore_file',
|
||||
name='test_restore_server',
|
||||
port=5444,
|
||||
host='localhost',
|
||||
database='postgres',
|
||||
@@ -241,19 +308,17 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
username='postgres'
|
||||
),
|
||||
params=dict(
|
||||
file='test_backup_file',
|
||||
file='test_restore_file',
|
||||
format='custom',
|
||||
verbose=True,
|
||||
schemas=[],
|
||||
tables=[],
|
||||
database='postgres',
|
||||
disable_trigger=True,
|
||||
no_data_fail_table=True,
|
||||
only_schema=False
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
expected_cmd_opts=['--disable-triggers',
|
||||
'--no-data-for-failed-tables'],
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--disable-triggers'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
@@ -261,7 +326,7 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
name='test_restore_file',
|
||||
name='test_restore_server',
|
||||
port=5444,
|
||||
host='localhost',
|
||||
database='postgres',
|
||||
@@ -269,7 +334,7 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
username='postgres'
|
||||
),
|
||||
params=dict(
|
||||
file='test_backup_file',
|
||||
file='test_restore_file',
|
||||
format='custom',
|
||||
verbose=True,
|
||||
schemas=[],
|
||||
@@ -278,10 +343,34 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
use_set_session_auth=True,
|
||||
exit_on_error=True,
|
||||
),
|
||||
url='/restore/job/{0}',
|
||||
# Add '--use_set_session_auth' into
|
||||
# expected_cmd_opts once #3363 fixed
|
||||
expected_cmd_opts=['--exit-on-error'],
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--exit-on-error',
|
||||
'--use-set-session-authorization'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
('When restore object with option - Exclude schema',
|
||||
dict(
|
||||
class_params=dict(
|
||||
sid=1,
|
||||
name='test_restore_server',
|
||||
port=5444,
|
||||
host='localhost',
|
||||
database='postgres',
|
||||
bfile='test_restore',
|
||||
username='postgres'
|
||||
),
|
||||
params=dict(
|
||||
file='test_restore_file',
|
||||
format='custom',
|
||||
verbose=True,
|
||||
schemas=[],
|
||||
tables=[],
|
||||
database='postgres',
|
||||
exclude_schema="sch*"
|
||||
),
|
||||
url=RESTORE_JOB_URL,
|
||||
expected_cmd_opts=['--exclude-schema', 'sch*'],
|
||||
not_expected_cmd_opts=[],
|
||||
expected_exit_code=[0, None]
|
||||
)),
|
||||
@@ -305,20 +394,17 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
if os.name == 'nt':
|
||||
binary_path = binary_path + '.exe'
|
||||
|
||||
retVal = does_utility_exist(binary_path)
|
||||
if retVal is not None:
|
||||
self.skipTest(retVal)
|
||||
ret_val = does_utility_exist(binary_path)
|
||||
if ret_val is not None:
|
||||
self.skipTest(ret_val)
|
||||
|
||||
@patch('pgadmin.tools.restore.Server')
|
||||
@patch('pgadmin.tools.restore.current_user')
|
||||
@patch('pgadmin.tools.restore.RestoreMessage')
|
||||
@patch('pgadmin.tools.restore.filename_with_file_manager_path')
|
||||
@patch('pgadmin.tools.restore.BatchProcess')
|
||||
@patch('pgadmin.utils.driver.{0}.server_manager.ServerManager.'
|
||||
'export_password_env'.format(PG_DEFAULT_DRIVER))
|
||||
def runTest(self, export_password_env_mock, batch_process_mock,
|
||||
filename_mock, restore_message_mock,
|
||||
current_user_mock, server_mock):
|
||||
filename_mock, restore_message_mock):
|
||||
class TestMockServer():
|
||||
def __init__(self, name, host, port, id, username):
|
||||
self.name = name
|
||||
@@ -336,8 +422,6 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
self.server_id,
|
||||
self.class_params['username']
|
||||
)
|
||||
mock_result = server_mock.query.filter_by.return_value
|
||||
mock_result.first.return_value = mock_obj
|
||||
|
||||
filename_mock.return_value = self.params['file']
|
||||
|
||||
|
||||
@@ -1866,7 +1866,6 @@ def load_file():
|
||||
|
||||
# get the current storage from request if available
|
||||
# or get it from last_storage preference.
|
||||
storage_folder = ''
|
||||
if 'storage' in file_data:
|
||||
storage_folder = file_data['storage']
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user