PSA/ee/server/migrations/citus/test-migrations.sh
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

223 lines
5.8 KiB
Bash
Executable File

#!/bin/bash
# Test script for Citus migrations
# This script sets up a local Citus cluster and runs migrations to verify they work correctly
set -e
echo "================================================"
echo "Citus Migration Test Script"
echo "================================================"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
DB_HOST=${DB_HOST:-localhost}
DB_PORT=${DB_PORT:-5433}
DB_NAME=${DB_NAME:-server_test}
DB_USER=${DB_USER:-postgres}
# Function to check if docker compose is running
check_docker() {
if ! docker info > /dev/null 2>&1; then
echo -e "${RED}Docker is not running. Please start Docker first.${NC}"
exit 1
fi
}
# Function to start Citus cluster
start_citus() {
echo -e "${YELLOW}Starting Citus cluster...${NC}"
docker compose -f docker-compose.test-citus.yaml up -d
echo "Waiting for Citus to be ready..."
sleep 15
# Verify Citus is running
docker exec alga_citus_coordinator psql -U postgres -d server_test -c "SELECT citus_version();" || {
echo -e "${RED}Failed to connect to Citus${NC}"
exit 1
}
echo -e "${GREEN}Citus cluster started successfully${NC}"
}
# Function to stop Citus cluster
stop_citus() {
echo -e "${YELLOW}Stopping Citus cluster...${NC}"
docker compose -f docker-compose.test-citus.yaml down -v
}
# Function to run base migrations
run_base_migrations() {
echo -e "${YELLOW}Running base migrations...${NC}"
# Create a temporary directory for combined migrations
TEMP_DIR=$(mktemp -d)
echo "Using temporary directory: $TEMP_DIR"
# Copy base migrations
cp server/migrations/*.cjs "$TEMP_DIR/" 2>/dev/null || true
# Create temporary knexfile for testing
cat > "$TEMP_DIR/knexfile-test.cjs" << EOF
module.exports = {
test_citus: {
client: 'pg',
connection: {
host: '$DB_HOST',
port: $DB_PORT,
user: '$DB_USER',
password: '$POSTGRES_PASSWORD',
database: '$DB_NAME',
},
pool: {
min: 0,
max: 20,
},
migrations: {
directory: "$TEMP_DIR"
}
}
};
EOF
# Run migrations using npx from project root
npx knex migrate:latest \
--knexfile "$TEMP_DIR/knexfile-test.cjs" \
--env test_citus
# Clean up
rm -rf "$TEMP_DIR"
echo -e "${GREEN}Base migrations completed${NC}"
}
# Function to run Citus migrations
run_citus_migrations() {
echo -e "${YELLOW}Running Citus migrations...${NC}"
# Create a temporary directory for Citus migrations
TEMP_DIR=$(mktemp -d)
echo "Using temporary directory: $TEMP_DIR"
# Copy Citus migrations
cp ee/server/migrations/citus/*.cjs "$TEMP_DIR/" 2>/dev/null || true
# Create temporary knexfile for testing
cat > "$TEMP_DIR/knexfile-test.cjs" << EOF
module.exports = {
test_citus: {
client: 'pg',
connection: {
host: '$DB_HOST',
port: $DB_PORT,
user: '$DB_USER',
password: '$POSTGRES_PASSWORD',
database: '$DB_NAME',
},
pool: {
min: 0,
max: 20,
},
migrations: {
directory: "$TEMP_DIR"
}
}
};
EOF
# Run migrations using npx from project root
npx knex migrate:latest \
--knexfile "$TEMP_DIR/knexfile-test.cjs" \
--env test_citus
# Clean up
rm -rf "$TEMP_DIR"
echo -e "${GREEN}Citus migrations completed${NC}"
}
# Function to verify distribution
verify_distribution() {
echo -e "${YELLOW}Verifying table distribution...${NC}"
docker exec alga_citus_coordinator psql -U postgres -d server_test -c "
SELECT
logicalrelid::regclass AS table_name,
column_to_column_name(logicalrelid, partkey) AS distribution_column,
colocationid AS colocation_group,
partmethod AS method
FROM pg_dist_partition
ORDER BY logicalrelid::regclass::text
LIMIT 10;
"
echo -e "${YELLOW}Checking worker nodes...${NC}"
docker exec alga_citus_coordinator psql -U postgres -d server_test -c "
SELECT * FROM citus_get_active_worker_nodes();
"
echo -e "${YELLOW}Counting distributed tables...${NC}"
docker exec alga_citus_coordinator psql -U postgres -d server_test -c "
SELECT
COUNT(*) as distributed_tables,
COUNT(DISTINCT colocationid) as colocation_groups
FROM pg_dist_partition;
"
}
# Main execution
main() {
case "${1:-}" in
start)
check_docker
start_citus
;;
stop)
stop_citus
;;
migrate)
check_docker
run_base_migrations
run_citus_migrations
verify_distribution
;;
verify)
verify_distribution
;;
full)
check_docker
stop_citus
start_citus
run_base_migrations
run_citus_migrations
verify_distribution
echo -e "${GREEN}Full test completed successfully!${NC}"
;;
clean)
stop_citus
echo -e "${GREEN}Cleanup completed${NC}"
;;
*)
echo "Usage: $0 {start|stop|migrate|verify|full|clean}"
echo ""
echo "Commands:"
echo " start - Start Citus cluster"
echo " stop - Stop Citus cluster"
echo " migrate - Run base and Citus migrations"
echo " verify - Verify table distribution"
echo " full - Run full test (start, migrate, verify)"
echo " clean - Stop and remove all containers/volumes"
exit 1
;;
esac
}
# Run main function
main "$@"