diff --git a/alembic/dev_seeds.py b/alembic/dev_seeds.py index 243059150..c5d0f70cf 100644 --- a/alembic/dev_seeds.py +++ b/alembic/dev_seeds.py @@ -6,7 +6,6 @@ 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 @@ -15,52 +14,6 @@ def create_user(user): if not user_exists: user.create() - -create_user( - User( - email="test@example.com", - password=user_manager.hash_password("password"), - role=UserRole.PUBLIC, - first_name="Test", - last_name="Example", - phone_number="(123) 456-7890", - ) -) - -create_user( - User( - email="contributor@example.com", - password=user_manager.hash_password("password"), - role=UserRole.CONTRIBUTOR, - first_name="Contributor", - last_name="Example", - phone_number="(123) 456-7890", - ) -) - -create_user( - User( - email="admin@example.com", - password=user_manager.hash_password("password"), - role=UserRole.ADMIN, - first_name="Admin", - last_name="Example", - phone_number="(012) 345-6789", - ) -) - -create_user( - User( - email="passport@example.com", - password=user_manager.hash_password("password"), - role=UserRole.PASSPORT, - first_name="Passport", - last_name="Example", - phone_number="(012) 345-6789", - ) -) - - def create_partner(partner): partner_exists = ( db.session.query(Partner).filter_by(id=partner.id).first() is not None @@ -69,17 +22,6 @@ def create_partner(partner): if not partner_exists: partner.create() - -create_partner( - Partner( - id="1", - name="Mapping Police Violence", - url="https://mappingpoliceviolence.us", - contact_email="info@campaignzero.org" - ) -) - - def create_incident(key=1, date="10-01-2019", lon=84, lat=34): base_id = 10000000 id = base_id + key @@ -118,12 +60,62 @@ def create_incident(key=1, date="10-01-2019", lon=84, lat=34): if not exists: incident.create() - -create_incident(key=1, date="10-01-2019", lon=-84.362576, lat=33.7589748) -create_incident(key=2, date="11-01-2019", lon=-118.1861128, lat=33.76702) -create_incident(key=3, date="12-01-2019", lon=-117.8827321, lat=33.800308) -create_incident(key=4, date="03-15-2020", lon=-118.1690197, lat=33.8338271) -create_incident(key=5, date="04-15-2020", lon=-83.9007382, lat=33.8389977) -create_incident(key=6, date="08-10-2020", lon=-84.2687574, lat=33.9009798) -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) +def create_seeds(): + create_user( + User( + email="test@example.com", + password=user_manager.hash_password("password"), + role=UserRole.PUBLIC, + first_name="Test", + last_name="Example", + phone_number="(123) 456-7890", + ) + ) + create_user( + User( + email="contributor@example.com", + password=user_manager.hash_password("password"), + role=UserRole.CONTRIBUTOR, + first_name="Contributor", + last_name="Example", + phone_number="(123) 456-7890", + ) + ) + create_user( + User( + email="admin@example.com", + password=user_manager.hash_password("password"), + role=UserRole.ADMIN, + first_name="Admin", + last_name="Example", + phone_number="(012) 345-6789", + ) + ) + create_user( + User( + email="passport@example.com", + password=user_manager.hash_password("password"), + role=UserRole.PASSPORT, + first_name="Passport", + last_name="Example", + phone_number="(012) 345-6789", + ) + ) + create_partner( + Partner( + id="1", + name="Mapping Police Violence", + url="https://mappingpoliceviolence.us", + contact_email="info@campaignzero.org" + ) + ) + create_incident(key=1, date="10-01-2019", lon=-84.362576, lat=33.7589748) + create_incident(key=2, date="11-01-2019", lon=-118.1861128, lat=33.76702) + create_incident(key=3, date="12-01-2019", lon=-117.8827321, lat=33.800308) + create_incident(key=4, date="03-15-2020", lon=-118.1690197, lat=33.8338271) + create_incident(key=5, date="04-15-2020", lon=-83.9007382, lat=33.8389977) + create_incident(key=6, date="08-10-2020", lon=-84.2687574, lat=33.9009798) + 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 diff --git a/backend/api.py b/backend/api.py index 0cef11e73..22766fbee 100644 --- a/backend/api.py +++ b/backend/api.py @@ -48,6 +48,22 @@ def register_commands(app: Flask): app.cli.add_command(db_cli) + @app.cli.command( + "seed", + context_settings=dict( + ignore_unknown_options=True, + allow_extra_args=True, + help_option_names=[], + ), + ) + @click.pass_context + @dev_only + def seed(ctx: click.Context): + """Seed the database.""" + from alembic.dev_seeds import create_seeds + + create_seeds() + @app.cli.command( "pip-compile", context_settings=dict(