-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·114 lines (97 loc) · 3.14 KB
/
dev.sh
File metadata and controls
executable file
·114 lines (97 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
set -e
CONTAINER_NAME="pg_slug_gen_dev"
DB_NAME="testdb"
DB_USER="postgres"
case "$1" in
start)
echo "Starting PostgreSQL container..."
docker-compose up -d
echo "Waiting for PostgreSQL to be ready..."
sleep 3
echo "PostgreSQL is ready!"
;;
stop)
echo "Stopping PostgreSQL container..."
docker-compose down
;;
restart)
echo "Restarting PostgreSQL container..."
docker-compose restart
;;
build)
echo "Building extension inside container..."
docker exec -u root -it $CONTAINER_NAME bash -c "cd /extension && make clean && make && make install"
echo "Extension built successfully!"
;;
install)
echo "Installing extension in database..."
docker exec -it $CONTAINER_NAME psql -U $DB_USER -d $DB_NAME -c "DROP EXTENSION IF EXISTS pg_slug_gen CASCADE;"
docker exec -it $CONTAINER_NAME psql -U $DB_USER -d $DB_NAME -c "CREATE EXTENSION pg_slug_gen;"
echo "Extension installed successfully!"
;;
rebuild)
echo "Rebuilding and reinstalling extension..."
$0 build
$0 install
;;
psql)
echo "Connecting to PostgreSQL..."
docker exec -it $CONTAINER_NAME psql -U $DB_USER -d $DB_NAME
;;
logs)
echo "Showing PostgreSQL logs..."
docker-compose logs -f
;;
test)
echo "Running regression tests..."
docker exec -u root -it $CONTAINER_NAME bash -c "cd /extension && make installcheck PGUSER=postgres"
echo ""
echo "Check test/regression.diffs for any failures (empty = all passed)"
;;
quicktest)
echo "Running quick manual test..."
docker exec -i $CONTAINER_NAME psql -U $DB_USER -d $DB_NAME << 'EOF'
-- Test different precision levels
SELECT 'Length 10 (seconds):' as test, gen_random_slug(10) as slug;
SELECT 'Length 13 (millis):' as test, gen_random_slug(13) as slug;
SELECT 'Length 16 (micros):' as test, gen_random_slug(16) as slug;
SELECT 'Length 19 (nanos):' as test, gen_random_slug(19) as slug;
SELECT 'Default (16):' as test, gen_random_slug() as slug;
-- Generate multiple slugs
SELECT 'Multiple slugs:' as test;
SELECT gen_random_slug() FROM generate_series(1, 5);
SELECT 'Quick test completed!' as result;
EOF
;;
shell)
echo "Opening shell in container..."
docker exec -it $CONTAINER_NAME bash
;;
clean)
echo "Cleaning build artifacts..."
rm -f *.o *.so *.bc
echo "Clean complete!"
;;
*)
echo "pg_slug_gen Development Helper"
echo ""
echo "Usage: ./dev.sh [command]"
echo ""
echo "Commands:"
echo " start - Start PostgreSQL container"
echo " stop - Stop PostgreSQL container"
echo " restart - Restart PostgreSQL container"
echo " build - Build extension inside container"
echo " install - Install extension in database"
echo " rebuild - Rebuild and reinstall extension"
echo " psql - Connect to PostgreSQL"
echo " logs - Show PostgreSQL logs"
echo " test - Run regression tests (pg_regress)"
echo " quicktest - Run quick manual test"
echo " shell - Open bash shell in container"
echo " clean - Clean build artifacts"
echo ""
exit 1
;;
esac