Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FherStk committed May 27, 2022
1 parent b95e356 commit e9492b3
Showing 1 changed file with 69 additions and 32 deletions.
101 changes: 69 additions & 32 deletions scripts/targets/batch/views.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,30 @@
# You should have received a copy of the GNU Affero General Public License
# along with AutoCheck. If not, see <https://www.gnu.org/licenses/>.

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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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}"
Expand Down

0 comments on commit e9492b3

Please sign in to comment.