Skip to content

Commit 02271b7

Browse files
2 parents 3752ab5 + f302f05 commit 02271b7

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

.github/workflows/blank.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Generate Prisma Schema from SQL
2+
3+
on:
4+
push:
5+
paths:
6+
- 'LearningManagementSystems/**/*.sql'
7+
- '!**/*.prisma' # Не запускать, если меняется только .prisma
8+
branches:
9+
- main
10+
- master
11+
12+
jobs:
13+
generate-prisma:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
ref: ${{ github.head_ref || github.ref }}
24+
25+
- name: Set up Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '18'
29+
30+
- name: Install Prisma CLI
31+
run: npm install -g prisma
32+
33+
- name: Find SQL files
34+
id: find_sql
35+
run: |
36+
SQL_FILES=$(find LearningManagementSystems -name "*.sql" -type f)
37+
if [ -z "$SQL_FILES" ]; then
38+
echo "No SQL files found"
39+
exit 1
40+
fi
41+
echo "files=$SQL_FILES" >> $GITHUB_OUTPUT
42+
43+
- name: Process each SQL file
44+
run: |
45+
while IFS= read -r sql_file; do
46+
echo "Processing $sql_file"
47+
48+
# Определяем путь к Prisma-файлу
49+
prisma_file="${sql_file%.sql}.prisma"
50+
temp_db="/tmp/$(basename ${sql_file%.sql}).db"
51+
52+
# Создаём временную SQLite базу
53+
sqlite3 "$temp_db" < "$sql_file"
54+
55+
# Если Prisma-файл ещё не существует — создаём новый schema.prisma
56+
if [ ! -f "$prisma_file" ]; then
57+
mkdir -p "$(dirname "$prisma_file")"
58+
cat > "$prisma_file" << EOF
59+
// Auto-generated from $sql_file
60+
generator client {
61+
provider = "prisma-client-js"
62+
}
63+
64+
datasource db {
65+
provider = "mysql"
66+
url = "file:$temp_db"
67+
}
68+
69+
// Models will be added below
70+
EOF
71+
fi
72+
73+
# Интроспекция: получаем схему из SQL через SQLite
74+
npx prisma db pull --schema="$prisma_file" --force
75+
76+
# Форматируем
77+
npx prisma format --schema="$prisma_file"
78+
79+
echo "✅ Generated Prisma schema: $prisma_file"
80+
done <<< "$(find LearningManagementSystems -name "*.sql" -type f)"
81+
82+
- name: Commit and Push Prisma files
83+
run: |
84+
git config user.name "github-actions[bot]"
85+
git config user.email "github-actions[bot]@users.noreply.github.com"
86+
87+
# Добавляем все .prisma файлы
88+
git add **/*.prisma
89+
90+
# Проверяем, есть ли изменения
91+
if git diff-index --quiet HEAD --; then
92+
echo "✅ No changes to commit"
93+
exit 0
94+
else
95+
git commit -m "🤖 Auto-generate Prisma schema from SQL
96+
Generated via GitHub Actions when SQL was updated."
97+
git push origin HEAD:main
98+
echo "✅ Prisma schemas committed and pushed"
99+
fi

0 commit comments

Comments
 (0)