Skip to content

Commit

Permalink
Remove explicit ID declarations from dev_seeds.
Browse files Browse the repository at this point in the history
Corrects and issue where the SQLAlchemy Autoincrement
collides with already used IDs.
  • Loading branch information
DMalone87 committed Jan 20, 2024
1 parent e2fe232 commit 0a3a83b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions alembic/dev_seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -103,7 +104,6 @@ def create_seeds():
)
create_partner(
Partner(
id="1",
name="Mapping Police Violence",
url="https://mappingpoliceviolence.us",
contact_email="[email protected]"
Expand All @@ -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()

create_seeds()

0 comments on commit 0a3a83b

Please sign in to comment.