Add D1 migrations and migrate.sh for notifications tables#63
Conversation
|
Warning Review limit reached
More reviews will be available in 49 minutes and 6 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR establishes automated D1 database migrations for the project. A new ChangesD1 Migration Setup
🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Cloudflare D1 migration support and introduces new database tables for notifications.
Changes:
- Configure Wrangler to use a migrations directory for the D1 database.
- Add initial schema + notifications-related migrations.
- Add a migration shell script and wire it into the Wrangler build step.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| wrangler.toml | Points D1 binding at migrations/ and adds a build hook to run migrations. |
| migrations/0001_initial_schema.sql | Introduces the baseline SQLite/D1 schema and indexes. |
| migrations/0002_add_notifications.sql | Adds notifications and notification_preferences tables + indexes. |
| migrate.sh | Adds a script to apply D1 migrations remotely via Wrangler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@migrate.sh`:
- Line 4: The migrate.sh currently runs "npx wrangler d1 migrations apply
education_db --remote" which applies migrations to production during build;
remove the "--remote" flag (or switch to "--local") in migrate.sh and stop
invoking migrations from the build step (remove or change the [build] command in
wrangler.toml so it only builds app code), then add a separate CI/CD job that
runs "npx wrangler d1 migrations apply education_db --remote" once before
deployment with appropriate locking to prevent concurrent runs; update any
docs/CI config referencing migrate.sh to reflect the new pre-deploy migration
step.
- Around line 1-5: Update migrate.sh to accept environment variables so it's
configurable: read a MIGRATION_ENV (e.g., "remote") to decide whether to include
the --remote flag and read a MIGRATION_DB (default "education_db") to decide the
target DB; modify the call to npx wrangler d1 migrations apply (the script
currently invokes npx wrangler d1 migrations apply education_db --remote) to
build the command using these vars and only append --remote when MIGRATION_ENV
is "remote" (or when a boolean-like var MIGRATION_REMOTE is truthy), and provide
sensible defaults so running bash migrate.sh without env vars behaves the same
as today.
In `@wrangler.toml`:
- Around line 55-56: The wrangler.toml file currently runs database migrations
in the [build] section via "bash migrate.sh", which must be removed; delete the
[build] block (or replace it with only safe build steps like transpile/bundle
commands) and stop invoking migrate.sh during build, then run D1 migrations as a
separate pre-deploy step (or CI job) using the Wrangler migrations command and
keep the existing migrations_dir setting so Wrangler can track applied
migrations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2f458712-9699-4c6c-8526-c96328c30536
⛔ Files ignored due to path filters (2)
migrations/0001_initial_schema.sqlis excluded by!**/migrations/**migrations/0002_add_notifications.sqlis excluded by!**/migrations/**
📒 Files selected for processing (2)
migrate.shwrangler.toml
Added migrations/ folder with two migration files, migrate.sh, and wired [build] command = "bash migrate.sh" into wrangler.toml so migrations run automatically on every deploy.
Also added migrations_dir = "migrations" so Wrangler tracks applied migrations.
Tested locally — 0001 and 0002 apply cleanly.
Overview
This PR establishes a structured D1 database migration system for the project by introducing automated migration management with two SQL migration files, a migration runner script, and wrangler configuration updates.
Key Changes
Migration Files
users,activities,sessions,enrollments,session_attendance,tags, andactivity_tagstables with appropriate foreign keys, indexes, and default timestamps.notificationsandnotification_preferencestables, enabling users to receive and manage notification preferences across enrollment, session, and system event types.Migration Infrastructure
education_dbusingnpx wrangler d1 migrations apply education_db --remote, with error handling and status logging.migrations_dir = "migrations"for Wrangler to track applied migrations[build]section withcommand = "bash migrate.sh"to automatically apply migrations on every deploymentImpact