-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-mysql-tables.ps1
More file actions
94 lines (85 loc) · 3.91 KB
/
Copy pathsetup-mysql-tables.ps1
File metadata and controls
94 lines (85 loc) · 3.91 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
# OrderNet MySQL Database Setup Script (PowerShell)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "OrderNet MySQL Database Setup" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Check if MySQL is installed
try {
$mysqlVersion = mysql --version 2>$null
if ($LASTEXITCODE -ne 0) {
throw "MySQL not found"
}
Write-Host "MySQL found: $mysqlVersion" -ForegroundColor Green
} catch {
Write-Host "MySQL command line client not found in PATH." -ForegroundColor Red
Write-Host ""
Write-Host "Please install MySQL or add it to your PATH." -ForegroundColor Yellow
Write-Host ""
Write-Host "You can:" -ForegroundColor Yellow
Write-Host "1. Install MySQL Server from: https://dev.mysql.com/downloads/mysql/" -ForegroundColor Yellow
Write-Host "2. Or use Docker: docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:8.0" -ForegroundColor Yellow
Write-Host ""
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "Starting database setup..." -ForegroundColor Green
Write-Host ""
# Prompt for MySQL root password
$mysqlPassword = Read-Host "Enter MySQL root password (default: password)"
if ([string]::IsNullOrEmpty($mysqlPassword)) {
$mysqlPassword = "password"
}
Write-Host ""
Write-Host "Creating OrderNet database and tables..." -ForegroundColor Green
Write-Host ""
# Run the SQL script
try {
mysql -u root -p$mysqlPassword -e "source mysql-tables.sql"
if ($LASTEXITCODE -eq 0) {
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "SUCCESS! OrderNet database setup complete." -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host "Database: ordernet_db" -ForegroundColor Yellow
Write-Host "Tables created:" -ForegroundColor Yellow
Write-Host "- users" -ForegroundColor White
Write-Host "- categories" -ForegroundColor White
Write-Host "- products" -ForegroundColor White
Write-Host "- images" -ForegroundColor White
Write-Host "- addresses" -ForegroundColor White
Write-Host "- carts" -ForegroundColor White
Write-Host "- cart_items" -ForegroundColor White
Write-Host "- orders" -ForegroundColor White
Write-Host "- order_items" -ForegroundColor White
Write-Host "- reviews" -ForegroundColor White
Write-Host "- refresh_tokens" -ForegroundColor White
Write-Host "- password_reset_tokens" -ForegroundColor White
Write-Host "- files" -ForegroundColor White
Write-Host ""
Write-Host "Sample data inserted:" -ForegroundColor Yellow
Write-Host "- 5 categories" -ForegroundColor White
Write-Host "- 1 admin user (admin@ordernet.com / admin123)" -ForegroundColor White
Write-Host "- 1 customer user (customer@ordernet.com / customer123)" -ForegroundColor White
Write-Host "- 5 sample products" -ForegroundColor White
Write-Host "- 1 sample address" -ForegroundColor White
Write-Host ""
Write-Host "You can now start your Spring Boot application!" -ForegroundColor Green
} else {
throw "MySQL command failed"
}
} catch {
Write-Host ""
Write-Host "========================================" -ForegroundColor Red
Write-Host "ERROR! Database setup failed." -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host ""
Write-Host "Please check:" -ForegroundColor Yellow
Write-Host "1. MySQL is running" -ForegroundColor Yellow
Write-Host "2. Root password is correct" -ForegroundColor Yellow
Write-Host "3. You have permission to create databases" -ForegroundColor Yellow
Write-Host ""
}
Write-Host ""
Read-Host "Press Enter to exit"