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

Convert install status to string #121

Merged
merged 11 commits into from
Jan 28, 2024
6 changes: 6 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: "Upgrade pip"
run: "pip install --upgrade pip"
- name: "Print python version"
run: "python --version"
- name: "Install package"
run: pip install ".[dev]"
- name: "Run lint checks"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/no_debug_allowed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: "Upgrade pip"
run: "pip install --upgrade pip"
- name: "Install package"
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/no_forgoten_migrations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Make sure to run manage.py makemigrations if you change models

on: [pull_request]

jobs:
is-migration-diff-clean:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: nycmesh-dev
POSTGRES_USER: nycmesh
POSTGRES_PASSWORD: abcd1234
POSTGRES_PORT: 5432
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: "Upgrade pip"
run: "pip install --upgrade pip"
- name: "Install package"
run: pip install ".[dev]"
- name: "You forgot to run manage.py makemigrations for model changes"
env:
DB_NAME: nycmesh-dev
DB_USER: nycmesh
DB_PASSWORD: abcd1234
DB_HOST: localhost
DB_PORT: 5432
DJANGO_SECRET_KEY: k7j&!u07c%%97s!^a_6%mh_wbzo*$hl4lj_6c2ee6dk)y9!k88
run: |
python src/manage.py makemigrations meshapi --dry-run # Run extra time for debug output
python src/manage.py makemigrations meshapi --dry-run | grep "No changes detected in app 'meshapi'"

12 changes: 8 additions & 4 deletions .github/workflows/run_django_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ jobs:
image: pelias/parser:latest
ports:
- 6800:3000
strategy:
max-parallel: 4
matrix:
python-version: [3.11]
redis:
image: redis
ports:
- 6379:6379

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: "Upgrade pip"
run: "pip install --upgrade pip"
- name: "Install package"
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ services:
volumes:
- postgres_data:/var/lib/postgresql/data/

redis:
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
networks:
- api
ports:
- 6379:6379
image:
redis

pelias:
networks:
- api
Expand All @@ -28,6 +38,8 @@ services:
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: curl http://127.0.0.1:8081/api/v1
interval: 2s
Expand Down
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ done

echo 'DB started'

# It's okay to start Celery in the background and continue without waiting, even though "migrate"
# might make DB changes we want to notify for since tasks are queued by Django Webhook and
# are executed as soon as celery starts
# FIXME: This makes testing locally a bit awkward, since this isn't started by "manage.py runserver"
# maybe there's a way to do this better?
echo 'Staring Celery Worker...'
celery -A meshdb worker -l INFO --detach

echo 'Running Migrations...'
python manage.py migrate

Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
name = "nycmesh-meshdb"
version = "0.1"
dependencies = [
"celery[redis]==5.3.*",
"django==4.2.*",
"djangorestframework==3.14.*",
"django-webhook>=0.0.7,<0.1.0",
"psycopg2-binary==2.9.*",
"gunicorn==21.2.*",
"python-dotenv==1.0.*",
Expand All @@ -26,7 +28,8 @@ dev = [
"black == 23.7.*",
"isort == 5.12.*",
"coverage == 7.3.*",
"mypy == 1.5.*"
"mypy == 1.5.*",
"flask == 3.0.*",
]

[project.scripts]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.9 on 2024-01-28 01:02

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("meshapi", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="installer",
name="group_ptr",
),
migrations.RemoveField(
model_name="readonly",
name="group_ptr",
),
migrations.DeleteModel(
name="Admin",
),
migrations.DeleteModel(
name="Installer",
),
migrations.DeleteModel(
name="ReadOnly",
),
]
101 changes: 101 additions & 0 deletions src/meshapi/migrations/0003_alter_building_building_status_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Generated by Django 4.2.9 on 2024-01-28 02:49

from django.db import migrations, models


def migrate_building_status_int_to_str(apps, _):
Building = apps.get_model("meshapi", "Building")

old_to_new_status_mapping = {0: "Inactive", 1: "Active"}

for building in Building.objects.all():
building.building_status = old_to_new_status_mapping[building.building_status_old]
building.save()


def migrate_install_status_int_to_str(apps, _):
Install = apps.get_model("meshapi", "Install")

old_to_new_status_mapping = {
0: "Open",
1: "Scheduled",
2: "NN Assigned",
3: "Blocked",
4: "Active",
5: "Inactive",
6: "Closed",
}

for install in Install.objects.all():
install.install_status = old_to_new_status_mapping[install.install_status_old]
install.save()


class Migration(migrations.Migration):
dependencies = [
("meshapi", "0002_remove_installer_group_ptr_remove_readonly_group_ptr_and_more"),
]

operations = [
migrations.RenameField(
model_name="building",
old_name="building_status",
new_name="building_status_old",
),
migrations.AddField(
model_name="building",
name="building_status",
field=models.TextField(choices=[("Inactive", "Inactive"), ("Active", "Active")], default="Inactive"),
),
migrations.RunPython(migrate_building_status_int_to_str),
migrations.RemoveField(
model_name="building",
name="building_status_old",
),
migrations.AlterField(
model_name="building",
name="building_status",
field=models.TextField(choices=[("Inactive", "Inactive"), ("Active", "Active")]),
),
migrations.RenameField(
model_name="install",
old_name="install_status",
new_name="install_status_old",
),
migrations.AddField(
model_name="install",
name="install_status",
field=models.TextField(
choices=[
("Open", "Open"),
("Scheduled", "Scheduled"),
("NN Assigned", "Nn Assigned"),
("Blocked", "Blocked"),
("Active", "Active"),
("Inactive", "Inactive"),
("Closed", "Closed"),
],
default="Inactive",
),
),
migrations.RunPython(migrate_install_status_int_to_str),
migrations.RemoveField(
model_name="install",
name="install_status_old",
),
migrations.AlterField(
model_name="install",
name="install_status",
field=models.TextField(
choices=[
("Open", "Open"),
("Scheduled", "Scheduled"),
("NN Assigned", "Nn Assigned"),
("Blocked", "Blocked"),
("Active", "Active"),
("Inactive", "Inactive"),
("Closed", "Closed"),
]
),
),
]
26 changes: 13 additions & 13 deletions src/meshapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@


class Building(models.Model):
class BuildingStatus(models.IntegerChoices):
INACTIVE = 0
ACTIVE = 1
class BuildingStatus(models.TextChoices):
INACTIVE = "Inactive"
ACTIVE = "Active"

bin = models.IntegerField(blank=True, null=True)
building_status = models.IntegerField(choices=BuildingStatus.choices)
building_status = models.TextField(choices=BuildingStatus.choices)
street_address = models.TextField(blank=True, null=True)
city = models.TextField(blank=True, null=True)
state = models.TextField(blank=True, null=True)
Expand Down Expand Up @@ -54,14 +54,14 @@ def __str__(self):


class Install(models.Model):
class InstallStatus(models.IntegerChoices):
OPEN = 0
SCHEDULED = 1
NN_ASSIGNED = 2
BLOCKED = 3
ACTIVE = 4
INACTIVE = 5
CLOSED = 6
class InstallStatus(models.TextChoices):
OPEN = "Open"
SCHEDULED = "Scheduled"
NN_ASSIGNED = "NN Assigned"
BLOCKED = "Blocked"
ACTIVE = "Active"
INACTIVE = "Inactive"
CLOSED = "Closed"

# Install Number (generated when form is submitted)
install_number = models.AutoField(
Expand All @@ -78,7 +78,7 @@ class InstallStatus(models.IntegerChoices):
)

# Summary status of install
install_status = models.IntegerField(choices=InstallStatus.choices)
install_status = models.TextField(choices=InstallStatus.choices)

# OSTicket ID
ticket_id = models.IntegerField(blank=True, null=True)
Expand Down
2 changes: 1 addition & 1 deletion src/meshapi/tests/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

sample_building = {
"bin": 8888,
"building_status": 1,
"building_status": "Active",
"street_address": "3333 Chom St",
"city": "Brooklyn",
"state": "NY",
Expand Down
Loading
Loading