Skip to content

Commit ff55103

Browse files
committed
ci: add D1 auto-migrations to deploy workflow
1 parent 92d4107 commit ff55103

4 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎.github/workflows/deploy.yml‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,31 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14-
- uses: cloudflare/wrangler-action@v3
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '20'
19+
20+
- name: Install Wrangler
21+
run: npm install -g wrangler
22+
23+
- name: Run D1 Migrations
24+
working-directory: website
25+
env:
26+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
27+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
28+
run: |
29+
# Apply all migrations in order
30+
for migration in migrations/*.sql; do
31+
if [ -f "$migration" ]; then
32+
echo "Applying migration: $migration"
33+
wrangler d1 execute openboot --remote --file="$migration" || true
34+
fi
35+
done
36+
37+
- name: Deploy Worker
38+
uses: cloudflare/wrangler-action@v3
1539
with:
1640
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
1741
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

‎website/migrations/0001_init.sql‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Migration: 0001_init
2+
-- Created: 2024-02-01
3+
4+
CREATE TABLE IF NOT EXISTS users (
5+
id TEXT PRIMARY KEY,
6+
username TEXT UNIQUE NOT NULL,
7+
email TEXT,
8+
avatar_url TEXT,
9+
created_at TEXT DEFAULT (datetime('now')),
10+
updated_at TEXT DEFAULT (datetime('now'))
11+
);
12+
13+
CREATE TABLE IF NOT EXISTS configs (
14+
id TEXT PRIMARY KEY,
15+
user_id TEXT NOT NULL,
16+
slug TEXT NOT NULL,
17+
name TEXT NOT NULL,
18+
description TEXT,
19+
base_preset TEXT DEFAULT 'developer',
20+
packages TEXT,
21+
custom_script TEXT,
22+
is_public INTEGER DEFAULT 1,
23+
created_at TEXT DEFAULT (datetime('now')),
24+
updated_at TEXT DEFAULT (datetime('now')),
25+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
26+
UNIQUE(user_id, slug)
27+
);
28+
29+
CREATE INDEX IF NOT EXISTS idx_configs_user_id ON configs(user_id);
30+
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Migration: 0002_add_alias
2+
-- Created: 2024-02-01
3+
-- Note: SQLite doesn't support "IF NOT EXISTS" for ALTER TABLE ADD COLUMN
4+
-- This migration may fail if already applied - that's expected behavior
5+
6+
-- Add alias column (will fail if exists - that's OK)
7+
ALTER TABLE configs ADD COLUMN alias TEXT UNIQUE;
8+
9+
-- Create index (idempotent)
10+
CREATE INDEX IF NOT EXISTS idx_configs_alias ON configs(alias);

‎website/wrangler.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ directory = "."
1313
binding = "DB"
1414
database_name = "openboot"
1515
database_id = "6faf0c13-b182-4dca-bf13-ec346d085960"
16+
migrations_dir = "migrations"

0 commit comments

Comments
 (0)