-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-seed-data.sh
More file actions
executable file
·135 lines (113 loc) · 3.79 KB
/
import-seed-data.sh
File metadata and controls
executable file
·135 lines (113 loc) · 3.79 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# JustGo - Import Seed Data Script
# 匯入台灣旅遊測試資料
# Load environment variables from .env file
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
# Default password if not set in .env
SA_PASSWORD=${SA_PASSWORD:-"JustGo2025!DevSQL#Secure"}
echo "================================================"
echo " JustGo - 匯入測試資料"
echo "================================================"
echo ""
# Check if SQL Server container is running
if ! docker ps | grep justgo-sqlserver > /dev/null; then
echo "❌ Error: SQL Server container is not running."
echo " Please start it first: docker-compose up -d"
exit 1
fi
echo "✓ SQL Server container is running"
echo ""
# Wait for SQL Server to be ready
echo "⏳ Checking SQL Server connection..."
for i in {1..10}; do
if docker exec justgo-sqlserver /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -C -Q "SELECT 1" > /dev/null 2>&1; then
echo "✓ SQL Server is ready"
break
fi
if [ $i -eq 10 ]; then
echo "❌ Error: Cannot connect to SQL Server"
exit 1
fi
echo " Waiting for SQL Server... ($i/10)"
sleep 3
done
echo ""
echo "================================================"
echo " Step 1: Creating database and running migrations"
echo "================================================"
echo ""
# Check if .NET is installed
if ! command -v dotnet &> /dev/null; then
echo "❌ .NET SDK not found. Please install .NET 6.0 SDK first."
exit 1
fi
cd JustGo
# Add dotnet tools to PATH
export PATH="$PATH:$HOME/.dotnet/tools"
# Run EF Core migrations to create database schema
echo "🗄️ Running Entity Framework migrations..."
echo " Creating ApplicationDbContext (Identity)..."
dotnet ef database update --context ApplicationDbContext
if [ $? -ne 0 ]; then
echo "❌ Error: Failed to run ApplicationDbContext migrations"
exit 1
fi
echo " Creating TravelContext (Travel data)..."
dotnet ef database update --context TravelContext
if [ $? -ne 0 ]; then
echo "❌ Error: Failed to run TravelContext migrations"
exit 1
fi
echo "✓ Database schema created successfully"
echo ""
cd ..
echo "================================================"
echo " Step 2: Importing all seed data"
echo " (景點、使用者、部落格)"
echo "================================================"
echo ""
# Import all seed data from consolidated file
docker exec -i justgo-sqlserver /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -C < database/seed-all-data.sql
if [ $? -ne 0 ]; then
echo "❌ Error: Failed to import seed data"
exit 1
fi
echo "✓ All seed data imported successfully"
echo ""
echo "================================================"
echo " ✅ All data imported successfully!"
echo "================================================"
echo ""
echo "Database Summary:"
echo " • 31 台灣景點 (Taiwan places)"
echo " • 5 天氣資料 (Weather data)"
echo " • 3 使用者帳號 (User accounts)"
echo " • 5 旅遊部落格 (Travel blogs)"
echo " • 20 部落格詳細內容 (Blog details)"
echo ""
echo "================================================"
echo " Test User Accounts (測試帳號)"
echo "================================================"
echo ""
echo "1. Email: taiwan.lover@justgo.com"
echo " Password: Test@123"
echo " Name: 台灣旅遊達人"
echo ""
echo "2. Email: mountain.hiker@justgo.com"
echo " Password: Test@123"
echo " Name: 登山小隊長"
echo ""
echo "3. Email: food.explorer@justgo.com"
echo " Password: Test@123"
echo " Name: 美食探險家"
echo ""
echo "================================================"
echo ""
echo "You can now run the application:"
echo " cd JustGo"
echo " dotnet run"
echo ""
echo "Or press F5 in VS Code to start debugging"
echo ""