From e4e328259805df5d3365b78d96f16130ca822728 Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 4 Nov 2025 20:31:30 -0300 Subject: Update db --- mqtt_client/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'mqtt_client/models.py') diff --git a/mqtt_client/models.py b/mqtt_client/models.py index 98549bc..6b71fe1 100644 --- a/mqtt_client/models.py +++ b/mqtt_client/models.py @@ -1,7 +1,7 @@ from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Boolean from sqlalchemy.orm import relationship from sqlalchemy.sql import func -from database import Base +from .database import Base # ---------------------------- # Location @@ -9,7 +9,7 @@ from database import Base class Location(Base): __tablename__ = "locations" - id = Column(Integer, primary_key=True, index=True) + id = Column(Integer, primary_key=True, index=True, autoincrement=True) street = Column(String(200), nullable=True, index=True) avenue = Column(String(200), nullable=True, index=True) zip_code = Column(String(20), nullable=True, index=True) @@ -24,7 +24,7 @@ class Location(Base): class Station(Base): __tablename__ = "stations" - id = Column(Integer, primary_key=True, index=True) + id = Column(Integer, primary_key=True, index=True, autoincrement=True) name = Column(String(100), nullable=False, index=True) location_id = Column(Integer, ForeignKey("locations.id"), nullable=True, index=True) installation_date = Column(DateTime, server_default=func.now()) @@ -41,7 +41,7 @@ class Station(Base): class SensorDevice(Base): __tablename__ = "sensor_devices" - id = Column(Integer, primary_key=True, index=True) + id = Column(Integer, primary_key=True, index=True, autoincrement=True) name = Column(String(100), nullable=True, index=True) installation_date = Column(DateTime, server_default=func.now()) station_id = Column(Integer, ForeignKey("stations.id"), nullable=True, index=True) @@ -58,7 +58,7 @@ class SensorDevice(Base): class Measure(Base): __tablename__ = "measures" - id = Column(Integer, primary_key=True, index=True) + id = Column(Integer, primary_key=True, index=True, autoincrement=True) name = Column(String(50), nullable=True, index=True) unit_code = Column(String(10), nullable=True) @@ -72,7 +72,7 @@ class Measure(Base): class Reading(Base): __tablename__ = "readings" - id = Column(Integer, primary_key=True, index=True) + id = Column(Integer, primary_key=True, index=True, autoincrement=True) sensor_device_id = Column(Integer, ForeignKey("sensor_devices.id"), nullable=True, index=True) measure_id = Column(Integer, ForeignKey("measures.id"), nullable=True, index=True) value = Column(Float, nullable=True) -- cgit v1.2.3