From 7e6872e0454e0403dcb73e74f1d43537f084062f Mon Sep 17 00:00:00 2001 From: Felix Delattre Date: Mon, 25 Oct 2021 09:40:19 +0000 Subject: [PATCH 1/2] Removed run-migrations script and shell linters --- .gitlab-ci.yml | 11 --------- Makefile | 8 ------- run-migrations.sh | 58 ----------------------------------------------- 3 files changed, 77 deletions(-) delete mode 100644 Makefile delete mode 100755 run-migrations.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a98d42b..44d960a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,16 +1,5 @@ image: debian:bookworm-slim -before_script: - - apt update -y - - apt install -y git make shellcheck golang-go postgresql -y -qq - - export GOPATH="$HOME/go" - - export PATH="$PATH:$GOPATH/bin" - - go get -u mvdan.cc/sh/v3/cmd/shfmt - -linters: - script: - - make check - test: services: - name: $CI_REGISTRY/dynamicexposure/server-components/containers/docker-obm-database:master diff --git a/Makefile b/Makefile deleted file mode 100644 index 8fbacce..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -SOURCES=./run-migrations.sh - -check: $(SOURCES) - shellcheck --external-sources $^ - shfmt -i 2 -d $^ - -format: $(SOURCES) - shfmt -i 2 -w $^ diff --git a/run-migrations.sh b/run-migrations.sh deleted file mode 100755 index 473b234..0000000 --- a/run-migrations.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -# -# Deletes current `gde_tiles` database and sets it up anew by running -# all SQL scripts in the migrations folder in ascending order. -# Run: script_name [db_user] -# May provide the database user as an argument (default: postgres). - -# Copyright (C) 2021: -# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see http://www.gnu.org/licenses/. - -sql_scripts_dir='migrations' -db_name='gde_tiles' -db_user='postgres' - -# Test for argument from the command line (now only one argument: database user) -if [[ -z ${1+x} ]]; then - # First parameter is the database user - printf 'Running %s with default database user %s\n' "$(basename "$0")" "${db_user}" -else - db_user=${1} - printf 'Running %s with database user %s\n' "$(basename "$0")" "${db_user}" -fi - -# Delete current `gde_tiles` database if exists and create anew -if psql -lqt | cut -d \| -f 1 | grep -qw ${db_name}; then - # Database exists - printf 'Database %s exists, deleting.\n' ${db_name} - dropdb ${db_name} - printf 'Creating %s\n' ${db_name} - createdb ${db_name} -else - createdb ${db_name} -fi - -# Run the SQL scripts in the migrations folder in ascending order -for file in "${sql_scripts_dir}"/*.sql; do - f_base=$(basename "${file}" .sql) - printf 'Running script %s\n' "${f_base}" - psql --username "${db_user}" \ - --dbname "${db_name}" \ - --echo-all --file "${file}" -done - -printf 'Done.\n' -exit 0 -- GitLab From 728f2e93ad8cea947ce3d7d91d17b4ae8b773e4a Mon Sep 17 00:00:00 2001 From: Felix Delattre Date: Mon, 25 Oct 2021 09:40:51 +0000 Subject: [PATCH 2/2] Added sql linter --- .gitlab-ci.yml | 11 +++++++++++ migrations/00001_create-initial-table.sql | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 44d960a..bcf54fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,17 @@ image: debian:bookworm-slim +linter: + before_script: + - apt-get update -y + - apt-get install python3-pip -y -qq + - pip install sqlfluff + script: + - sqlfluff lint --dialect postgres + test: + before_script: + - apt-get update -y + - apt-get install postgresql -y -qq services: - name: $CI_REGISTRY/dynamicexposure/server-components/containers/docker-obm-database:master alias: postgres diff --git a/migrations/00001_create-initial-table.sql b/migrations/00001_create-initial-table.sql index 17e1fcc..68ac850 100644 --- a/migrations/00001_create-initial-table.sql +++ b/migrations/00001_create-initial-table.sql @@ -5,4 +5,4 @@ CREATE TABLE public.gde_tiles ); ALTER TABLE public.gde_tiles - OWNER to postgres; +OWNER TO postgres; -- GitLab