Skip to content

Add D1 migrations and migrate.sh for notifications tables#63

Merged
A1L13N merged 3 commits into
alphaonelabs:mainfrom
Ananya44444:mig
Jun 3, 2026
Merged

Add D1 migrations and migrate.sh for notifications tables#63
A1L13N merged 3 commits into
alphaonelabs:mainfrom
Ananya44444:mig

Conversation

@Ananya44444
Copy link
Copy Markdown
Contributor

@Ananya44444 Ananya44444 commented Jun 2, 2026

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

  • 0001_initial_schema.sql: Creates the foundational database schema including users, activities, sessions, enrollments, session_attendance, tags, and activity_tags tables with appropriate foreign keys, indexes, and default timestamps.
  • 0002_add_notifications.sql: Adds notification functionality with notifications and notification_preferences tables, enabling users to receive and manage notification preferences across enrollment, session, and system event types.

Migration Infrastructure

  • migrate.sh: Bash script that applies D1 migrations to education_db using npx wrangler d1 migrations apply education_db --remote, with error handling and status logging.
  • wrangler.toml: Updated to:
    • Define migrations_dir = "migrations" for Wrangler to track applied migrations
    • Add [build] section with command = "bash migrate.sh" to automatically apply migrations on every deployment

Impact

  • Enables consistent database schema versioning and automated deployment of database changes across environments
  • Introduces notification infrastructure supporting multi-type notifications with user preferences and read status tracking
  • Ensures migrations run with proper error handling and remote database synchronization during builds

Copilot AI review requested due to automatic review settings June 2, 2026 22:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

Warning

Review limit reached

@Ananya44444, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: af888439-6f92-43f5-81cf-6ace8f77050c

📥 Commits

Reviewing files that changed from the base of the PR and between efcd0e3 and c8e15e0.

📒 Files selected for processing (1)
  • migrate.sh

Walkthrough

This PR establishes automated D1 database migrations for the project. A new migrate.sh bash script applies migrations remotely to education_db, and wrangler.toml is updated to specify the migrations directory and run the script during the build process.

Changes

D1 Migration Setup

Layer / File(s) Summary
Migration script execution
migrate.sh
New script that runs npx wrangler d1 migrations apply against education_db --remote with fail-fast behavior (set -e) and logging bookends.
Build and migrations configuration
wrangler.toml
Configures migrations_dir = "migrations" to point to the D1 migrations source and adds a [build] section with command = "bash migrate.sh" to execute migrations during the build.

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding D1 migrations and a migrate.sh script for notifications tables, which aligns with all changes in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread wrangler.toml
Comment thread migrate.sh
Comment thread migrations/0002_add_notifications.sql
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5858a40 and efcd0e3.

⛔ Files ignored due to path filters (2)
  • migrations/0001_initial_schema.sql is excluded by !**/migrations/**
  • migrations/0002_add_notifications.sql is excluded by !**/migrations/**
📒 Files selected for processing (2)
  • migrate.sh
  • wrangler.toml

Comment thread migrate.sh
Comment thread migrate.sh Outdated
Comment thread wrangler.toml
@A1L13N A1L13N merged commit 1db8387 into alphaonelabs:main Jun 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants