From d04222074f1a8200189c0146a961d7cf818b0418 Mon Sep 17 00:00:00 2001 From: Brian Bjarke Jensen Date: Thu, 22 Jan 2026 21:42:24 +0100 Subject: [PATCH] added manual CI step to configure database --- .gitea/workflows/setup_database.yml | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .gitea/workflows/setup_database.yml diff --git a/.gitea/workflows/setup_database.yml b/.gitea/workflows/setup_database.yml new file mode 100644 index 0000000..6c24336 --- /dev/null +++ b/.gitea/workflows/setup_database.yml @@ -0,0 +1,43 @@ + +name: Setup PostgreSQL Database + +on: + workflow_dispatch: + inputs: + database_name: + description: 'Database name' + required: false + default: 'homeassistant' + username: + description: 'Database user' + required: false + default: 'homeassistant' + +jobs: + setup-database: + runs-on: ubuntu-latest + steps: + - name: Create database and user + env: + DB_HOST: ${{ secrets.POSTGRES_HOST }} + DB_PORT: ${{ secrets.POSTGRES_PORT }} + PGPASSWORD: ${{ secrets.POSTGRES_ROOT_PASSWORD }} + DB_NAME: ${{ inputs.database_name }} + DB_USER: ${{ inputs.username }} + DB_PASSWORD: ${{ secrets.DB_PASSWORD }} + run: | + psql -h ${DB_HOST} -p ${DB_PORT} -U postgres -c "CREATE DATABASE ${DB_NAME};" + psql -h ${DB_HOST} -p ${DB_PORT} -U postgres -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASSWORD}';" + psql -h ${DB_HOST} -p ${DB_PORT} -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};" + + - name: Verify setup + env: + DB_HOST: ${{ secrets.POSTGRES_HOST }} + DB_PORT: ${{ secrets.POSTGRES_PORT }} + PGPASSWORD: ${{ secrets.POSTGRES_ROOT_PASSWORD }} + DB_NAME: ${{ inputs.database_name }} + DB_USER: ${{ inputs.username }} + run: | + echo "Database setup completed successfully!" + psql -h ${DB_HOST} -p ${DB_PORT} -U postgres -c "\l" | grep ${DB_NAME} + psql -h ${DB_HOST} -p ${DB_PORT} -U postgres -c "\du" | grep ${DB_USER} \ No newline at end of file