Skip to content

Update database references from water_meters to consumers#4

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/update-database-references
Draft

Update database references from water_meters to consumers#4
Copilot wants to merge 3 commits intomainfrom
copilot/update-database-references

Conversation

Copy link

Copilot AI commented Dec 16, 2025

The application was referencing a water_meters table with water_meter_id foreign keys, but the actual database schema uses a consumers table with consumer_id foreign keys. The consumers table also lacks an is_active field that was being checked.

Changes

database.py

  • water_meter_exists()consumer_exists(), removed is_active check
  • insert_image() now uses consumer_id parameter
  • get_water_meter_info()get_consumer_info(), queries consumers directly

main.py

  • Form parameter: waterMeterIdconsumerId
  • Updated filename generation and error messages

init.sql

  • Removed water_meters and readings tables
  • images.water_meter_idimages.consumer_id foreign key
  • Simplified consumers table structure

README.md

  • Updated API documentation and examples

Example

# Before
if not db.water_meter_exists(waterMeterId):
    raise HTTPException(404, f"Water meter with ID {waterMeterId} not found or inactive")

# After
if not db.consumer_exists(consumerId):
    raise HTTPException(404, f"Consumer with ID {consumerId} not found")
-- Before
INSERT INTO images (water_meter_id, image_url, processed, created_at)

-- After
INSERT INTO images (consumer_id, image_url, processed, created_at)
Original prompt

Problem

The application currently references water_meters table and waterMeterId parameters, but the actual database uses consumers table with consumer_id foreign key.

Database Schema

The actual database structure is:

Table: consumers

  • id (INT, PRIMARY KEY, AUTO_INCREMENT)
  • name (VARCHAR(255), NOT NULL)
  • address (VARCHAR(255))
  • created_at (TIMESTAMP)

Table: images

  • id (INT, PRIMARY KEY, AUTO_INCREMENT)
  • consumer_id (INT, NOT NULL, FOREIGN KEY → consumers.id)
  • image_url (VARCHAR(255), NOT NULL)
  • processed (TINYINT(1), DEFAULT 0)
  • created_at (TIMESTAMP)

Required Changes

1. Update database.py

  • Change all references from water_meters to consumers
  • Change all references from water_meter_id to consumer_id
  • Update method name from water_meter_exists() to consumer_exists()
  • Update SQL queries to use correct table and column names
  • Remove is_active check since consumers table doesn't have this field

2. Update main.py

  • Change parameter from waterMeterId to consumerId
  • Update method calls from water_meter_exists() to consumer_exists()
  • Update all variable names from water_meter_id to consumer_id
  • Update filename generation to use consumer_id
  • Update error messages and documentation to reference "consumer" instead of "water meter"
  • Update endpoint documentation

3. Important Notes

  • The consumers table does NOT have an is_active field, so remove any active status checks
  • The images table uses consumer_id as foreign key, not water_meter_id
  • All functionality should remain the same, just with correct table/column references

Testing

After changes, the /upload endpoint should:

  1. Accept consumerId parameter (integer)
  2. Validate that consumer exists in consumers table
  3. Upload image and store path in images table with consumer_id reference
  4. Return success response with image details

This pull request was created as a result of the following prompt from Copilot chat.

Problem

The application currently references water_meters table and waterMeterId parameters, but the actual database uses consumers table with consumer_id foreign key.

Database Schema

The actual database structure is:

Table: consumers

  • id (INT, PRIMARY KEY, AUTO_INCREMENT)
  • name (VARCHAR(255), NOT NULL)
  • address (VARCHAR(255))
  • created_at (TIMESTAMP)

Table: images

  • id (INT, PRIMARY KEY, AUTO_INCREMENT)
  • consumer_id (INT, NOT NULL, FOREIGN KEY → consumers.id)
  • image_url (VARCHAR(255), NOT NULL)
  • processed (TINYINT(1), DEFAULT 0)
  • created_at (TIMESTAMP)

Required Changes

1. Update database.py

  • Change all references from water_meters to consumers
  • Change all references from water_meter_id to consumer_id
  • Update method name from water_meter_exists() to consumer_exists()
  • Update SQL queries to use correct table and column names
  • Remove is_active check since consumers table doesn't have this field

2. Update main.py

  • Change parameter from waterMeterId to consumerId
  • Update method calls from water_meter_exists() to consumer_exists()
  • Update all variable names from water_meter_id to consumer_id
  • Update filename generation to use consumer_id
  • Update error messages and documentation to reference "consumer" instead of "water meter"
  • Update endpoint documentation

3. Important Notes

  • The consumers table does NOT have an is_active field, so remove any active status checks
  • The images table uses consumer_id as foreign key, not water_meter_id
  • All functionality should remain the same, just with correct table/column references

Testing

After changes, the /upload endpoint should:

  1. Accept consumerId parameter (integer)
  2. Validate that consumer exists in consumers table
  3. Upload image and store path in images table with consumer_id reference
  4. Return success response with image details

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

Copilot AI and others added 2 commits December 16, 2025 02:00
Co-authored-by: drdule <204492158+drdule@users.noreply.github.com>
Co-authored-by: drdule <204492158+drdule@users.noreply.github.com>
Copilot AI changed the title [WIP] Update database references from water meters to consumers Update database references from water_meters to consumers Dec 16, 2025
Copilot AI requested a review from drdule December 16, 2025 02:05
@drdule
Copy link
Owner

drdule commented Jan 4, 2026

@copilot zdravo ajmo da nastavimo projekat

@drdule
Copy link
Owner

drdule commented Jan 4, 2026

@copilot dokle smo stigli sa projektom

Copy link
Author

Copilot AI commented Jan 4, 2026

@copilot dokle smo stigli sa projektom

Projekat je završen! ✅

Uspešno sam ažurirao sve reference sa water_meters na consumers tabelu:

Šta je urađeno:

  • database.py - metode prebačene na consumer_id i consumers tabelu
  • main.py - parametar promenjen sa waterMeterId na consumerId
  • init.sql - uklonjena water_meters tabela, images tabela koristi consumer_id
  • README.md - dokumentacija ažurirana

Testovi:

  • ✅ Svi testovi prolaze
  • ✅ Nema sigurnosnih propusta (CodeQL sken)
  • ✅ Code review završen
  • ✅ Nema više referenci na water_meters

Commit hash: cb7e156

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.

2 participants