...
 
Commits (27)
image: debian:9.5
services:
- postgres:9.6
variables:
POSTGRES_DB: 'ecodata'
POSTGRES_USER: 'ecodata'
POSTGRES_PASSWORD: ''
DB_HOST: 'postgres'
PGPASSWORD: '' #should be the same as POSTGRES_PASSWORD
stages:
- lint
- test
linter_shell:
stage: lint
tags:
- postgres
- debian
script:
- apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install wget locales locales-all -y
- locale-gen pt_BR.UTF-8
- export LANG=pt_BR.UTF-8
- scversion="stable" # or "v0.4.7", or "latest"
- wget "https://storage.googleapis.com/shellcheck/shellcheck-$scversion.linux.x86_64.tar.xz"
- tar --xz -xvf "shellcheck-$scversion.linux.x86_64.tar.xz"
- shellcheck() { "shellcheck-$scversion/shellcheck" "$@"; }
- ./.linter_shell.sh
test:
stage: test
tags:
- postgres
- debian
script:
- cat /etc/apt/sources.list | sed -e 's/deb.debian.org/debian.c3sl.ufpr.br/g' > /tmp/s
- mv /tmp/s /etc/apt/sources.list
- apt update
- apt install postgresql-client-9.6 libpq-dev --yes
- ./insersor.sh teste/
#!/bin/bash
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
sh_files=$(find . -name "*.sh")
exe_files=$(grep -Erl "#\!/bin/(bash|sh)" --exclude=*.*)
files="$sh_files\n$exe_files"
#find no files
if [[ "$files" == "\n" ]];then
echo -e "${YELLOW}No shell files found!${NC}"
exit 0
fi
if [[ $(echo -e "$files"| xargs shellcheck -s bash) -eq 0 ]]
then
echo "AWESOME!No problems found."
exit 0
else
echo -e "Understand errors in: ${BLUE}https://github.com/koalaman/shellcheck/wiki${NC}"
exit 1
fi
#! /bin/bash
if [[ $# -ne 1 ]]; then
echo "A directory with .sql input files is expected as argument"
exit 1
fi
PGPASSWORD="$POSTGRES_PASSWORD"
for i in "$1"*.sql
do
psql -h $DB_HOST -d $POSTGRES_DB -U $POSTGRES_USER -c "BEGIN";
error=0
while read -r j
do
if [[ $(psql "$dbauth" -c "$j") -ne 0 ]]
then
error=1
break
fi
done < "$i"
if [[ $error -eq 1 ]]
then
psql -h $DB_HOST -d $POSTGRES_DB -U $POSTGRES_USER -c "ROLLBACK;"
else
psql -h $DB_HOST -d $POSTGRES_DB -U $POSTGRES_USER -c "COMMIT;"
fi
done
CREATE TABLE scm (
"COD IBGE 7" INTEGER,
"Cidade" TEXT,
"UF" TEXT,
"Latitude" DOUBLE PRECISION,
"Longitude" DOUBLE PRECISION,
"Projeto" TEXT,
"Operadoras" TEXT
);
INSERT INTO smc ("Cidade", "UF") VALUES ("Curitiba", "PR");
SELECT * FROM scm
CREATE TABLE scm (
"COD IBGE 7" INTEGER,
"Cidade" TEXT,
"UF" TEXT,
"Latitude" DOUBLE PRECISION,
"Longitude" DOUBLE PRECISION,
"Projeto" TEXT,
"Operadoras" TEXT
);
INSERT INTO scm ("Cidade", "UF") VALUES ("Curitiba", "PR");
SELECT * FROM scm