From fec0a579dc86b24874ea8502bbdc86aea1d166cb Mon Sep 17 00:00:00 2001 From: Li Jie Date: Mon, 9 Dec 2024 17:15:38 +0800 Subject: [PATCH] finish action (#1) * finish action --- .github/workflows/ci.yml | 64 ++++++++++++ README.md | 196 +++++++++++++++++++++++-------------- action.yml | 87 ++++++++++++++++ scripts/install-macos.sh | 82 ++++++++++++++++ scripts/install-ubuntu.sh | 106 ++++++++++++++++++++ scripts/install-windows.sh | 114 +++++++++++++++++++++ 6 files changed, 577 insertions(+), 72 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 action.yml create mode 100644 scripts/install-macos.sh create mode 100644 scripts/install-ubuntu.sh create mode 100644 scripts/install-windows.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..833d890 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + continue-on-error: true + strategy: + fail-fast: false + matrix: + postgres-version: [14, 15, 16, 17] + os: [ubuntu-latest, ubuntu-24.04, windows-latest, windows-2019, macos-latest, macos-13] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + + - name: Setup pgvector + uses: ./ + with: + postgres-version: ${{ matrix.postgres-version }} + postgres-user: testuser + postgres-password: testpass + postgres-db: testdb + + - name: Test Extension (Unix) + if: runner.os != 'Windows' + env: + PGPASSWORD: testpass + run: | + psql -h localhost -U testuser -d testdb -c 'CREATE EXTENSION IF NOT EXISTS vector;' + psql -h localhost -U testuser -d testdb -c 'CREATE TABLE IF NOT EXISTS items (id bigserial PRIMARY KEY, embedding vector(3));' + psql -h localhost -U testuser -d testdb -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');" + psql -h localhost -U testuser -d testdb -c 'SELECT * FROM items;' + + - name: Test Extension (Windows PowerShell) + if: runner.os == 'Windows' + shell: pwsh + env: + PGPASSWORD: testpass + run: | + psql -h localhost -U testuser -d testdb -c 'CREATE EXTENSION IF NOT EXISTS vector;' + psql -h localhost -U testuser -d testdb -c 'CREATE TABLE IF NOT EXISTS items (id bigserial PRIMARY KEY, embedding vector(3));' + psql -h localhost -U testuser -d testdb -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');" + psql -h localhost -U testuser -d testdb -c 'SELECT * FROM items;' + + - name: Test Extension (Windows CMD) + if: runner.os == 'Windows' + shell: cmd + env: + PGPASSWORD: testpass + run: psql -h localhost -U testuser -d testdb -c "SELECT * FROM items;" + + - name: Test Extension (Windows MSYS2) + if: runner.os == 'Windows' + shell: msys2 {0} + env: + PGPASSWORD: testpass + run: psql -h localhost -U testuser -d testdb -c 'SELECT * FROM items;' diff --git a/README.md b/README.md index 8470640..b314c3f 100644 --- a/README.md +++ b/README.md @@ -1,97 +1,149 @@ -# Setup pgvector Action +# Setup pgvector -This action sets up [pgvector](https://github.com/pgvector/pgvector) in your GitHub Actions workflow. It uses the preinstalled PostgreSQL on GitHub runners and installs pgvector using platform-specific methods. +GitHub Action and scripts to set up PostgreSQL with pgvector extension for vector similarity search. -## Usage +## Features + +- 🚀 Quick setup of PostgreSQL with pgvector extension +- 🔄 Supports both GitHub Actions and local installation +- 🛠️ Customizable PostgreSQL and pgvector versions +- 🔐 Secure password authentication +- 🌐 Cross-platform support: Ubuntu, Windows (MSYS2), and macOS +- 🏗️ Builds pgvector from source for maximum compatibility + +## Supported Platforms + +The following table shows the compatibility matrix for different PostgreSQL versions and platforms: + +| Platform | Architecture | PostgreSQL 14 | PostgreSQL 15 | PostgreSQL 16 | PostgreSQL 17 | +|----------|-------------|:-------------:|:-------------:|:-------------:|:-------------:| +| Ubuntu Latest | x86_64 | ✅ | ✅ | ✅ | ✅ | +| Ubuntu 24.04 | x86_64 | ✅ | ✅ | ✅ | ✅ | +| Windows Latest | x86_64 | ✅ | ✅ | ✅ | ✅ | +| Windows 2019 | x86_64 | ✅ | ✅ | ✅ | ✅ | +| macOS Latest | arm64 | ✅ | ✅ | ✅ | ✅ | +| macOS 13 | x86_64 | ✅ | ✅ | ✅ | ✅ | + +## Quick Start + +### GitHub Actions ```yaml steps: -- uses: actions/checkout@v4 -- uses: cpunion/setup-pgvector@v1 +- uses: cpunion/setup-pgvector@main with: - postgres-version: '17' # optional, defaults to 17. Use 14 for ubuntu-22.04 and ubuntu-20.04 + postgres-version: '17' + postgres-user: 'myuser' + postgres-password: 'mypassword' + postgres-db: 'mydb' + +- name: Test pgvector + env: + PGPASSWORD: mypassword + run: | + psql -h localhost -U myuser -d mydb -c 'CREATE EXTENSION vector;' ``` -## Inputs +### Local Installation -- `postgres-version`: PostgreSQL version to use (default: '17'). Note: Use '14' for ubuntu-22.04 and ubuntu-20.04. +#### Method 1: Direct Installation -## Platform Support +```bash +# Ubuntu +curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-ubuntu.sh | bash -This action supports all major GitHub Actions platforms: -- Ubuntu (using postgresql-xx-pgvector package) -- macOS (using Homebrew) -- Windows (building from source using Visual Studio Build Tools) +# macOS +curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-macos.sh | bash -## CI Status +# Windows (MSYS2) +curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-windows.sh | bash +``` -The action is tested on the following platforms: -- Ubuntu: ubuntu-latest, ubuntu-24.04 -- Windows: windows-latest, windows-2019 -- macOS: macos-latest, macos-13 +With custom parameters: +```bash +# Format: curl ... | bash -s [PG_VERSION] [PGVECTOR_VERSION] [PGUSER] [PGPASSWORD] [PGDATABASE] +curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-ubuntu.sh | bash -s 17 0.8.0 myuser mypassword mydb +``` -## Example workflows +#### Method 2: Clone and Run -### Ubuntu -```yaml -name: Test Ubuntu - -on: [push] - -jobs: - test: - runs-on: ubuntu-latest # or ubuntu-22.04, ubuntu-20.04 - steps: - - uses: actions/checkout@v4 - - name: Setup pgvector - uses: cpunion/setup-pgvector@v1 - with: - postgres-version: '17' # Use '14' for ubuntu-22.04 and ubuntu-20.04 - - name: Create extension - run: | - sudo -u postgres psql -c 'CREATE EXTENSION vector;' +```bash +# Ubuntu +./scripts/install-ubuntu.sh + +# macOS +./scripts/install-macos.sh + +# Windows (MSYS2) +./scripts/install-windows.sh ``` -### macOS +## Requirements + +- Ubuntu: No additional requirements +- Windows: MSYS2 environment +- macOS: Homebrew +- Git (for building pgvector) + +## Detailed Usage + +### GitHub Actions + ```yaml -name: Test macOS - -on: [push] - -jobs: - test: - runs-on: macos-latest # or macos-13 - steps: - - uses: actions/checkout@v4 - - name: Setup pgvector - uses: cpunion/setup-pgvector@v1 - - name: Create extension - run: | - psql postgres -c 'CREATE EXTENSION vector;' +steps: +- uses: cpunion/setup-pgvector@main + with: + # PostgreSQL version to install (default: 17) + postgres-version: '17' + # pgvector version to install (default: 0.8.0) + pgvector-version: '0.8.0' + # PostgreSQL user to create (default: postgres) + postgres-user: 'myuser' + # Password for the PostgreSQL user (default: postgres) + postgres-password: 'mypassword' + # Database to create (default: postgres) + postgres-db: 'mydb' + +- name: Test pgvector + env: + PGPASSWORD: mypassword + run: | + psql -h localhost -U myuser -d mydb -c 'CREATE EXTENSION vector;' + psql -h localhost -U myuser -d mydb -c 'CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));' + psql -h localhost -U myuser -d mydb -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');" + psql -h localhost -U myuser -d mydb -c 'SELECT * FROM items;' ``` -### Windows -```yaml -name: Test Windows - -on: [push] - -jobs: - test: - strategy: - matrix: - os: [windows-latest, windows-2019] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - name: Setup pgvector - uses: cpunion/setup-pgvector@v1 - - name: Create extension - shell: cmd - run: | - psql -U postgres -c "CREATE EXTENSION vector;" +### Script Parameters + +All installation scripts accept the following parameters: + +1. `PG_VERSION` (default: 17) - PostgreSQL version to install +2. `PGVECTOR_VERSION` (default: 0.8.0) - pgvector version to install +3. `PGUSER` (default: postgres) - PostgreSQL user to create +4. `PGPASSWORD` (default: postgres) - Password for the PostgreSQL user +5. `PGDATABASE` (default: postgres) - Database to create + +### Connection Details + +After installation, you can connect to PostgreSQL using: + +```bash +# Using password from environment variable +export PGPASSWORD=mypassword +psql -h localhost -U myuser -d mydb + +# Or using password prompt +psql -h localhost -U myuser -d mydb ``` +## Notes + +- The scripts will install PostgreSQL if not already installed +- The scripts will create the specified user and database if they don't exist +- The scripts will build and install pgvector from source +- All connections are configured to use password authentication + ## License MIT diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..bf39919 --- /dev/null +++ b/action.yml @@ -0,0 +1,87 @@ +name: 'Setup pgvector' +description: 'Setup pgvector in GitHub Actions' +inputs: + postgres-version: + description: 'PostgreSQL version to use' + required: false + default: '17' + pgvector-version: + description: 'pgvector version to install' + required: false + default: '0.8.0' + postgres-user: + description: 'PostgreSQL user to create' + required: false + default: 'postgres' + postgres-password: + description: 'PostgreSQL user password' + required: false + default: 'postgres' + postgres-db: + description: 'PostgreSQL database to create' + required: false + default: 'postgres' +runs: + using: "composite" + steps: + - name: Install and Configure PostgreSQL on Ubuntu + if: runner.os == 'Linux' + shell: bash + run: | + chmod +x ${{ github.action_path }}/scripts/install-ubuntu.sh + ${{ github.action_path }}/scripts/install-ubuntu.sh \ + ${{ inputs.postgres-version }} \ + ${{ inputs.pgvector-version }} \ + ${{ inputs.postgres-user }} \ + ${{ inputs.postgres-password }} \ + ${{ inputs.postgres-db }} + + - name: Install and Configure PostgreSQL on macOS + if: runner.os == 'macOS' + shell: bash + run: | + chmod +x ${{ github.action_path }}/scripts/install-macos.sh + ${{ github.action_path }}/scripts/install-macos.sh \ + ${{ inputs.postgres-version }} \ + ${{ inputs.pgvector-version }} \ + ${{ inputs.postgres-user }} \ + ${{ inputs.postgres-password }} \ + ${{ inputs.postgres-db }} + + - name: Setup MSYS2 + if: runner.os == 'Windows' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: >- + mingw-w64-x86_64-postgresql + mingw-w64-x86_64-gcc + mingw-w64-x86_64-make + mingw-w64-x86_64-tools-git + make + diffutils + git + + - name: Add MSYS2 to PATH + if: runner.os == 'Windows' + shell: pwsh + run: | + echo "D:\a\_temp\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "D:\a\_temp\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + - name: Install and Configure PostgreSQL on Windows + if: runner.os == 'Windows' + shell: msys2 {0} + env: + MSYSTEM: MINGW64 + CHERE_INVOKING: 1 + run: | + SCRIPT_PATH=$(echo "${{ github.action_path }}/scripts/install-windows.sh" | sed 's/\\/\//g') + chmod +x "$SCRIPT_PATH" + "$SCRIPT_PATH" \ + ${{ inputs.postgres-version }} \ + ${{ inputs.pgvector-version }} \ + ${{ inputs.postgres-user }} \ + ${{ inputs.postgres-password }} \ + ${{ inputs.postgres-db }} diff --git a/scripts/install-macos.sh b/scripts/install-macos.sh new file mode 100644 index 0000000..dcb9d16 --- /dev/null +++ b/scripts/install-macos.sh @@ -0,0 +1,82 @@ +#!/bin/bash +set -ex + +# Default versions if not provided +PG_VERSION=${1:-17} +PGVECTOR_VERSION=${2:-0.8.0} +PGUSER=${3:-postgres} +PGPASSWORD=${4:-postgres} +PGDATABASE=${5:-postgres} + +# Function to export variables +export_var() { + local name=$1 + local value=$2 + export "$name=$value" + # Only export to GITHUB_ENV if running in GitHub Actions + if [ -n "$GITHUB_ENV" ]; then + echo "$name=$value" >> $GITHUB_ENV + fi +} + +# Install PostgreSQL +brew install "postgresql@$PG_VERSION" +brew link --force "postgresql@$PG_VERSION" + +# Add PostgreSQL binaries to PATH +PG_PATH="/usr/local/opt/postgresql@$PG_VERSION/bin" +# For Apple Silicon Macs +if [ -d "/opt/homebrew/opt/postgresql@$PG_VERSION/bin" ]; then + PG_PATH="/opt/homebrew/opt/postgresql@$PG_VERSION/bin" +fi +export PATH="$PG_PATH:$PATH" +# Only add to GITHUB_PATH if running in GitHub Actions +if [ -n "$GITHUB_PATH" ]; then + echo "$PG_PATH" >> $GITHUB_PATH +fi + +# Start PostgreSQL +brew services start "postgresql@$PG_VERSION" + +# Wait for PostgreSQL to start +sleep 3 + +# Set password and create database/user +createuser -s $PGUSER || true +psql -d postgres -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';" +if [ "$PGDATABASE" != "postgres" ]; then + createdb -O $PGUSER $PGDATABASE +fi + +# Build and install pgvector +git clone --branch "v$PGVECTOR_VERSION" https://github.com/pgvector/pgvector.git +cd pgvector +make +make install +cd .. +rm -rf pgvector + +# Create and configure pgvector extension +psql -d $PGDATABASE -c 'CREATE EXTENSION IF NOT EXISTS vector;' + +# Export environment variables +export_var "PGHOST" "localhost" +export_var "PGUSER" "$PGUSER" +export_var "PGPASSWORD" "$PGPASSWORD" +export_var "PGDATABASE" "$PGDATABASE" + +# Verify installation +echo "Checking PostgreSQL installation..." +psql -d $PGDATABASE -c "SELECT version();" +echo "Checking available extensions..." +psql -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';" +echo "Checking installed extensions..." +psql -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';" + +# Print success message +echo "PostgreSQL and pgvector have been successfully installed!" +echo "Connection details:" +echo " Host: localhost" +echo " User: $PGUSER" +echo " Database: $PGDATABASE" +echo " Password: [hidden]" diff --git a/scripts/install-ubuntu.sh b/scripts/install-ubuntu.sh new file mode 100644 index 0000000..e0c6a4c --- /dev/null +++ b/scripts/install-ubuntu.sh @@ -0,0 +1,106 @@ +#!/bin/bash +set -ex + +# Default versions if not provided +PG_VERSION=${1:-17} +PGVECTOR_VERSION=${2:-0.8.0} +PGUSER=${3:-postgres} +PGPASSWORD=${4:-postgres} +PGDATABASE=${5:-postgres} + +echo "Installing PostgreSQL ${PG_VERSION}..." +sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y +sudo apt-get update +sudo apt-get install -y postgresql-${PG_VERSION} + +# Configure PostgreSQL +sudo systemctl stop postgresql +sudo pg_dropcluster --stop ${PG_VERSION} main || true +sudo pg_createcluster ${PG_VERSION} main --start || true +sudo systemctl start postgresql + +# Create runner user and grant permissions +sudo -u postgres psql -c "CREATE USER runner WITH SUPERUSER;" + +# Verify PostgreSQL installation and version +echo "Checking PostgreSQL version..." +PG_ACTUAL_VERSION=$(sudo -u postgres psql -t -c "SHOW server_version;" | xargs) +echo "PostgreSQL actual version: ${PG_ACTUAL_VERSION}" +PG_MAJOR_VERSION=$(echo ${PG_ACTUAL_VERSION} | cut -d. -f1) +echo "PostgreSQL major version: ${PG_MAJOR_VERSION}" + +# Remove any existing pgvector installations +sudo apt-get remove -y postgresql-*-pgvector || true +sudo rm -f /usr/lib/postgresql/*/lib/vector.so +sudo rm -f /usr/share/postgresql/*/extension/vector* + +echo "Installing pgvector..." +# Always build from source to match PostgreSQL version +echo "Building pgvector from source..." +sudo apt-get install -y postgresql-server-dev-${PG_MAJOR_VERSION} build-essential git +git clone --branch v${PGVECTOR_VERSION} https://github.com/pgvector/pgvector.git +cd pgvector +make clean +PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin/pg_config make +sudo PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin/pg_config make install +cd .. +rm -rf pgvector + +# Configure PostgreSQL authentication for CI +echo "local all postgres trust" | sudo tee /etc/postgresql/${PG_VERSION}/main/pg_hba.conf +echo "local all runner trust" | sudo tee -a /etc/postgresql/${PG_VERSION}/main/pg_hba.conf +echo "local all all trust" | sudo tee -a /etc/postgresql/${PG_VERSION}/main/pg_hba.conf +echo "host all all 127.0.0.1/32 trust" | sudo tee -a /etc/postgresql/${PG_VERSION}/main/pg_hba.conf +echo "host all all ::1/128 trust" | sudo tee -a /etc/postgresql/${PG_VERSION}/main/pg_hba.conf + +# Restart PostgreSQL to ensure pgvector is loaded +sudo systemctl restart postgresql + +# Verify pgvector installation +echo "Verifying pgvector installation..." +echo "Installed extensions:" +sudo -u postgres psql -d postgres -c "SELECT * FROM pg_extension;" || true +echo "Available extensions:" +sudo -u postgres psql -d postgres -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';" || true + +# List extension directory contents +echo "Checking extension files..." +echo "PostgreSQL ${PG_MAJOR_VERSION} extension directory:" +ls -la /usr/share/postgresql/${PG_MAJOR_VERSION}/extension/ || true +echo "PostgreSQL ${PG_MAJOR_VERSION} lib directory:" +ls -la /usr/lib/postgresql/${PG_MAJOR_VERSION}/lib/ || true + +# Set password and create database +sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$PGPASSWORD';" +if [ "$PGUSER" != "postgres" ]; then + sudo -u postgres createuser -s $PGUSER + sudo -u postgres psql -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';" +fi +if [ "$PGDATABASE" != "postgres" ]; then + sudo -u postgres createdb -O $PGUSER $PGDATABASE +fi + +# Create and configure pgvector extension +sudo -u postgres psql -d $PGDATABASE -c "CREATE EXTENSION IF NOT EXISTS vector;" + +# Export environment variables +export PGHOST=localhost +export PGUSER=$PGUSER +export PGPASSWORD=$PGPASSWORD +export PGDATABASE=$PGDATABASE + +# Export to GITHUB_ENV only if running in GitHub Actions +if [ -n "$GITHUB_ENV" ]; then + echo "PGHOST=$PGHOST" >> $GITHUB_ENV + echo "PGUSER=$PGUSER" >> $GITHUB_ENV + echo "PGPASSWORD=$PGPASSWORD" >> $GITHUB_ENV + echo "PGDATABASE=$PGDATABASE" >> $GITHUB_ENV +fi + +# Verify installation +echo "Checking PostgreSQL installation..." +psql -d $PGDATABASE -c "SELECT version();" +echo "Checking available extensions..." +psql -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';" +echo "Checking installed extensions..." +psql -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';" diff --git a/scripts/install-windows.sh b/scripts/install-windows.sh new file mode 100644 index 0000000..1b66e30 --- /dev/null +++ b/scripts/install-windows.sh @@ -0,0 +1,114 @@ +#!/bin/bash +set -ex + +# Default versions if not provided +PG_VERSION=${1:-17} +PGVECTOR_VERSION=${2:-0.8.0} +PGUSER=${3:-postgres} +PGPASSWORD=${4:-postgres} +PGDATABASE=${5:-postgres} + +# Function to export variables +export_var() { + local name=$1 + local value=$2 + export "$name=$value" + # Only export to GITHUB_ENV if running in GitHub Actions + if [ -n "$GITHUB_ENV" ]; then + echo "$name=$value" >> $GITHUB_ENV + fi +} + +# Set environment variables +export_var "PGDATA" "/c/data/postgres" +export_var "PGHOST" "localhost" +export_var "PGUSER" "$PGUSER" +export_var "PGPASSWORD" "$PGPASSWORD" +export_var "PGDATABASE" "$PGDATABASE" + +# Initialize PostgreSQL if not already initialized +if [ ! -d "$PGDATA" ]; then + # Create a temporary password file + PWFILE=$(mktemp) + echo "$PGPASSWORD" > "$PWFILE" + + initdb -D "$PGDATA" -U $PGUSER --pwfile="$PWFILE" + rm -f "$PWFILE" + + # Configure PostgreSQL for password authentication + echo "host all all 127.0.0.1/32 md5" >> "$PGDATA/pg_hba.conf" + echo "host all all ::1/128 md5" >> "$PGDATA/pg_hba.conf" + + # Configure logging + cat >> "$PGDATA/postgresql.conf" << EOL +logging_collector = on +log_directory = 'log' +log_filename = 'postgresql-%Y-%m-%d.log' +log_rotation_age = 1d +EOL + + # Create log directory + mkdir -p "$PGDATA/log" +fi + +# Start PostgreSQL +echo "Starting PostgreSQL..." +pg_ctl -D "$PGDATA" -w start + +# Wait for PostgreSQL to start +sleep 3 + +# Show PostgreSQL logs +echo "PostgreSQL log content:" +if [ -f "$PGDATA/log/postgresql-$(date +%Y-%m-%d).log" ]; then + cat "$PGDATA/log/postgresql-$(date +%Y-%m-%d).log" +else + echo "Log file not found. PostgreSQL is still running, continuing..." +fi + +# Create database if it doesn't exist +if [ "$PGDATABASE" != "postgres" ]; then + PGPASSWORD=$PGPASSWORD createdb -h localhost -U $PGUSER $PGDATABASE || true +fi + +# Install build tools and dependencies if running in MSYS2 +if command -v pacman &> /dev/null; then + pacman -S --noconfirm \ + mingw-w64-x86_64-gcc \ + mingw-w64-x86_64-postgresql \ + make +fi + +# Add PostgreSQL binaries to PATH +export PATH="/mingw64/bin:$PATH" +export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH" + +# Build and install pgvector +git clone --branch "v$PGVECTOR_VERSION" https://github.com/pgvector/pgvector.git +cd pgvector +make clean +PG_CONFIG=/mingw64/bin/pg_config make +PG_CONFIG=/mingw64/bin/pg_config make install +cd .. +rm -rf pgvector + +# Create and configure pgvector extension +echo "Creating pgvector extension..." +PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "CREATE EXTENSION IF NOT EXISTS vector;" + +# Verify installation +echo "Checking PostgreSQL installation..." +PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT version();" +echo "Checking available extensions..." +PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';" +echo "Checking installed extensions..." +PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';" + +# Print success message +echo "PostgreSQL and pgvector have been successfully installed!" +echo "Connection details:" +echo " Host: localhost" +echo " User: $PGUSER" +echo " Database: $PGDATABASE" +echo " Password: [hidden]" +echo " Data directory: $PGDATA"