forked from simplcommerce/SimplCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpl-build.sh
More file actions
executable file
·72 lines (61 loc) · 3.01 KB
/
simpl-build.sh
File metadata and controls
executable file
·72 lines (61 loc) · 3.01 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
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
WEBHOST_DIR="$SCRIPT_DIR/src/SimplCommerce.WebHost"
DB_FILE="$WEBHOST_DIR/simplcommerce.db"
DB_DIR="$SCRIPT_DIR/src/Database"
# ── dotnet-ef ────────────────────────────────────────────────────────────────
if ! dotnet ef --version &>/dev/null 2>&1; then
echo "Installing dotnet-ef 8.0.0..."
dotnet tool install --global dotnet-ef --version 8.0.0
export PATH="$PATH:$HOME/.dotnet/tools"
fi
# ── Build ────────────────────────────────────────────────────────────────────
dotnet restore && dotnet build
# ── Migrations ───────────────────────────────────────────────────────────────
rm -f "$DB_FILE"
rm -rf "$WEBHOST_DIR/Migrations"
mkdir -p "$WEBHOST_DIR/Migrations"
cd "$WEBHOST_DIR"
dotnet ef migrations add initialSchema
dotnet ef database update
# ── Seed static data ─────────────────────────────────────────────────────────
# The .sql files use SQL Server syntax; convert on-the-fly before importing.
python3 - "$DB_FILE" "$DB_DIR" <<'PYEOF'
import re, subprocess, sys, os
db = sys.argv[1]
ddir = sys.argv[2]
def to_sqlite(sql):
sql = re.sub(r'\[dbo\]\.', '', sql) # remove [dbo]. schema prefix
sql = re.sub(r'^\s*GO\s*$', '', sql, flags=re.MULTILINE) # remove GO batch separators
sql = re.sub(r"\bN'", "'", sql) # strip N'' unicode prefix
sql = sql.replace('&', '&') # unescape HTML entities
lines = []
for line in sql.splitlines():
s = line.rstrip()
if re.match(r'\s*INSERT\s+\[', s): # INSERT -> INSERT INTO
s = re.sub(r'\bINSERT\s+\[', 'INSERT INTO [', s)
if s.endswith(')') and re.match(r'\s*INSERT', s): # add missing semicolons
s += ';'
lines.append(s)
return '\n'.join(lines)
files = [
"Countries.sql",
"StaticData-US.sql",
"StaticData-DefaultLocalization.sql",
]
for fname in files:
path = os.path.join(ddir, fname)
with open(path, encoding='utf-8-sig') as f:
sql = to_sqlite(f.read())
result = subprocess.run(["sqlite3", db], input=sql, capture_output=True, text=True)
if result.returncode != 0:
print(f" ERROR seeding {fname}:\n{result.stderr[:400]}")
sys.exit(1)
else:
print(f" Seeded: {fname}")
PYEOF
echo ""
echo "Done. SQLite database created at: $DB_FILE"
echo "Run the app with: cd src/SimplCommerce.WebHost && dotnet run"
echo "Admin: http://localhost:5000/Admin | admin@simplcommerce.com / 1qazZAQ!"