From 0a3a83b00fad41d240cc6649e22407a82bcadbdf Mon Sep 17 00:00:00 2001 From: Darrell Malone Jr Date: Sat, 20 Jan 2024 12:55:50 -0800 Subject: [PATCH] Remove explicit ID declarations from dev_seeds. Corrects and issue where the SQLAlchemy Autoincrement collides with already used IDs. --- alembic/dev_seeds.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/alembic/dev_seeds.py b/alembic/dev_seeds.py index c5d0f70cf..b7ee41410 100644 --- a/alembic/dev_seeds.py +++ b/alembic/dev_seeds.py @@ -6,6 +6,7 @@ from backend.database.models.partner import Partner from backend.database.models.use_of_force import UseOfForce + def create_user(user): user_exists = ( db.session.query(User).filter_by(email=user.email).first() is not None @@ -14,6 +15,7 @@ def create_user(user): if not user_exists: user.create() + def create_partner(partner): partner_exists = ( db.session.query(Partner).filter_by(id=partner.id).first() is not None @@ -22,14 +24,12 @@ def create_partner(partner): if not partner_exists: partner.create() + def create_incident(key=1, date="10-01-2019", lon=84, lat=34): - base_id = 10000000 - id = base_id + key mpv = db.session.query(Partner).filter_by( name="Mapping Police Violence").first() incident = Incident( - id=id, - source_id="1", + source_id=mpv.id, date_record_created=f"{date} 00:00:00", time_of_incident=f"{date} 00:00:00", time_confidence="1", @@ -55,11 +55,12 @@ def create_incident(key=1, date="10-01-2019", lon=84, lat=34): ], use_of_force=[UseOfForce(item=f"gunshot {key}")] ) - exists = db.session.query(Incident).filter_by(id=id).first() is not None + exists = db.session.query(Incident).filter_by(id=key).first() is not None if not exists: incident.create() + def create_seeds(): create_user( User( @@ -103,7 +104,6 @@ def create_seeds(): ) create_partner( Partner( - id="1", name="Mapping Police Violence", url="https://mappingpoliceviolence.us", contact_email="info@campaignzero.org" @@ -118,4 +118,5 @@ def create_seeds(): create_incident(key=7, date="10-01-2020", lon=-118.40853, lat=33.9415889) create_incident(key=8, date="10-15-2020", lon=-84.032149, lat=33.967774) -create_seeds() \ No newline at end of file + +create_seeds()