diff --git a/scripts/targets/batch/views.yaml b/scripts/targets/batch/views.yaml index 856e31c1..9b8f46b1 100644 --- a/scripts/targets/batch/views.yaml +++ b/scripts/targets/batch/views.yaml @@ -16,43 +16,30 @@ # You should have received a copy of the GNU Affero General Public License # along with AutoCheck. If not, see . -inherits: "../../templates/permissions.yaml" +inherits: "../../templates/views.yaml" + +vars: + student: "" batch: - - connector: - type: "TextStream" - - - run: - connector: "TextStream" - command: "Substring" - arguments: - content: "{$CURRENT_FOLDER_NAME}" - regex: "^[^ ]+(?= )" - store: "student" - - - caption: "Running on batch mode for ~{$STUDENT}:" - - concurrent: !!int 1 #cannot run in parallel due permissions over users + - caption: "Running on batch mode for ~{$CURRENT_FOLDER_NAME}:" + - concurrent: 1 #cannot run in parallel due permissions over users + - local: - path: "{$APP_FOLDER_PATH}/../test/samples/private/views" - vars: current_host: "localhost" current_user: "postgres" current_password: "postgres" - database: "empresa-views-{$STUDENT}" + database: "empresa-permissions-{$STUDENT}" - copy_detector: type: "SqlLog" file: "*.log" threshold: !!float 0.65 - - run: - connector: "TextStream" - command: "DirectoryName" - arguments: "--path {$CURRENT_FOLDER_PATH}" - store: "dirname" - - - setup: - - echo: "Extracting files at ~{$DIRNAME}:" + - setup: + - echo: "Extracting files at ~{$CURRENT_FOLDER_NAME}:" - run: command: "GetFile" @@ -62,13 +49,13 @@ batch: - connector: type: "Compressed" arguments: "--filePath {$ZIP_FILE}" - + - run: connector: "TextStream" command: "FileName" arguments: "--path {$ZIP_FILE}" store: "filename" - + - run: caption: " Extracting the file ~{$FILENAME}... " connector: "Compressed" @@ -77,13 +64,14 @@ batch: arguments: recursive: !!bool True + - pre: - echo: "" - - echo: "Restoring BBDD permissions:" + - echo: "Restoring BBDD permissions:" - connector: type: "Postgres" - arguments: "--host {$CURRENT_HOST} --database postgres --username {$CURRENT_USER} --password {$CURRENT_PASSWORD}" - + arguments: "--host {$CURRENT_HOST} --database postgres --username {$CURRENT_USER} --password {$CURRENT_PASSWORD}" + - run: caption: " Dropping user it... " connector: "Postgres" @@ -96,16 +84,65 @@ batch: connector: "Postgres" command: "CreateUser" arguments: "--user it" - onexception: "SUCCESS" + onexception: "SUCCESS" - echo: "" - - echo: "Importing SQL dump:" + - echo: "Setting up SQL dump:" + + - run: + caption: " Getting student name... " + connector: "TextStream" + command: "Substring" + arguments: + content: "{$CURRENT_FOLDER_NAME}" + regex: "^[^_]+(?=_)" + store: "$STUDENT" + + - run: + caption: " Getting database name... " + connector: "TextStream" + command: "Replace" + arguments: + content: "{$STUDENT}" + replacement: "-" + regex: \s + store: "$STUDENT" - run: + caption: " Looking for the SQL dump... " command: "GetFile" arguments: "--path {$CURRENT_FOLDER_PATH} --file *.sql" - store: "SQL_FILE" - + store: "SQL_FILE" + + - connector: + type: "PlainText" + arguments: "--filePath {$SQL_FILE}" + + - run: + caption: " Replacing the database name... " + connector: "PlainText" + command: "Replace" + arguments: + replacement: "DATABASE {$DATABASE}" + regex: DATABASE empresa + + - run: + caption: " Replacing the database connection... " + connector: "PlainText" + command: "Replace" + arguments: + replacement: "\\connect {$DATABASE}" + regex: \\connect empresa + + - run: + caption: " Storing changes... " + connector: "PlainText" + command: "Store" + arguments: "--filePath {$SQL_FILE}" + + - echo: "" + - echo: "Importing SQL dump:" + - connector: type: "Postgres" arguments: "--host {$CURRENT_HOST} --database {$DATABASE} --username {$CURRENT_USER} --password {$CURRENT_PASSWORD}"