Altered the Cardinality of the foreign keys to be non-nullable

This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2025-06-05 22:01:54 -03:00
parent be1bce9261
commit 103b9a9da1
5 changed files with 21 additions and 10 deletions

View File

@ -4,8 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="0a7f92e2-b44a-4dfe-8e01-136d1c0c18be" name="Changes" comment="Made some changes to naming in both the classes and the tables of the database to conform the correct naming scheme">
<change beforePath="$PROJECT_DIR$/src/pilgrim/command.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/command.py" afterDir="false" />
<list default="true" id="0a7f92e2-b44a-4dfe-8e01-136d1c0c18be" name="Changes" comment="Added the travel_diary id as foreign key to the photos and add a check on the creation to avoid leaving it empty or bad referenced">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pilgrim/models/entry.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/entry.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pilgrim/models/photo.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/photo.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pilgrim/models/photo_in_entry.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/photo_in_entry.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pilgrim/service/entry_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/service/entry_service.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -154,7 +158,15 @@
<option name="project" value="LOCAL" />
<updated>1749164385581</updated>
</task>
<option name="localTasksCounter" value="6" />
<task id="LOCAL-00006" summary="Added the travel_diary id as foreign key to the photos and add a check on the creation to avoid leaving it empty or bad referenced">
<option name="closed" value="true" />
<created>1749168650225</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1749168650225</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -177,7 +189,8 @@
<MESSAGE value="Added the Services layer to the code to do the database operation" />
<MESSAGE value="Added the photo_service.py and modified photo.py to have all the crud operations" />
<MESSAGE value="Made some changes to naming in both the classes and the tables of the database to conform the correct naming scheme" />
<option name="LAST_COMMIT_MESSAGE" value="Made some changes to naming in both the classes and the tables of the database to conform the correct naming scheme" />
<MESSAGE value="Added the travel_diary id as foreign key to the photos and add a check on the creation to avoid leaving it empty or bad referenced" />
<option name="LAST_COMMIT_MESSAGE" value="Added the travel_diary id as foreign key to the photos and add a check on the creation to avoid leaving it empty or bad referenced" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/Pilgrim$Database.coverage" NAME="Database Coverage Results" MODIFIED="1748987101492" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/src/Database" />

View File

@ -17,7 +17,7 @@ class Entry(Base):
"Photo",
secondary=photo_entry_association,
back_populates="entries")
fk_travel_diary_id = Column(Integer, ForeignKey("travel_diaries.id"))
fk_travel_diary_id = Column(Integer, ForeignKey("travel_diaries.id"),nullable=False)
def __init__(self, title: str, text: str, date: str, travel_diary_id: int, **kw: Any):
super().__init__(**kw)
self.title = title

View File

@ -20,7 +20,7 @@ class Photo(Base):
back_populates="photos"
)
fk_travel_diary_id = Column(Integer, ForeignKey("travel_diaries.id"))
fk_travel_diary_id = Column(Integer, ForeignKey("travel_diaries.id"),nullable=False)
def __init__(self, filepath, name, addition_date=None, caption=None, entries=None, **kw: Any):
super().__init__(**kw)

View File

@ -4,5 +4,5 @@ from ..database import Base
photo_entry_association = Table('photo_entry_association', Base.metadata,
Column('id', Integer, primary_key=True, autoincrement=True),
Column('fk_photo_id', Integer, ForeignKey('photos.id')),
Column('fk_entry_id', Integer, ForeignKey('entries.id')))
Column('fk_photo_id', Integer, ForeignKey('photos.id'),nullable=False),
Column('fk_entry_id', Integer, ForeignKey('entries.id'),nullable=False))

View File

@ -16,8 +16,6 @@ class EntryService:
self.session.add(new_entry)
self.session.commit()
self.session.refresh(new_entry)
return new_entry
def read_by_id(self,entry_id:int)->Entry: