Skip to content

Prevent Renaming Habits With Existing Logs (Clone Instead) #83

Description

@BrayanMQ

Problem

Currently, EditHabitModal.tsx allows users to freely change a habit’s name (title).

This creates a data integrity issue:

  • A habit like "Drink water" can be renamed to "Read in the morning"
  • All existing logs (e.g. 40 days) are then incorrectly associated with the new meaning
  • This rewrites the user’s historical data and breaks trust

A habit with existing logs should not change its meaning, only its presentation.


Goal

Preserve historical accuracy by preventing direct renaming of habits that already have logs.

Instead, when a habit has logs and the user changes its name:

  • The original habit remains unchanged
  • A new habit is created with the new name
  • The streak and logs start fresh for the new habit

Proposed Solution (Option A)

Business Rule

  • ✅ If a habit has no logs → allow editing the name normally
  • ❌ If a habit has at least one log → do NOT rename it

When logs exist and the title is changed:

  1. Show a confirmation modal explaining the consequence
  2. If confirmed:
    • Create a new habit with the updated title
    • Keep the old habit and its logs intact

UX Behavior

When the user tries to change the name of a habit with existing logs:

Modal message (example):

This habit already has recorded history.
Changing its name will create a new habit and keep the previous history intact.

Actions:

  • Cancel
  • Create new habit

Technical Notes

Location

  • EditHabitModal.tsx

Required Checks

Before updating the habit title:

SELECT 1
FROM habit_logs
WHERE habit_id = $1
LIMIT 1;

Logic Flow

  • If no logs → update habit normally
  • If logs exist AND title changed:
    • Prevent direct update
    • Prompt confirmation
    • On confirm:
      • Insert new row into habits
      • Do not modify the original habit

No database migrations are required.


Acceptance Criteria

  • Habits with existing logs cannot have their title directly renamed
  • A confirmation modal is shown when renaming is attempted
  • Confirming creates a new habit instead of updating the existing one
  • Existing logs remain associated with the original habit
  • Habits without logs can still be renamed normally

Future Considerations

This approach intentionally avoids habit versioning for now.

A future improvement could introduce:

  • Habit versioning
  • Archived habits
  • More granular edit rules

This issue focuses on data integrity and minimal schema changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions