Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add seed command #305

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 59 additions & 67 deletions alembic/dev_seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,52 +14,6 @@ def create_user(user):
if not user_exists:
user.create()


create_user(
User(
email="[email protected]",
password=user_manager.hash_password("password"),
role=UserRole.PUBLIC,
first_name="Test",
last_name="Example",
phone_number="(123) 456-7890",
)
)

create_user(
User(
email="[email protected]",
password=user_manager.hash_password("password"),
role=UserRole.CONTRIBUTOR,
first_name="Contributor",
last_name="Example",
phone_number="(123) 456-7890",
)
)

create_user(
User(
email="[email protected]",
password=user_manager.hash_password("password"),
role=UserRole.ADMIN,
first_name="Admin",
last_name="Example",
phone_number="(012) 345-6789",
)
)

create_user(
User(
email="[email protected]",
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
Expand All @@ -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="[email protected]"
)
)


def create_incident(key=1, date="10-01-2019", lon=84, lat=34):
base_id = 10000000
id = base_id + key
Expand Down Expand Up @@ -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="[email protected]",
password=user_manager.hash_password("password"),
role=UserRole.PUBLIC,
first_name="Test",
last_name="Example",
phone_number="(123) 456-7890",
)
)
create_user(
User(
email="[email protected]",
password=user_manager.hash_password("password"),
role=UserRole.CONTRIBUTOR,
first_name="Contributor",
last_name="Example",
phone_number="(123) 456-7890",
)
)
create_user(
User(
email="[email protected]",
password=user_manager.hash_password("password"),
role=UserRole.ADMIN,
first_name="Admin",
last_name="Example",
phone_number="(012) 345-6789",
)
)
create_user(
User(
email="[email protected]",
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="[email protected]"
)
)
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()
16 changes: 16 additions & 0 deletions backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading