fix: streamline database table creation in ensure_tables function and… #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| # ── Lint & unit tests (no database needed) ────────────────────────────────── | |
| check: | |
| name: Lint & Unit Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - name: Cache Cargo registry & build | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Run Clippy | |
| run: cargo clippy -- -A clippy:manual_inspect | |
| - name: Build | |
| run: cargo build --verbose | |
| - name: Run unit tests | |
| run: cargo test --test unit --verbose | |
| # ── Integration tests (requires Postgres) ─────────────────────────────────── | |
| integration: | |
| name: Integration Tests | |
| runs-on: ubuntu-latest | |
| needs: check | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: test | |
| POSTGRES_PASSWORD: test | |
| POSTGRES_DB: zcloudpass_test | |
| options: >- | |
| --health-cmd "pg_isready -U test" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| env: | |
| DATABASE_URL: postgres://test:test@localhost:5432/zcloudpass_test | |
| RUST_TEST_THREADS: 1 | |
| RUST_BACKTRACE: 1 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache Cargo registry & build | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Wait for Postgres and prepare DB | |
| run: | | |
| echo "Waiting for Postgres to accept connections..." | |
| for i in {1..30}; do | |
| pg_isready -h localhost -p 5432 -U test && break || sleep 1 | |
| done | |
| export PGPASSWORD=test | |
| echo "Creating clean test schema" | |
| psql -h localhost -U test -d zcloudpass_test -c "DROP TABLE IF EXISTS sessions CASCADE; DROP TABLE IF EXISTS users CASCADE;" | |
| psql -h localhost -U test -d zcloudpass_test -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;" | |
| psql -h localhost -U test -d zcloudpass_test -c "CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, username VARCHAR(255), email VARCHAR(255) UNIQUE NOT NULL, srp_salt TEXT, srp_verifier TEXT, encrypted_vault TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, last_login TIMESTAMP, account_status VARCHAR(20) DEFAULT 'active');" | |
| psql -h localhost -U test -d zcloudpass_test -c "CREATE TABLE IF NOT EXISTS sessions (id SERIAL PRIMARY KEY, user_id INT REFERENCES users(id) ON DELETE CASCADE, session_token TEXT UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at TIMESTAMP, last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP);" | |
| - name: Run integration tests | |
| run: | | |
| export DATABASE_URL="postgres://test:test@localhost:5432/zcloudpass_test" | |
| export RUST_TEST_THREADS=1 | |
| export RUST_BACKTRACE=1 | |
| cargo test --test integration --verbose |