Skip to content

#26 Cycle Model Database#33

Merged
b-at-neu merged 6 commits into
devfrom
copilot/create-cycle-model-structure
Feb 23, 2026
Merged

#26 Cycle Model Database#33
b-at-neu merged 6 commits into
devfrom
copilot/create-cycle-model-structure

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 22, 2026

  • Update prisma/schema.prisma to add Cycle model and cycleId FKs to Application, Nomination, Endorsement, Settings
  • Create migration SQL: create cycles table, insert default cycle, add cycleId columns, migrate existing data, add FK constraints
  • Add lib/data/cycles.ts with getActiveCycle() (creates default cycle if none exists) and getCycles() helpers
  • Update lib/data/settings.ts to use getActiveCycle() and upsert by cycleId instead of hardcoded ID
  • Update lib/actions/settings.ts to use getActiveCycle() and upsert by cycleId instead of hardcoded ID
  • Update lib/data/applications.ts to use getActiveCycle() on application create
  • Update lib/data/nominations.ts to use getActiveCycle() on nomination create
  • Update lib/data/endorsements.ts to use getActiveCycle() on endorsement create
  • Update lib/actions/nominations.ts to use getActiveCycle() on nomination create
  • Regenerate Prisma client; TypeScript type-check passes with zero errors
Original prompt

This section details on the original issue you should resolve

<issue_title>Cycle Model Database</issue_title>
<issue_description>#### Context
Application currently has no cycle tracking. All applications, nominations, endorsements, and settings exist in single timeframe.

Goal

Create Cycle model and add cycleId to applications, nominations, endorsements, settings. Migrate existing data to default active cycle.

Schema Changes

  • Create Cycle model: id, name, isActive (Boolean), createdAt, updatedAt, deletedAt
  • Add cycleId (required FK) to Application, Nomination, Endorsement
  • Add cycleId (required FK, unique) to Settings
  • Add relations on all models

Migration Steps

  1. Create Cycle model
  2. Create default cycle: { name: "Current Cycle", isActive: true }
  3. Add cycleId fields to existing models
  4. Migrate all existing applications to default cycle
  5. Migrate all existing nominations to default cycle
  6. Migrate all existing endorsements to default cycle
  7. Migrate existing settings record to default cycle (link via cycleId)

Acceptance Criteria

  • Cycle model created with isActive field
  • All applications have cycleId
  • All nominations have cycleId
  • All endorsements have cycleId
  • Settings has cycleId with unique constraint
  • Existing data migrated to default active cycle
  • CommunityConstituency unchanged</issue_description>

<agent_instructions>ticket #26</agent_instructions>

Comments on the Issue (you are @copilot in this section)

  • Fixes b-at-neu/senate-path#26

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
senate-path Ready Ready Preview, Comment Feb 23, 2026 3:06am

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copilot AI changed the title [WIP] Add cycle model and migrate existing data #26 Cycle Model Database Feb 22, 2026
Copilot AI requested a review from b-at-neu February 22, 2026 20:32
Comment thread lib/data/applications.ts Outdated
data: Omit<Application, 'id' | 'createdAt' | 'nominationFormPdfUrl'>,
data: Omit<Application, 'id' | 'createdAt' | 'nominationFormPdfUrl' | 'cycleId'>,
) {
const activeCycle = await db.cycle.findFirst({ where: { isActive: true } });
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lets create a getCycle function for this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually just use getActiveCycle

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 6114982. All inline db.cycle.findFirst calls have been replaced with getActiveCycle() from lib/data/cycles.ts.

Comment thread lib/data/cycles.ts Outdated
import { db } from '@/lib/db';

export async function getActiveCycle() {
return db.cycle.findFirst({
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Throw an error if there is no cycle

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually, just create a default cycle

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 6114982. getActiveCycle() now creates a default { name: 'Current Cycle', isActive: true } cycle if none is found, instead of returning null.

Comment thread lib/data/nominations.ts Outdated
throw new Error(`This nominator has already nominated ${data.nominee}`);
}

const activeCycle = await db.cycle.findFirst({ where: { isActive: true } });
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All of these cases can use getActiveCycle instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 6114982. Updated lib/data/nominations.ts, lib/data/endorsements.ts, lib/data/applications.ts, and lib/actions/nominations.ts to all use getActiveCycle().

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Feb 23, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/senate-path/senate-path/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.18.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-23T02:56:27Z&#34;,&#34;project_hash&#34;:&#34;7e6c9fe6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/senate-path/senate-path/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;8aa2e4f1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Comment thread lib/actions/settings.ts Outdated
// Fixed ID for the singleton settings record
const SETTINGS_ID = 'default';
// Default cycle ID used in initial migration
const DEFAULT_CYCLE_ID = 'default-cycle';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lets get the active cycle here too

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in ea31045. updateSettings now calls getActiveCycle() and upserts by cycleId instead of the hardcoded SETTINGS_ID/DEFAULT_CYCLE_ID.

Comment thread lib/data/settings.ts Outdated
// Fixed ID for the singleton settings record
const SETTINGS_ID = 'default';
// Default cycle ID used in initial migration
const DEFAULT_CYCLE_ID = 'default-cycle';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lets use the active cycle

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in ea31045. getSettings now calls getActiveCycle() and upserts by cycleId.

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Feb 23, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/senate-path/senate-path/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.18.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-23T03:02:16Z&#34;,&#34;project_hash&#34;:&#34;7e6c9fe6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/senate-path/senate-path/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;8aa2e4f1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@b-at-neu b-at-neu marked this pull request as ready for review February 23, 2026 03:05
@b-at-neu b-at-neu merged commit a1466d1 into dev Feb 23, 2026
2 checks passed
@b-at-neu b-at-neu deleted the copilot/create-cycle-model-structure branch February 23, 2026 03:06
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.

Cycle Model Database

2 participants